Workbook book = new Workbook("/Users/zyx/Desktop/974246-NPD-HC(1).xlsx.xlsx");
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageType(ImageType.JPEG);
final String filename = "/Users/zyx/Desktop/excelImage/aaa";
// Get the first worksheet.
final WorksheetCollection worksheets = book.getWorksheets();
List<String> list = new ArrayList(worksheets.getCount() * 4);
for (int i = 0; i < worksheets.getCount(); i++) {
// Create a SheetRender object for the target sheet
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 = filename + "sheet" + (i+1) + "_" + (j+1) + ".jpg";
sr.toImage(j, name);
list.add(name);
}
}
if(Objects.nonNull(book)){
book.dispose();
}
We have logged the issue as “CELLSJAVA-43476” in our database for investigations of low quality images. Once we will have some news for you, we will update you in this topic.
Please extend the horizontal and vertical resolutions, it will enhance the quality of the rendered JPG images. See the sample lines (in bold) of code for your reference:
e.g. Sample code:
…
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageType(ImageType.JPEG); imgOptions.setHorizontalResolution(300); imgOptions.setVerticalResolution(300);
…
Let us know if you still see any low quality images.
Please note, there are lots of cells with font settings to “Calibri”, however the font “Calibri” can’t render Chinese characters properly. So, please set imgOptions.setDefaultFont("宋体") to prefer to use font “宋体” in this case. Also set horizontal and vertical resolution to further higher value to get better image.
e.g. Sample code:
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageType(ImageType.JPEG);
imgOptions.setHorizontalResolution(600);
imgOptions.setVerticalResolution(600);
imgOptions.setDefaultFont("宋体");
If you could take the print preview of the sheet, you will also notice there are no gridlines. If you want to render gridlines of the sheet, you may use the PageSetup option. See the sample line of code: worksheets.get(i).getPageSetup().setPrintGridlines(true);
You cannot specify series of fonts (list) using imgOptions.setDefaultFont. However, you can try to use the method, i.e., FontConfigs.SetFontSubstitutes(string originalFontName, string[] substituteFontNames)
Please note, you need to specify the parameter ‘orginalFontName’ used in the source file.