In Aspose.Cells 5.1.3.0, a call to sheet.Cells.DeleteRow sometimes fails with a NullReferenceException. This is in code that has been working for at least a year, the only change being the .Cells version. In fact, it worked as recently as .Cells 5.1.2.6.
In the code fragment below, you can see that the row indicated by "rows+2" is (created and) each column is filled with a constant string. Then, AutofitColumns is executed and finally the row is deleted. I'll provide the best information I can but I do not have an easily reproducible example as of yet. It doesn't appear to be a hard failure in that sometimes the code executes correctly.
Error: System.NullReferenceException: Object reference not set to an instance
of an object.
Stacktrace:
ዺ.ዹ.݃(int ٹ = 1305, int ࢞ = -1, Aspose.Cells.Worksheet = {Aspose.Cells.Worksheet}) + 0xfe bytes
ዺ.ጹ.݃(int ب = 1305, int ߄ = -1, Aspose.Cells.Worksheet = {Aspose.Cells.Worksheet}) + 0x54 bytes
Aspose.Cells.Cells.DeleteRows(int rowIndex = 1305, int totalRows = 1) + 0x821 bytes
Aspose.Cells.Cells.DeleteRow(int rowIndex = 1305) + 0x30 bytes
ModelSheet.AsposeGenerator.AsposeGenerator.DeleteRow(object exsheet = {Aspose.Cells.Worksheet}, int nrow = 1306) Line 428 + 0x1c bytes C#
ModelSheet.Model.Spreadsheet.BasicExcelGenerator.SaveBookAs(ModelSheet.Model.Spreadsheet.Workbook book = "Workbook Advanced Template", string fullname = null, ModelSheet.Model.ProgressStep monitor = {ModelSheet.Model.ProgressStep}, string filetype = "xls") Line 632 + 0x14 bytes C#
My version of DeleteRow:
public override void DeleteRow(Object exsheet, int nrow) {
Worksheet assheet=(Worksheet)exsheet;
assheet.Cells.DeleteRow(nrow-1);
return;
}
The code fragment that calls DeleteRow:
if (sheet.WantAutofit) {
if (sizer!="") {
// Put in the sizer string at the bottom of each column to
// influence autofit behavior
for (int nc=1; nc<=cols; nc++) SetValue(GetCell(exsheet, rows+2, nc), sizer);
};
if (colfixedwidth<=0.0) AutofitColumns(exsheet);
AutofitRows(exsheet);
if (sizer!="") {
// Remove the sizer row
DeleteRow(exsheet, rows+2); // ***** This is the call that causes the exception
};
if (colfixedwidth>0.0 || colpctfudge>0.0) {
// Do final adjustments on column widths
for (int nc=1; nc<=cols; nc++) {
double width=colfixedwidth;
if (width<=0.0) width=GetColumnWidth(exsheet, nc);
SetColumnWidth(exsheet, nc, Math.Min(width*(colpctfudge+1.0), 255.0));
};
};
};
Thanks,
--Howard