将打印区域范围导出为HTML
Contents
[
Hide
]
可能的使用场景
这是一个非常常见的场景,我们需要将仅打印区域即所选单元格的范围导出为HTML,而不是整个工作表。这个功能已经在PDF渲染中可用,现在也可以在HTML中执行此任务。首先在工作表的页面设置对象中设置打印区域。然后仅使用 HtmlSaveOptions.ExportPrintAreaOnly 属性来仅导出所选范围。
导出打印区域范围至HTML的Java代码
以下示例代码加载一个工作簿,然后将打印范围导出至HTML。您可以从以下链接下载用于测试此功能的示例文件:
This file contains 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 wb = new Workbook(srcDir + "sampleInlineCharts.xlsx"); | |
// Access the sheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Set the print area. | |
ws.getPageSetup().setPrintArea("D2:M20"); | |
// Initialize HtmlSaveOptions | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
// Set flag to export print area only | |
options.setExportPrintAreaOnly(true); | |
//Save to HTML format | |
wb.save(outDir + "outputInlineCharts.html",options); |