将单元格的HTML字符串值导出到数据表
Contents
[
Hide
]
可能的使用场景
使用Aspose.Cells API,开发人员可以在导出工作表数据时用相关HTML字符串(基于单元格值)填充DataTable。本文档说明了如何使用Aspose.Cells API导出格式化单元格数据的HTML字符串以填充DataTable。
将单元格的HTML字符串值导出到DataTable
以下示例代码说明了如何在从工作表导出数据到DataTable时导出单元格的HTML字符串值。请参阅示例Excel文件,以及屏幕截图和控制台输出以供参考。
屏幕截图
示例代码
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 sample Excel file | |
Workbook wb = new Workbook(sourceDir + "sampleExportTableAsHtmlString.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Specify export table options and set ExportAsHtmlString to true | |
ExportTableOptions opts = new ExportTableOptions(); | |
opts.ExportColumnName = false; | |
opts.ExportAsHtmlString = true; | |
//Export the cells data to data table with the specified export table options | |
DataTable dt = ws.Cells.ExportDataTable(0, 0, 3, 3, opts); | |
//Print the cell html string value that is in third row and second column | |
Console.WriteLine(dt.Rows[2][1].ToString()); |
控制台输出
<Font Style="FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #00b0f0;Background-Color: #ffe699;">Crow</Font>