[英]Generate Image from Excel sheet containg more than one sheet and bulk amount of data?
我正在使用aspose.cells生成Excel工作表的圖像,並且工作正常,但是當我嘗試生成包含4張工作表和大量數據的Excel文件時,會產生錯誤
OutOfHeapMemory
如果我把條件設置成比它讀取的excel數據少的excel,
Workbook workbook = new Workbook(sourceDir);
List<Worksheet> worksheets = getAllWorksheets(workbook);
if (worksheets != null) {
int noOfImages = 0;
for (Worksheet worksheet : worksheets) {
if (worksheet.getCells().getCount() > 0 || worksheet.getCharts().getCount() > 0 || worksheet.getPictures().getCount() > 0) {
System.out.println("Worksheet Before Condition" + worksheet);
if (worksheet.getCells().getCount() < 2000) {
System.out.println("Worksheet After Condition" + worksheet);
String imageFilePath = workingDir + File.separator + projectName + File.separator + fileName + "_" + (noOfImages++) + ".png";
SheetRender sr = new SheetRender(worksheet, getImageOrPrintOptions());
sr.toImage(0, imageFilePath);
}
}
}
}
我在if條件之前和之后使用System.out.println來檢查循環迭代的工作表。
Worksheet Before ConditionAspose.Cells.Worksheet[ Details of Indian Companies Reg ]
Worksheet Before ConditionAspose.Cells.Worksheet[ LLP'S Incorporated in Jun ]
Worksheet Before ConditionAspose.Cells.Worksheet[ Foreign Companies Registered ]
Worksheet After ConditionAspose.Cells.Worksheet[ Foreign Companies Registered ]
請注意以下示例代碼供您參考,它將為第一張工作表的不同頁面生成一系列圖像:
樣例代碼:
// Instantiate a new workbook with path to an Excel file
Workbook book = new Workbook(dataDir + “MyTestBook1.xlsx”);
// Create an object for ImageOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Set the image type
imgOptions.setImageFormat(ImageFormat.getPng());
// Get the first worksheet.
Worksheet sheet = book.getWorksheets().get(0);
// Create a SheetRender object for the target sheet
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int j = 0; j < sr.getPageCount(); j++) {
// Generate an image for the worksheet
sr.toImage(j, dataDir + “WToImage-out” + j + “.png”);
}
// Print message
System.out.println(“Images generated successfully.”);
如果您仍然發現任何問題或困惑,請提供您的模板文件並粘貼示例代碼(可運行)以顯示問題,我們將盡快進行檢查。
注意:我在Aspose擔任技術支持/開發人員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.