Spalten und Zeilen automatisch anpassen, während HTML in die Arbeitsmappe geladen wird

Mögliche Nutzungsszenarien

Sie können Spalten und Zeilen automatisch anpassen, während Sie Ihre HTML-Datei in das Workbook-Objekt laden. Bitte setzen Sie die**HtmlLoadOptions.AutoFitColsAndRows** Eigentum zu**wahr**für diesen Zweck.

Spalten und Zeilen automatisch anpassen, während HTML in die Arbeitsmappe geladen wird

Der folgende Beispielcode lädt zunächst das Beispiel HTML ohne Ladeoptionen in die Arbeitsmappe und speichert es im Format XLSX. Es lädt dann erneut das Beispiel HTML in die Arbeitsmappe, aber dieses Mal lädt es das HTML nach dem Festlegen von**HtmlLoadOptions.AutoFitColsAndRows** Eigentum zu**wahr**und speichert es im Format XLSX. Bitte laden Sie beide ausgegebenen Excel-Dateien herunter, dhExcel-Datei ohne AutoFitColsAndRows ausgeben undExcel-Datei mit AutoFitColsAndRows ausgeben . Der folgende Screenshot zeigt die Wirkung von**HtmlLoadOptions.AutoFitColsAndRows**-Eigenschaft in beiden Excel-Ausgabedateien.

todo: Bild_alt_Text

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 = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//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");