Please check the attached file inside the zip.
It fails with OutOfMemory exception with latest version of Aspose.Cells NuGet.
457971_OutOfMemory_Exception.zip (103.9 KB)
Which version of the Aspose.Cells for .NET you are using? I tested with latest Aspose.Cells for .NET v24.6 and it works find and I do not get any exception.
e.g.,
Sample code:
Workbook workbook = new Workbook("e:\\test2\\457971_OutOfMemory_Exception.xlsx");
If you still encounter the issue with the latest version (Aspose.Cells for .NET v24.6), please provide a sample simulation code (runnable) to reproduce the issue on our end. We will investigate it promptly.
Latest version of Aspose.Cells
@amjad.sahi Just updated the sample code(with doc.Save…)
var loadFormat = Aspose.Cells.LoadFormat.Auto;
var loadOptions = new Aspose.Cells.LoadOptions(loadFormat);
var doc = new Workbook(inputPath, loadOptions);
doc.Save(inputPath + ".pdf", Aspose.Cells.SaveFormat.Pdf);
@amjad.sahi The issue is reproduced with the sample code that I provided.
Do you reproduce it on your end?
@DWProject
We have reproduced your mentioned issue. There are too many pages when converting to pdf. Please open the file in MS Excel, then print view the first sheet, your will find there are 34,812,556 pages. The right border of the cell B1047195, B1048540, B1048562 is applied. They should be meaningless, but we have to export huge pages as MS Excel, so the OutOfMemory exception is thrown.
1). Its’s the best that you can remove border from these cells in MS Excel or by Aspose.Cells API.
2). Please ignore blank pages when converting Excel to PDF.
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.PrintingPageType = PrintingPageType.IgnoreBlank;
//saveOptions.PrintingPageType = PrintingPageType.IgnoreStyle;
doc.Save(dir + "dest.pdf", saveOptions);
Thank you for the suggestions!
The code for converting to PDF will be used.
There is also a Out Of Memory Exception when creating a SheetRender class.
It is reproduced with the attached file(without removed borders).
What is the fix for this case?(if borders cannot be removed)
Here is the code snippet:
var loadFormat = Aspose.Cells.LoadFormat.Auto;
var loadOptions = new Aspose.Cells.LoadOptions(loadFormat);
var doc = new Workbook(inputPath, loadOptions);
float dpi = 180;
var renderer = new SheetRender(doc.Worksheets[0], new ImageOrPrintOptions
{
OnePagePerSheet = false,
AllColumnsInOnePagePerSheet = false,
HorizontalResolution = (int)Math.Round(dpi), // not enough precision
VerticalResolution = (int)Math.Round(dpi),
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
//WarningCallback = this,
});
Console.WriteLine(renderer.PageCount);
@DWProject
By using sample files and code for testing on the latest version v24.6, we can reproduce the issue. Discovered that OutOfMemoryException occurs when creating a SheetRender.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSNET-56002
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
There is a similar solution for SheetRender
: ImageOrPrintOptions.PrintingPage
. The code will be:
var loadFormat = Aspose.Cells.LoadFormat.Auto;
var loadOptions = new Aspose.Cells.LoadOptions(loadFormat);
var doc = new Workbook(inputPath, loadOptions);
float dpi = 180;
var renderer = new SheetRender(doc.Worksheets[0], new ImageOrPrintOptions
{
//ignore blank page
PrintingPage = PrintingPageType.IgnoreBlank,
OnePagePerSheet = false,
AllColumnsInOnePagePerSheet = false,
HorizontalResolution = (int)Math.Round(dpi), // not enough precision
VerticalResolution = (int)Math.Round(dpi),
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
//WarningCallback = this,
});
Console.WriteLine(renderer.PageCount);
Also, you can set a proper printarea that has data for sheet "Posteingang ", e.g. “A1:G932”
doc.Worksheets["Posteingang "].PageSetup.PrintArea = "A1:G932";
@DWProject
Please check the cell “XFD169” and “XFD396” in MS Excel, there are useless values in them.
It’s better to remove them as the following :
cells[“XFD169”].PutValue(null);
cells[“XFD396”].PutValue(null);