Node.jsとC++を使用してHTMLのインポート時に余分なスペースを削除
Contents
[
Hide
]
HtmlLoadOptions.getDeleteRedundantSpaces() プロパティを使用し、それを true に設定して、改行タグの後に来るすべての余分なスペースを削除してください。デフォルトではこのプロパティは false であり、余分なスペースは出力されるExcelファイルに保持されます。
HTMLLoadOptions.deleteRedundantSpacesプロパティをfalseとtrueに設定した場合の効果
このプロパティをfalseとtrueに設定した効果を以下のスクリーンショットで示します。
HTMLをインポートする際に改行後の余分なスペースを削除する効果
プログラミングサンプル
以下のサンプルコードは、HtmlLoadOptions.getDeleteRedundantSpaces()プロパティの使用例を示しています。出力結果を上記スクリーンショットのように得るには、trueまたはfalseに設定してください。
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// Sample Html containing redundant spaces after <br> tag
const html = "<html> <body> <table> <tr> <td> <br> This is sample data <br> This is sample data<br> This is sample data</td> </tr> </table> </body> </html>";
// Convert Html to byte array
const byteArray = Buffer.from(html, 'utf-8');
// Set Html load options and keep precision true
const loadOptions = new AsposeCells.HtmlLoadOptions(AsposeCells.LoadFormat.Html);
loadOptions.setDeleteRedundantSpaces(true);
// Convert byte array into stream
const stream = Uint8Array.from(byteArray);
// Create workbook from stream with Html load options
const workbook = new AsposeCells.Workbook(stream, loadOptions);
// Access first worksheet
const sheet = workbook.getWorksheets().get(0);
// Auto fit the sheet columns
sheet.autoFitColumns();
// Save the workbook
const outputDir = path.join(__dirname, "output");
workbook.save(path.join(outputDir, "outputDeleteRedundantSpacesWhileImportingFromHtml.xlsx"), AsposeCells.SaveFormat.Xlsx);