Dear All,
I am evaluating Aspose Cells .NET, I downloaded the latest version 8.0.2.0, and Office 2007
I am facing with 'Unable to read file’
why?.. did I miss something in the codes below? … I enclosed the excel file…
// ===== creating Header ====
private void createXLS_MO()
{
_workbook = new Workbook();
_sheet = _workbook.Worksheets[0];
_cells = _sheet.Cells;
_sheet.Name = “Raw Data”;
_sheet.FreezePanes(1, 1, 1, 25);
_header.Font.IsBold = true;
_header.HorizontalAlignment = TextAlignmentType.Center;
_txtdetail.Font.IsBold = false;
_txtdetail.HorizontalAlignment = TextAlignmentType.Left;
_numformat.Number = 4;
_numformat.HorizontalAlignment = TextAlignmentType.Right;
_numformat.Font.IsBold = false;
_cell = _cells[“A1”];
_cell.PutValue(“Branch”);
_cell.SetStyle(_header);
_cell = _cells[“B1”];
_cell.PutValue(“MO”);
_cell.SetStyle(_header);
_cell = _cells[“C1”];
_cell.PutValue(“Source”);
_cell.SetStyle(_header);
_cell = _cells[“D1”];
_cell.PutValue(“Outstanding”);
_cell.SetStyle(_header);
_cell = _cells[“E1”];
_cell.PutValue(“Current”);
_cell.SetStyle(_header);
_cell = _cells[“F1”];
_cell.PutValue(“Overdue”);
_cell.SetStyle(_header);
}
//==== Creating Pivot ====
private void createPivot_MO()
{
try
{
Worksheet sheet2 = _workbook.Worksheets[_workbook.Worksheets.Add()];
sheet2.Name = “PivotTable”;
int filter = cboFilter.SelectedIndex;
_cells = sheet2.Cells;
_cells.Merge(0, 1, 1, 7, true, false);
_cell = _cells[“B1”];
_cell.PutValue(“Profit Comm by " + cboFilter.Text);
_cell.SetStyle(_header);
_cells.Merge(1, 1, 1, 7, true, false);
_cell = _cells[“B2”];
_cell.PutValue(_condition);
_cell.SetStyle(_header);
Aspose.Cells.Pivot.PivotTableCollection pivotTables = sheet2.PivotTables;
int index = pivotTables.Add(”=" + _workbook.Worksheets[0].Name + “!A1:F” + _workbook.Worksheets[0].Cells.Rows.Count, “B4”, “PivotTable1”);
Aspose.Cells.Pivot.PivotTable pivotTable = pivotTables[index];
pivotTable.RowGrand = true;
pivotTable.IsAutoFormat = true;
pivotTable.AutoFormatType = Aspose.Cells.Pivot.PivotTableAutoFormatType.Table1;
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, “Branch”);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, “MO”);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, “Source”);
//Dragging Fields to Data Area
PivotField nominal = pivotTable.BaseFields[“Outstanding”];
nominal.Function = ConsolidationFunction.Sum;
nominal.NumberFormat = “#,##0.00”;
pivotTable.AddFieldToArea(PivotFieldType.Data, nominal);
PivotField payment = pivotTable.BaseFields[“Current”];
payment.Function = ConsolidationFunction.Sum;
payment.NumberFormat = “#,##0.00”;
pivotTable.AddFieldToArea(PivotFieldType.Data, payment);
PivotField pctg = pivotTable.BaseFields[“Overdue”];
pctg.NumberFormat = “#,##0.00”;
pivotTable.AddFieldToArea(PivotFieldType.Data, pctg);
if (pivotTable.DataField != null)
{
pivotTable.AddFieldToArea(PivotFieldType.Column, pivotTable.DataField);
}
pivotTable.DataFields[0].NumberFormat = “#,##0.00”;
pivotTable.DataFields[1].NumberFormat = “#,##0.00”;
pivotTable.DataFields[2].NumberFormat = “#,##0.00”;
index = _workbook.Styles.Add();
Style style = _workbook.Styles[index];
style.HorizontalAlignment = TextAlignmentType.Right;
CellArea area = pivotTable.RowRange;
int start = area.StartRow;
for (int i = pivotTable.RowRange.StartRow; i <= pivotTable.RowRange.EndRow; i++)
{
pivotTable.Format(i, 4, style);
pivotTable.Format(i, 5, style);
pivotTable.Format(i, 6, style);
}
PivotFieldCollection dfs = pivotTable.DataFields;
PivotField df = dfs[0];
df.IsAutoSort = true;
df.IsAscendShow = false;
// df.IsAscendSort = false;
df.AutoSortField = -1;
df.IsAutoShow = true;
// Final
sheet2.AutoFitColumns();
sheet2.MoveTo(0);
_xls = clsMain.getRandomFileName("Profit Comm ", “xls”);
if (clsMain.isFileExists(@_xls))
clsMain.fileDelete(@_xls);
_workbook.Save(@_xls);
}
catch { }
finally { }
}