从 Excel sheet 生成图像包含多个 sheet 和大量数据?

Generate Image from Excel sheet containg more than one sheet and bulk amount of data?

我正在使用 aspose.cells 生成 excel sheet 的图像并且它工作正常但是当我尝试生成包含 4 sheet 的 excel 文件时s 和其中的大量数据会产生错误

OutOfHeapMemory

如果我输入条件,它会显示 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 来检查在循环中迭代的工作sheet。

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 担任支持开发人员/传播者。