将打印区域范围导出为HTML

可能的使用场景

这是一个常见情况,我们需要将选定的单元格范围而不是整个工作表导出为 HTML。此功能已经可用于 PDF 渲染,现在您也可以对 HTML 进行此任务。首先在工作表的页面设置对象中设置打印区域。然后使用 HtmlSaveOptions.export_print_area_only 标志仅导出选定的范围。

示例代码

下面的示例代码加载一个工作簿,然后将打印区域导出到 HTML。用于测试此功能的示例文件可以从以下链接下载:

sampleInlineCharts.xlsx

from aspose.cells import HtmlSaveOptions, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Load the Excel file.
wb = Workbook(sourceDir + "sampleInlineCharts.xlsx")
# Access the sheet
ws = wb.worksheets[0]
# Set the print area.
ws.page_setup.print_area = "D2:M20"
# Initialize HtmlSaveOptions
options = HtmlSaveOptions()
# Set flag to export print area only
options.export_print_area_only = True
# Save to HTML format
wb.save(outputDir + "outputInlineCharts.html", options)