Çalışma Kitabında HTML yüklenirken Sütunları ve Satırları Otomatik Sığdır
Olası Kullanım Senaryoları
HTML dosyanızı Workbook nesnesine yüklerken sütunları ve satırları otomatik olarak sığdırabilirsiniz. Lütfen ayarlayın**HtmlLoadOptions.AutoFitColsAndRows** mülkiyet**doğru**bu 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.
Basit kod
// 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"); |