Adatta automaticamente colonne e righe durante il caricamento di HTML in Workbook
Possibili Scenari di Utilizzo
Puoi adattare automaticamente colonne e righe durante il caricamento del tuo file HTML all’interno dell’oggetto Workbook. Imposta la proprietà HtmlLoadOptions.AutoFitColsAndRows su true per questo scopo.
Adatta automaticamente colonne e righe durante il caricamento di HTML in Workbook
Il codice di esempio seguente carica prima l’HTML di esempio nel Workbook senza alcuna opzione di caricamento e lo salva in formato XLSX. Quindi carica di nuovo l’HTML di esempio nel Workbook ma questa volta lo carica dopo aver impostato la proprietà HtmlLoadOptions.AutoFitColsAndRows su true e lo salva in formato XLSX. Si prega di scaricare entrambi i file excel di output, cioè File Excel di Output Senza AutoFitColsAndRows e File Excel di Output Con AutoFitColsAndRows. La seguente schermata mostra l’effetto della proprietà HtmlLoadOptions.AutoFitColsAndRows su entrambi i file excel di output.
Codice di Esempio
// 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"); |