Spalten und Zeilen automatisch anpassen beim Laden von HTML in Arbeitsmappe
Mögliche Verwendungsszenarien
Sie können Spalten und Zeilen automatisch anpassen, während Sie Ihre HTML-Datei im Workbook-Objekt laden. Bitte setzen Sie die HtmlLoadOptions.AutoFitColsAndRows-Eigenschaft zu true für diesen Zweck.
Spalten und Zeilen automatisch anpassen beim Laden von HTML in Arbeitsmappe
Der folgende Beispielcode lädt zunächst den Beispiel-HTML-Code ohne Ladeoptionen in Workbook und speichert ihn im XLSX-Format. Danach wird der Beispiel-HTML-Code erneut in Workbook geladen, diesmal jedoch nachdem die HtmlLoadOptions.AutoFitColsAndRows-Eigenschaft auf true gesetzt wurde, und im XLSX-Format gespeichert. Bitte laden Sie beide Ausgabe-Excel-Dateien herunter, d.h. Ausgabe Excel-Datei ohne AutoFitColsAndRows und Ausgabe Excel-Datei mit AutoFitColsAndRows. Der folgende Screenshot zeigt die Wirkung der HtmlLoadOptions.AutoFitColsAndRows-Eigenschaft auf beide Ausgabe-Excel-Dateien.

Beispielcode
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| // The path to the documents directory. | |
| string dataDir = "./"; | |
| //Sample HTML. | |
| string sampleHtml = "<html><body><table><tr><td>This is sample text.</td><td>Some text.</td></tr><tr><td>This is another sample text.</td><td>Some text.</td></tr></table></body></html>"; | |
| //Load html string into memory stream. | |
| MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(sampleHtml)); | |
| //Load memory stream into workbook. | |
| Workbook wb = new Workbook(ms); | |
| //Save the workbook in xlsx format. | |
| wb.Save(dataDir + "outputWithout_AutoFitColsAndRows.xlsx"); | |
| //Specify the HTMLLoadOptions and set AutoFitColsAndRows = true. | |
| HtmlLoadOptions opts = new HtmlLoadOptions(); | |
| opts.AutoFitColsAndRows = true; | |
| //Load memory stream into workbook with the above HTMLLoadOptions. | |
| wb = new Workbook(ms, opts); | |
| //Save the workbook in xlsx format. | |
| wb.Save(dataDir + "outputWith_AutoFitColsAndRows.xlsx"); |