Free Support Forum - aspose.com

DeleteRange Question

Hi,

quick question, I think I’m doing something wrong. I delete a series of rows on a couple of sheets. First, I did the following (within a loop):



for(int row…)
{
sheets.Cells.DeleteRow(row–);
while(RowIsEmpty(row) == true)
{
sheets.Cells.DeleteRow(row–);
}
}


Now I thought as DeleteRow seems to be rather costly, I would count the rows to delete in a loop like so



for(int row…)
{
int startRow = row + 1;
while(RowIsEmpty(startRow) == true)
{
startRow++;
}
sheet.Cells.DeleteRange(row, 0, startRow - 1, 0, ShiftType.Up);
}



Now when I do this, I can’t save the sheet as an Exception is thrown in the Record constructor. Maybe I’m doing something wrong calling DeleteRange()? Maybe something goes wrong deleting a range of cells?

What about adding shortcut methods such as DeleteColumns() and DeleteRows()?

Thanks

Regards

Kai

Hi Kai,

Thanks for your suggestion.

We will add DeleteRows/DeleteColumns methods in the future release. It will be available within about one week.

If possible, could you please zip and upload your file and sample code here? I will check this issue ASAP.

Laurence,

I would definitely want to send the sample to you, but

a) The Excel designer contains confidential data
b) A sample would be too complex to generate out of my production code

However what is strange is, that when I delete rows by calling DeleteRow() it works just fine, When I call DeleteRange(row1, 0, row2, 0, ShiftType.Up) the Save() fails. The parameters I pass to DeleteRange() seem OK to you (row2 >= row1)?

Regards

Kai

DeleteRange has some differences with DeleteRow. If row2>= row1, it should be ok.

I will check this issue. And your file and sample code will be very helpful.

Could you please:

1. Romove all data in designer but keep formulas
2. Tell me the range you want to delete

Thank you.

Laurence,

I will try to reduce my code in order to supply you with a “working” sample. Don’t know whether I can make it (today)

Regards

Kai

Laurence,

I am unable to cut down my sample in order to make it usable / executable on your side, I’m afraid. However I have emailed the resulting workbook to you. Maybe the stack trace may be helpful?



ERR: [19.04.2005 17:23:02] :: FSNParser.FSNParser.Run(String[] args) (D:\Work\IFRS-Reporting\FSNParser\FSNParser.cs, 158)
>>> Exception
>>> ----------------------------------------------------------------------
>>> Errors in Excel Save method:0
>>> ----------------------------------------------------------------------
>>>
>>> Inner Exception
>>> ----------------------------------------------------------------------
>>> Errors in Excel Save method:0
>>> ----------------------------------------------------------------------
>>>
>>> Inner Exception
>>> ----------------------------------------------------------------------
>>> Arithmetic operation resulted in an overflow.
>>> ----------------------------------------------------------------------
>>>
>>>
>>> Stack Trace
>>> ----------------------------------------------------------------------
>>> at Aspose.Excel.Worksheets.a(UInt32 A_0, Exception A_1)
>>> at Aspose.Excel.Worksheets.a(String A_0, SaveType A_1, FileFormatType A_2, HttpResponse A_3)
>>> at Aspose.Excel.Excel.Save(String fileName, FileFormatType fileFormatType)
>>> at DWS.ITMS.IFRS.ReportGenerator.SaveExcelFile(Excel excel, ExcelFile excelFile) in d:\work\ifrs-reporting\ifrslibrary\reportgenerator.cs:line 375
>>> at DWS.ITMS.IFRS.ReportGenerator.ProcessPackage() in d:\work\ifrs-reporting\ifrslibrary\reportgenerator.cs:line 338
>>> at DWS.ITMS.IFRS.ReportGenerator.GenerateReport(ReportPackage package, String portfolioID, DateTime reportDate, DateTime referenceDate, String outputDirectory) in d:\work\ifrs-reporting\ifrslibrary\reportgenerator.cs:line 280
>>> at FSNParser.FSNParser.Run(String[] args) in D:\Work\IFRS-Reporting\FSNParser\FSNParser.cs:line 134
>>> ----------------------------------------------------------------------
ERR: [19.04.2005 17:23:02] :: FSNParser.FSNParser.Run(String[] args) (D:\Work\IFRS-Reporting\FSNParser\FSNParser.cs, 158)
>>> Exception
>>> ----------------------------------------------------------------------
>>> Errors in Excel Save method:0
>>> ----------------------------------------------------------------------
>>>
>>> Inner Exception
>>> ----------------------------------------------------------------------
>>> Arithmetic operation resulted in an overflow.
>>> ----------------------------------------------------------------------
>>>
>>>
>>> Stack Trace
>>> ----------------------------------------------------------------------
>>> at Aspose.Excel.Worksheets.a(UInt32 A_0, Exception A_1)
>>> at Aspose.Excel.Worksheets.a(String A_0, FileFormatType A_1, MemoryStream& A_2)
>>> at Aspose.Excel.Worksheets.a(String A_0, SaveType A_1, FileFormatType A_2, HttpResponse A_3)
>>> ----------------------------------------------------------------------
ERR: [19.04.2005 17:23:02] :: FSNParser.FSNParser.Run(String[] args) (D:\Work\IFRS-Reporting\FSNParser\FSNParser.cs, 158)
>>> Exception
>>> ----------------------------------------------------------------------
>>> Arithmetic operation resulted in an overflow.
>>> ----------------------------------------------------------------------
>>>
>>>
>>> Stack Trace
>>> ----------------------------------------------------------------------
>>> at Aspose.Excel.Record.df…ctor(UInt16 row, Byte firstColumn, Byte lastColumn, ArrayList xfIndexList)
>>> at Aspose.Excel.Cells.d(bj A_0, FileFormatType A_1)
>>> at Aspose.Excel.Worksheet.c(bj A_0)
>>> at Aspose.Excel.Worksheets.b(bj A_0)
>>> at Aspose.Excel.Worksheets.a(UCOMIStream A_0)
>>> at Aspose.Excel.Record.ax.a(a0 A_0, h A_1, Worksheets A_2)
>>> at Aspose.Excel.Worksheets.a(String A_0, FileFormatType A_1, MemoryStream& A_2)
>>> ----------------------------------------------------------------------


What about the DeleteRows() / DeleteColumns() methods? I guess these could be helpful and speed up things on my side

Regards

Kai


Hi Kai,

DeleteRows/DeleteColumns methods will be available before the start of next week.

Laurence,

this is great news. Thanks again for your support

Regards

Kai