这个简短的教程将指导您使用 Node.js 自动调整 Excel。它包含设置应用程序开发环境的详细说明、步骤列表以及演示如何使用 Node.js 在 Excel 中自动调整单元格大小**的运行示例代码。使用各种重载方法根据您的要求自动调整行和列中的单元格大小。
使用 Node.js 在 Excel 中自动调整的步骤
- 将 IDE 设置为使用 Aspose.Cells for Node.js 通过 Java 自动调整 Excel
- 使用 Workbook 类对象加载 Excel 文件
- 访问要自动调整行和列的目标工作表
- 使用 autoFitRows() 方法自动调整目标工作表中的行
- 使用 autoFitColumns() 方法自动调整列
- 保存生成的 Excel 文件,其中包含自动调整的行和列
这些步骤定义了使用 Node.js 自动调整行并设置列高的过程。首先加载 Excel 文件、访问工作表并调用 autoFitRows() 和 autoFitColumns()。根据单元格中的内容设置单元格的高度和宽度后保存工作簿。
使用 Node.js 自动调整 Excel 列的代码
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
const fs = require('fs'); | |
//Set the license | |
new aspose.cells.License().setLicense("License.lic"); | |
// Create a new Workbook. | |
var workbook = aspose.cells.Workbook("AutofitInput.xlsx"); | |
// Get the first worksheet. | |
var sheet = workbook.getWorksheets().get(0); | |
sheet.autoFitRows(); | |
sheet.autoFitColumns(); | |
// Save the Excel file | |
workbook.save("Updated.xlsx"); | |
console.log('Autofit rows performed successfully'); |
此代码片段演示了如何使用 Node.js* 设置 Excel 自动高度。您可以使用 AutoFitterOptions 类对象作为参数来设置自动调整合并单元格的标志、定义自动调整换行文本的类型、格式设置策略以及忽略隐藏的行和列。
在本主题中,我们学习了如何设置 Excel 文件中单元格的高度和宽度。如果您想在 Excel 中应用条件格式,请参阅有关 如何使用 Node.js 在 Excel 中应用条件格式 的文章。