Çalışma Kitabında HTML yüklenirken Sütunları ve Satırları Otomatik Sığdır

Olası Kullanım Senaryoları

HTML dosyanızı yüklerken sütunları ve satırları otomatik sığdırabilirsiniz.Çalışma Kitabınesne. Lütfen ayarlayınHtmlLoadOptions.AutoFitColsAndRows mülkiyetdoğrubu amaç için.

Çalışma Kitabında HTML yüklenirken Sütunları ve Satırları Otomatik Sığdır

Aşağıdaki örnek kod, önce HTML örneğini herhangi bir yükleme seçeneği olmadan Çalışma Kitabı’na yükler ve XLSX biçiminde kaydeder. Daha sonra HTML örneğini tekrar Çalışma Kitabı’na yükler, ancak bu sefer, ayarladıktan sonra HTML’i yükler.HtmlLoadOptions.AutoFitColsAndRows mülkiyetdoğruve XLSX formatında kaydeder. Lütfen her iki çıktı excel dosyasını da indirin, yaniExcel Dosyasını AutoFitColsAndRows Olmadan Çıkarın veAutoFitColsAndRows ile Çıktı Excel Dosyası . Aşağıdaki ekran görüntüsü etkisini göstermektedir**HtmlLoadOptions.AutoFitColsAndRows**her iki çıktı excel dosyasındaki özellik.

yapılacaklar:resim_alternatif_metin

Basit kod

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