ワークブックに HTML をロードする際の列と行の自動調整
Contents
[
Hide
]
考えられる使用シナリオ
HTML ファイルを**ワークブック**物体。を設定してください**HtmlLoadOptions.AutoFitColsAndRows**プロパティへ**真実**この目的のために。
ワークブックに HTML をロードする際の列と行の自動調整
次のサンプル コードは、最初にサンプル HTML を読み込みオプションなしで Workbook に読み込み、XLSX 形式で保存します。次に、サンプル HTML を再度 Workbook に読み込みますが、今回は、設定後に HTML を読み込みます。HtmlLoadOptions.AutoFitColsAndRowsプロパティへ真実XLSX 形式で保存します。両方の出力 Excel ファイルをダウンロードしてください。AutoFitColsAndRows なしで Excel ファイルを出力するとAutoFitColsAndRows を使用して Excel ファイルを出力する.次のスクリーンショットは、**HtmlLoadOptions.AutoFitColsAndRows**両方の出力 Excel ファイルのプロパティ。
サンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |