public static void main(String[] args) throws Exception {
Workbook book = new Workbook("/Users/zyx/Downloads/workflow批量导入项目模版 (2).xlsx");
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageType(ImageType.JPEG);
imgOptions.setOutputBlankPageWhenNothingToPrint(false);
imgOptions.setHorizontalResolution(300);
imgOptions.setVerticalResolution(300);
imgOptions.setCheckWorkbookDefaultFont(true);
// 如果 AllColumnsInOnePagePerSheet 为 true ,则一张工作表的所有列内容将只输出到一页。pagesetup 的纸张大小宽度将无效,pagesetup 的其他设置仍然有效。
imgOptions.setAllColumnsInOnePagePerSheet(true);
imgOptions.setQuality(50);
// 指示当单元格字体不兼容时是否只替换字符的字体。
imgOptions.setFontSubstitutionCharGranularity(true);
// Get the first worksheet.
final WorksheetCollection worksheets = book.getWorksheets();
List<FileTargetDTO> list = new ArrayList<>(worksheets.getCount() * 8);
for (int i = 0; i < worksheets.getCount(); i++) {
// Create a SheetRender object for the target sheet
final Worksheet sheet = worksheets.get(i);
sheet.getPageSetup().setPrintGridlines(true);
sheet.getCells().deleteBlankRows();
sheet.getCells().deleteBlankColumns();
SheetRender sr = new SheetRender(worksheets.get(i), imgOptions);
for (int j = 0; j < sr.getPageCount(); j++) {
// Generate an image for the worksheet
final String name = "aaa.jpg";
sr.toImage(j, name);
}
}
}
public static void main(String[] args) throws Exception {
Workbook book = new Workbook("/Users/zyx/Downloads/workflow批量导入项目模版 (2).xlsx");
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageType(ImageType.JPEG);
imgOptions.setOutputBlankPageWhenNothingToPrint(false);
imgOptions.setHorizontalResolution(300);
imgOptions.setVerticalResolution(300);
imgOptions.setCheckWorkbookDefaultFont(true);
// 如果 AllColumnsInOnePagePerSheet 为 true ,则一张工作表的所有列内容将只输出到一页。pagesetup 的纸张大小宽度将无效,pagesetup 的其他设置仍然有效。
imgOptions.setAllColumnsInOnePagePerSheet(true);
imgOptions.setQuality(50);
// 指示当单元格字体不兼容时是否只替换字符的字体。
imgOptions.setFontSubstitutionCharGranularity(true);
// Get the first worksheet.
final WorksheetCollection worksheets = book.getWorksheets();
for (int i = 0; i < worksheets.getCount(); i++) {
// Create a SheetRender object for the target sheet
final Worksheet sheet = worksheets.get(i);
sheet.getPageSetup().setPrintGridlines(true);
sheet.getCells().deleteBlankRows();
sheet.getCells().deleteBlankColumns();
SheetRender sr = new SheetRender(worksheets.get(i), imgOptions);
for (int j = 0; j < sr.getPageCount(); j++) {
// Generate an image for the worksheet
final String name = "aaa.jpg";
sr.toImage(j, name);
}
}
}
This is not an issue with the Aspose.Cells for Java API by any means. I checked your file and found your so called XLSX file is not a valid Excel file. I tried opening the file into MS Excel manually and MS Excel itself prompts an error and does not open the file into it. I then open your file into notepad and its contents are like error trace, see the screenshot attached. sc_shot1.png (10.9 KB)
Please notice, I am able to reproduce the issue as you mentioned by using your new big sized template file. I found the first two pages (of the first visible sheet) are not rendered correctly (as per your attached images) in Sheet to image conversion. I have logged a ticket with an id “CELLSJAVA-43505” for your issue. We will look into it soon.
Once we have an update on it, we will let you know.
@zyx
Please note that when I use the following code to generate the xlsx. the result file is consistent with the picture you gave. Therefore I don’t think this is a mistake.
code:
Workbook book = new Workbook("/Users/zyx/Downloads/workflow批量导入项目模版 (2).xlsx");
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageType(ImageType.JPEG);
imgOptions.setOutputBlankPageWhenNothingToPrint(false);
imgOptions.setHorizontalResolution(300);
imgOptions.setVerticalResolution(300);
imgOptions.setCheckWorkbookDefaultFont(true);
// 如果 AllColumnsInOnePagePerSheet 为 true ,则一张工作表的所有列内容将只输出到一页。pagesetup 的纸张大小宽度将无效,pagesetup 的其他设置仍然有效。
imgOptions.setAllColumnsInOnePagePerSheet(true);
imgOptions.setQuality(50);
// 指示当单元格字体不兼容时是否只替换字符的字体。
imgOptions.setFontSubstitutionCharGranularity(true);
// Get the first worksheet.
final WorksheetCollection worksheets = book.getWorksheets();
for (int i = 0; i < worksheets.getCount(); i++) {
// Create a SheetRender object for the target sheet
final Worksheet sheet = worksheets.get(i);
sheet.getPageSetup().setPrintGridlines(true);
sheet.getCells().deleteBlankRows();
sheet.getCells().deleteBlankColumns();
SheetRender sr = new SheetRender(worksheets.get(i), imgOptions);
// for (int j = 0; j < sr.getPageCount(); j++) {
// // Generate an image for the worksheet
// final String name = “aaa.jpg”;
//
// sr.toImage(j, name);
// }
}
I don’t understand what you mean very much. What I want to express is that when I convert xlsx to jpgs, the effect of the conversion is very different from that of xlsx, and it feels very strange.
@zyx
I mean the xlsx file has changed after performing your operation.
The jpg is generated based on the xlsx after the operation.
The displayed effect of xlsx after operation is the same as that of jpg.
So there is no problem. res.png (149.4 KB)