Çalışma Kitabında HTML yüklenirken Sütunları ve Satırlar Otomatik Uydurma
Olası Kullanım Senaryoları
HTML dosyanızı Çalışma Kitabının içine yüklerken sütun ve satırları otomatik olarak uyarlatabilirsiniz. Bu amaçla lütfen HtmlLoadOptions.auto_fit_cols_and_rows özelliğini true olarak ayarlayın.
HTML yüklenirken Sütunları ve Satırları Otomatik Uydurma
Aşağıdaki örnek kod, önce örnek HTML’yi herhangi bir yükleme seçeneği olmadan Çalışma Kitabına yükler ve XLSX formatında kaydeder. Daha sonra örnek HTML’yi tekrar Çalışma Kitabına yükler, bu sefer HtmlLoadOptions.auto_fit_cols_and_rows özelliğini true olarak ayarladıktan sonra XLSX formatında kaydeder. Lütfen hem otomatik uyarlama sütunları ve satırları olmadan OtomatikUyarlanmamışSütunveSatırÇıktıExcelDosyası hem de otomatik uyarlama sütunları ve satırları olan OtomatikUyarlanmışSütunveSatırÇıktıExcelDosyası dosyalarını indirin. Aşağıdaki ekran görüntüsü, HtmlLoadOptions.auto_fit_cols_and_rows özelliğinin her iki çıktı Excel dosyasındaki etkisini gösterir.
Örnek Kod
from aspose.cells import HtmlLoadOptions, Workbook | |
from io import BytesIO | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Sample HTML. | |
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. | |
ms = BytesIO(sampleHtml.encode("utf-8")) | |
# Load memory stream into workbook. | |
wb = Workbook(ms) | |
# Save the workbook in xlsx format. | |
wb.save(dataDir + "outputWithout_AutoFitColsAndRows.xlsx") | |
# Specify the HTMLLoadOptions and set AutoFitColsAndRows = true. | |
opts = HtmlLoadOptions() | |
opts.auto_fit_cols_and_rows = True | |
# Load memory stream into workbook with the above HTMLLoadOptions. | |
wb = Workbook(ms, opts) | |
# Save the workbook in xlsx format. | |
wb.save(dataDir + "outputWith_AutoFitColsAndRows.xlsx") |