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 Eigenschaft HtmlLoadOptions.AutoFitColsAndRows auf true für diesen Zweck.

Spalten und Zeilen automatisch anpassen beim Laden von HTML in Arbeitsmappe

Der folgende Beispielscode lädt zuerst das Beispiels-HTML in die Arbeitsmappe ohne Ladeoptionen und speichert es im XLSX-Format. Dann lädt er erneut das Beispiels-HTML in die Arbeitsmappe, aber diesmal lädt er das HTML, nachdem die Eigenschaft HtmlLoadOptions.AutoFitColsAndRows auf true gesetzt wurde, und speichert es im XLSX-Format. Bitte laden Sie beide Ausgabedateien herunter, d.h. Ausgabedatei ohne AutofitColsAndRows und Ausgabedatei mit AutofitColsAndRows. Der folgende Screenshot zeigt die Wirkung der Eigenschaft HtmlLoadOptions.AutoFitColsAndRows auf beide Ausgabedateien.

todo:image_alt_text

Beispielcode

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(AutoFitColumnsRowsLoadingHTML.class) + "LoadingSavingConvertingAndManaging/";
//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 byte array input stream
ByteArrayInputStream bais = new ByteArrayInputStream(sampleHtml.getBytes());
//Load byte array stream into workbook.
Workbook wb = new Workbook(bais);
//Save the workbook in xlsx format.
wb.save(dataDir + "outputWithout_AutoFitColsAndRows.xlsx");
//Specify the HtmlLoadOptions and set AutoFitColsAndRows = true.
HtmlLoadOptions opts = new HtmlLoadOptions();
opts.setAutoFitColsAndRows(true);
//Load byte array stream into workbook with the above HtmlLoadOptions.
bais.reset();
wb = new Workbook(bais, opts);
//Save the workbook in xlsx format.
wb.save(dataDir + "outputWith_AutoFitColsAndRows.xlsx");