将打印区域范围导出为HTML
Contents
[
Hide
]
可能的使用场景
这是一个常见情况,我们需要将选定的单元格范围而不是整个工作表导出为 HTML。此功能已经可用于 PDF 渲染,现在您也可以对 HTML 进行此任务。首先在工作表的页面设置对象中设置打印区域。然后使用 HtmlSaveOptions.ExportPrintAreaOnly 标志仅导出选定的范围。
示例代码
下面的示例代码加载一个工作簿,然后将打印区域导出到 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-.NET | |
// Load the Excel file. | |
Workbook wb = new Workbook(sourceDir + "sampleInlineCharts.xlsx"); | |
// Access the sheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Set the print area. | |
ws.PageSetup.PrintArea = "D2:M20"; | |
// Initialize HtmlSaveOptions | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
// Set flag to export print area only | |
options.ExportPrintAreaOnly = true; | |
//Save to HTML format | |
wb.Save(outputDir + "outputInlineCharts.html", options); |