I am trying to produce an excel file with 65,000 rows (82 col) through ASP.NET application but without success. Aspose component is eating all the memory. The server has 8 gig of total RAM and 60% of it can be used for ASPNET worker process.
I have created a test application that generates about 2500 rows with 82 columns and Aspose alone is costing about 96 MB memory. See the memory allocations at the bottom of this post captured by CLRProfiler.
Here are my psudo codes:
CreateReport(96 MB) --> WriteData(49 MB); Save(46 MB)--->WriteGroupData(49 MB)
How can I improve the memory consumption? Did you realize that I would need 2.4 gig of memory just to run the CreateReport method if I were to produce an excel file with 65,000 rows?
Thanks in advance.
Prodip
Codes and Memory allocation:
public string CreateReport()
{
try
{
string licenseFile = GetAsposeLicense();
oExcel = new Aspose.Excel.Excel(licenseFile);
// Open Template
oExcel.Open(GetTemplate());
//Write Data
if (dtData.Rows.Count > 0)
WriteData();
else
oExcel.Replace("&Data", "");
//Save Excel Report
oExcel.Save(ReportDest, FileFormatType.Excel2000);
oExcel = null;
//Return report path
return ReportDest;
}
catch (Exception e)
{
throw (e);
}
}
private int WriteGroupData(DataView dv, int Row, int Col)
{
int InitCol = Col;
Worksheet ws=oExcel.Worksheets.GetAt(0);
Cells oCells = ws.Cells;
double dColWidth;
//Define Styles
Styles oStyles = oExcel.Styles;
int styleIndexCustom = oStyles.Add();
int styleIndex40 = oStyles.Add();
int styleIndex14 = oStyles.Add();
int styleIndexDefault = oStyles.Add();
int styleIndex0 = oStyles.Add();
Style styleDefault = oExcel.Styles.GetAt(styleIndexDefault);
styleDefault.Font.Name="Tahoma";
styleDefault.Font.Size=10;
styleDefault.Number=0;
styleDefault.HorizontalAlignment=TextAlignmentType.Left;
Style styleCustom = oExcel.Styles.GetAt(styleIndexCustom);
styleCustom.Font.Name="Tahoma";
styleCustom.Font.Size=10;
styleCustom.HorizontalAlignment=TextAlignmentType.Right;
styleCustom.Custom="#0.00000_);[Red](#0.00000)";
Style style40 = oExcel.Styles.GetAt(styleIndex40);
style40.Font.Name="Tahoma";
style40.Font.Size=10;
style40.Number=40;
style40.HorizontalAlignment=TextAlignmentType.Right;
Style style14 = oExcel.Styles.GetAt(styleIndex14);
style14.Font.Name="Tahoma";
style14.Font.Size=10;
style14.Number=14;
style14.HorizontalAlignment=TextAlignmentType.Right;
Style style0 = oExcel.Styles.GetAt(styleIndex0);
style0.Font.Name="Tahoma";
style0.Font.Size=10;
style0.Number=0;
style0.HorizontalAlignment=TextAlignmentType.Right;
//Cell oCell=null;
// Write each row
foreach(DataRowView drv in dv)
{
// Write each column
for(int i = 0; i<dv.Table.Columns.Count; i++)
{
if (HasSubtotals)
{ // If subtotals, then add column value to running total
int iCol = FindColumn(dtData.Columns.ToString());
if (iCol >= 0)
{
Column oCol = (Column) columnTotals[iCol];
if (oCol.Type == "Subtotal")
{
oCol.AddGroupTotal(groupBy.Count-1, (decimal) drv);
}
else if(oCol.Type == "SubtotalInt")
{
oCol.AddGroupTotal(groupBy.Count-1, (int) drv);
}
else
{
oCol.AddGroupCount(groupBy.Count-1, (int) 1);
}
}
}
// Write value
Cell oCell = oCells[Row, (byte) Col];
//oCell.PutValue(drv);
oCell.PutValue(drv);
// Set CellFormat based on datatype
if (dtData.Columns.DataType.Name == "Decimal")
{
if (RateFormat(dtData.Columns.ColumnName.ToString()))
{
oCell.Style=styleCustom;
}
else
{
oCell.Style=style40;
}
}
else if (dtData.Columns.DataType.Name == "DateTime")
{
oCell.Style=style14;
dColWidth = oCells.GetColumnWidth((byte) i);
if (dColWidth < 10)
oCells.SetColumnWidth((byte) i, 10);
}
else if (dtData.Columns.DataType.Name == "Int32")
{
oCell.Style=style0;
}
else
{
oCell.Style=styleDefault;
}
Col++;
oCell=null;
}
Row++;
Col = InitCol;
}
//Release the local objects
oStyles=null;
styleDefault=null;
styleCustom=null;
style40=null;
style14=null;
//oCell=null;
oCells=null;
ws=null;
//Return Value
return Row;
}
: 111 MB (100.00%)
ProbAspose.ProfileAspose::Main static void (String[]): 111 MB (99.99%)
ProbAspose.MasterFile::CreateReport String (): 111 MB (99.98%)
ProbAspose.ExcelReport::CreateReport String (): 96 MB (86.33%)
ProbAspose.MasterFile::GetData void (): 15 MB (13.64%)
ProbAspose.ExcelReport::WriteData void (): 49 MB (44.53%)
Aspose.Excel.Excel::Save void (String Aspose.Excel.FileFormatType): 46 MB (41.53%)
EMCSQLDataAccessImplementation.OleDbHelper::ExecuteDataset void (String String): 15 MB (13.64%)
ProbAspose.ExcelReport::WriteGroupData int32 ( int32 int32): 49 MB (44.52%)
Aspose.Excel.Worksheets::a void (String Aspose.Excel.SaveType Aspose.Excel.FileFormatType ): 46 MB (41.50%)
EMCSQLDataAccessImplementation.OleDbHelper::ExecuteDataset void (String String []): 15 MB (13.64%)
Aspose.Excel.Worksheets::d void (b5): 46 MB (41.50%)
EMCSQLDataAccessImplementation.OleDbHelper::ExecuteDataset void ( String []): 15 MB (13.60%)
Aspose.Excel.Cell::set_Style void (Aspose.Excel.Style): 11 MB (10.00%)
System.RuntimeType::get_Name String (): 9.3 MB (8.42%)
System.Data.DataRowView::get_Item Object (int32): 1.4 MB (1.22%)
Aspose.Excel.Worksheet::c void (b5): 46 MB (41.15%)
Aspose.Excel.Cells::get_Item Aspose.Excel.Cell (int32 unsigned int8): 27 MB (23.96%)
System.Data.Common.DbDataAdapter::Fill int32 (System.Data.DataSet): 15 MB (13.60%)
System.Data.DataColumn::get_Item Object (int32): 1.4 MB (1.22%)
Aspose.Excel.Cells::d void (b5 Aspose.Excel.FileFormatType): 46 MB (41.15%)
System.Data.Common.DbDataAdapter::Fill int32 (System.Data.DataSet int32 int32 String System.Data.IDbCommand System.Data.CommandBehavior): 15 MB (13.60%)
System.Data.Common.DecimalStorage::Get Object (int32): 1.3 MB (1.16%)
Aspose.Excel.Cell::a void (b5 Aspose.Excel.FileFormatType): 36 MB (32.03%)
System.Data.Common.DbDataAdapter::FillFromCommand int32 (Object int32 int32 String System.Data.IDbCommand System.Data.CommandBehavior): 15 MB (13.60%)
Aspose.Excel.Cells::c unsigned int32 (b5 Aspose.Excel.FileFormatType): 7.3 MB (6.56%)
Aspose.Excel.Cells::b void (Aspose.Excel.Cell): 2.0 MB (1.80%)
dg::a bool (unsigned int16 unsigned int16 unsigned int16 float64): 23 MB (20.32%)
System.Data.Common.DbDataAdapter::Fill int32 (System.Data.DataSet String System.Data.IDataReader int32 int32): 15 MB (13.57%)
f::a void (b5): 4.2 MB (3.80%)
df::a void (b5): 3.1 MB (2.79%)
Aspose.Excel.Cells::a void (Aspose.Excel.Cell): 2.0 MB (1.80%)
System.Data.Common.DbDataAdapter::FillFromReader int32 (Object String System.Data.IDataReader int32 int32 System.Data.DataColumn Object): 15 MB (13.57%)
dg::a bool (float64): 7.6 MB (6.84%)
System.Collections.ArrayList::Insert void (int32 Object): 2.0 MB (1.80%)
System.Data.Common.DbDataAdapter::FillLoadDataRow int32 (System.Data.Common.SchemaMapping): 15 MB (13.32%)
System.BitConverter::GetBytes static unsigned int8[] (float64): 3.9 MB (3.52%)
System.Data.Common.SchemaMapping::LoadDataRow void (bool bool): 15 MB (13.32%)
System.Data.DataTable::LoadDataRow System.Data.DataRow (Object[] bool): 8.5 MB (7.65%)
System.Data.OleDb.OleDbDataReader::GetValues int32 (Object[]): 6.3 MB (5.67%)
System.Data.DataTable::NewRecordFromArray int32 (Object[]): 8.3 MB (7.46%)
System.Data.OleDb.DBBindings::get_Value Object (): 6.3 MB (5.67%)
System.Data.RecordManager::NewRecordBase int32 (): 8.3 MB (7.46%)
System.Data.OleDb.DBBindings::get_Value_NUMERIC void (): 2.0 MB (1.78%)
System.Data.RecordManager::GrowRecordCapacity void (): 8.3 MB (7.46%)
System.Data.OleDb.DBBindings::Get_NUMERIC static void (int int32[]): 2.0 MB (1.78%)
System.Data.RecordManager::set_RecordCapacity void (int32): 8.3 MB (7.44%)
System.Collections.ArrayList::EnsureCapacity void (int32): 2.5 MB (2.22%)
System.Data.DataColumn::SetCapacity void (int32): 8.3 MB (7.44%)
System.Collections.ArrayList::set_Capacity void (int32): 2.5 MB (2.22%)
System.Data.Common.DecimalStorage::SetCapacity void (int32): 7.3 MB (6.59%)
System.Delegate::Combine static System.Delegate (System.Delegate System.Delegate): 5.6 MB (5.00%)
System.MulticastDelegate::CombineImpl System.Delegate (System.Delegate): 5.6 MB (5.00%)
System.Byte [] : 34 MB (31.05%)
Aspose.Excel.Cell : 22 MB (20.02%)
a3 : 11 MB (10.01%)
System.String : 10 MB (9.40%)
System.Decimal [] : 7.3 MB (6.54%)
System.UInt16 : 5.1 MB (4.55%)
cx : 4.8 MB (4.29%)
System.Decimal : 4.7 MB (4.20%)
System.Object [] : 3.8 MB (3.38%)
dg : 2.9 MB (2.63%)
df : 1.2 MB (1.04%)