我想将我的 excel 文件及其实体(图表、表格、图像)转换为 jpeg/png 图像。目前正在为此使用 aspose。这是我的代码
public static int excelToImages(final String sourceFilePath, final String outFilePrefix) throws Exception {
int noOfImages = 0;
Workbook workbook = getWorkbook(sourceFilePath);
List<Worksheet> worksheets = getAllWorksheets(workbook);
if (worksheets != null) {
for (Worksheet worksheet : worksheets) {
if (worksheet.getCells().getCount() > 0) {
String outFilePath = FileUtils.getAbsoluteFilePath(outFilePrefix + (noOfImages++));
SheetRender sr = new SheetRender(worksheet, getImageOrPrintOptions());
sr.toImage(0, outFilePath);
}
}
}
return noOfImages;
}
private static ImageOrPrintOptions getImageOrPrintOptions() {
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
imgOptions.setOnePagePerSheet(true);
return imgOptions;
}
private static List<Worksheet> getAllWorksheets(final Workbook workbook) {
List<Worksheet> worksheets = new ArrayList<Worksheet>();
WorksheetCollection worksheetCollection = workbook.getWorksheets();
for (int i = 0; i < worksheetCollection.getCount(); i++) {
worksheets.add(worksheetCollection.get(i));
}
return worksheets;
}
我的问题是输出图像的大小要么分成多个 A4 大小或单张 1 取决于值
imgOptions.setOnePagePerSheet(true);
谁能告诉我如何自定义输出图像文件的大小?