Adatta automaticamente colonne e righe durante il caricamento di HTML in Workbook
Possibili Scenari di Utilizzo
È possibile adattare automaticamente le colonne e le righe durante il caricamento del file HTML all’interno dell’oggetto Workbook. Impostare la proprietà HtmlLoadOptions.AutoFitColsAndRows su true a tale scopo.
Adatta automaticamente colonne e righe durante il caricamento di HTML in Workbook
Il seguente codice di esempio carica innanzitutto l’HTML di esempio in un Workbook senza alcuna opzione di caricamento e lo salva in formato XLSX. Quindi carica nuovamente l’HTML di esempio in un Workbook ma questa volta, carica l’HTML dopo aver impostato la proprietà HtmlLoadOptions.AutoFitColsAndRows su true e lo salva in formato XLSX. Si prega di scaricare entrambi i file di output di Excel, cioè File di Excel di output senza AutoFitColsAndRows e File di Excel di output con AutoFitColsAndRows. La seguente schermata mostra l’effetto della proprietà HtmlLoadOptions.AutoFitColsAndRows su entrambi i file di output di Excel.
Codice di Esempio
// 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"); |