Export HTML String Value of the Cells to the DataTable
Possible Usage Scenarios
Using Aspose.Cells APIs, developers can fill a DataTable with corresponding HTML strings (based on cells values) while exporting worksheet data. This document explains how to export HTML strings for the formatted cells data to fill a DataTable using Aspose.Cells APIs.
Export HTML String Value of the Cells to the DataTable
The following sample code illustrates how to export HTML string value of the cells to the DataTable while exporting data from worksheet into DataTable. Please see the sample Excel file, its screenshot and the console output for a reference.
Screenshot
Sample Code
// 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()); |
Console Output
<Font Style="FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #00b0f0;Background-Color: #ffe699;">Crow</Font>