Exportieren Sie den HTML-Zeichenfolgenwert von Cells in die DataTable

Mögliche Nutzungsszenarien

Mithilfe von Aspose.Cells-APIs können Entwickler eine DataTable mit entsprechenden HTML-Strings (basierend auf Zellenwerten) füllen, während sie Arbeitsblattdaten exportieren. In diesem Dokument wird erläutert, wie HTML-Zeichenfolgen für die formatierten Zellendaten exportiert werden, um eine DataTable mithilfe von Aspose.Cells-APIs zu füllen.

Exportieren Sie den HTML-Zeichenfolgenwert von Cells in die DataTable

Der folgende Beispielcode veranschaulicht, wie der Zeichenfolgenwert HTML der Zellen in die DataTable exportiert wird, während Daten aus dem Arbeitsblatt in die DataTable exportiert werden. Bitte sehen Sie sich … anBeispiel-Excel-Datei, sein Screenshot und die Konsolenausgabe als Referenz.

Bildschirmfoto

todo: Bild_alt_Text

Beispielcode

// 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());

Konsolenausgabe

 <Font Style="FONT-FAMILY: Calibri;FONT-SIZE: 11pt;COLOR: #00b0f0;Background-Color: #ffe699;">Crow</Font>