转换Excel到高分辨率图像
Contents
[
Hide
]
随着高分辨率屏幕的普及,以默认96 DPI生成的图像往往显得模糊不清。为了确保在高分辨率屏幕上的清晰度,必须以更高的DPI生成图像。Aspose.Cells提供设置 ImageOrPrintOptions.HorizontalResolution 和 ImageOrPrintOptions.VerticalResolution 的功能,从而可以从Excel文件创建在高分辨率显示器上清晰锐利的高质量图像。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Load the Excel file | |
Workbook workbook = new Workbook("input.xlsx"); | |
// Create an instance of ImageOrPrintOptions | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set horizontal and vertical resolution to 300 DPI | |
options.setHorizontalResolution(300); | |
options.setVerticalResolution(300); | |
// Set the image type | |
options.setImageType(ImageType.PNG); | |
// Get the worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Create a SheetRender instance | |
SheetRender render = new SheetRender(sheet, options); | |
// Generate and save the image | |
render.toImage(0, "output.png"); |