这个简短的教程描述了如何使用 Node.js 在 Excel 中旋转单元格。它包含设置 IDE 环境的所有详细信息、编写应用程序的步骤列表,以及用于使用 Node.js 在 Excel 中旋转单元格的可运行示例代码。您将学习设置单元格中文本样式的不同选项。
使用 Node.js 在 Excel 中旋转单元格的步骤
- 将 IDE 设置为使用 Aspose.Cells for Node.js 通过 Java 旋转单元格
- 创建一个 workbook,访问工作表,并访问所需的单元格
- 在目标单元格中设置一些示例文本
- 访问目标单元格的 Style 对象
- 调用Style.setRotationAngle()旋转单元格中的内容
- 在保存输出工作簿之前将样式设置回目标单元格
这些步骤定义了使用 node.js* 更改 Excel 中的文本方向的过程。该过程是通过访问单元格并使用 getStyle() 方法获取其样式来启动的。 Style 类包含 setRotationAngle() 方法,最终用于设置文本旋转角度。
使用 Node.js 旋转 Excel 单元格的代码
const fs = require('fs'); | |
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Set the license | |
new aspose.cells.License().setLicense("License.lic"); | |
// Create a workbook | |
var wb = new aspose.cells.Workbook(); | |
// Access the worksheet | |
var ws = wb.getWorksheets().get(0); | |
// Access the cells collection | |
var cells = ws.getCells(); | |
// Access the target cell | |
var targetCell = cells.get("D5"); | |
// Set some text in the cell | |
targetCell.putValue("Sample text for rotation"); | |
// Get the cell style | |
var style = targetCell.getStyle(); | |
// Set the rotation angle | |
style.setRotationAngle(60); | |
// Set the cell style | |
targetCell.setStyle(style); | |
// Save the workbook | |
wb.save("output.xlsx"); | |
console.log("Cell rotated successfully"); |
此示例代码演示了如何使用 Node.js 旋转 Excel 单元格。您可以将上下角度设置为 255,向上为 90,向下为 -90,0 为不旋转。您还可以在 Style 对象中设置其他属性,例如 setBackgroundColor()、setBorder() 和 setForegroundColor() 等。
本文教会了我们如何使用 Node.js 在 Excel 中旋转单元格。如果您想在工作簿中添加验证,请参阅有关 如何使用 Node.js 在 Excel 中制作下拉列表 的文章。