在输出中单独导出工作表 CSS HTML
Contents
[
Hide
]
可能的使用场景
Aspose.Cells 提供将Excel文件转换为HTML时单独导出工作表CSS的功能,请使用HtmlSaveOptions.ExportWorksheetCSSSeparately用于此目的的属性并将其设置为真的同时将 Excel 文件保存为 HTML 格式。
在输出中单独导出工作表 CSS HTML
以下示例代码创建一个 Excel 文件,在单元格中添加一些文本B5在红色的颜色,然后使用 HTML 格式将其保存HtmlSaveOptions.ExportWorksheetCSSSeparately财产。请参阅输出 HTML生成的代码供参考。你会找到样式表.css在其中作为示例代码的结果。
示例代码
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 | |
//Create workbook object | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access cell B5 and put value inside it | |
Cell cell = ws.Cells["B5"]; | |
cell.PutValue("This is some text."); | |
//Set the style of the cell - font color is Red | |
Style st = cell.GetStyle(); | |
st.Font.Color = Color.Red; | |
cell.SetStyle(st); | |
//Specify html save options - export worksheet css separately | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.ExportWorksheetCSSSeparately = true; | |
//Save the workbook in html | |
wb.Save("outputExportWorksheetCSSSeparately.html", opts); |
导出单张工作簿到HTML
当使用 Aspose.Cells 将具有多个工作表的工作簿转换为 HTML 时,它会创建一个 HTML 文件以及一个包含 CSS 和多个 HTML 文件的文件夹。在浏览器中打开此 HTML 文件时,选项卡可见。具有单个工作表的工作簿在转换为 HTML 时需要相同的行为。之前没有为单个工作表工作簿创建单独的文件夹,只创建了 HTML 文件。这样的 HTML 文件在浏览器中打开时不显示选项卡。 MS Excel 还为单个工作表创建了适当的文件夹和 HTML,因此使用 Aspose.Cells API 实现了相同的行为。示例文件可以从以下链接下载,用于下面的示例代码:
示例代码
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 sample Excel file containing single sheet only | |
Workbook wb = new Workbook(sourceDir + "sampleSingleSheet.xlsx"); | |
// Specify HTML save options | |
Aspose.Cells.HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions(); | |
// Set optional settings if required | |
options.Encoding = System.Text.Encoding.UTF8; | |
options.ExportImagesAsBase64 = true; | |
options.ExportGridLines = true; | |
options.ExportSimilarBorderStyle = true; | |
options.ExportBogusRowData = true; | |
options.ExcludeUnusedStyles = true; | |
options.ExportHiddenWorksheet = true; | |
//Save the workbook in Html format with specified Html Save Options | |
wb.Save(outputDir + "outputSampleSingleSheet.htm", options); |