这个简短的教程将指导 如何使用 Node.js 在 Excel 中显示公式。它具有 IDE 设置、步骤列表和可运行的示例代码,用于使用 Node.js 在 Excel 中显示公式。您还将学习在工作簿中计算公式的不同选项,而无需使用任何第三方工具或软件。
使用 Node.js 显示单元格公式的步骤
- 将 IDE 设置为使用 Aspose.Cells for Node.js 通过 Java 显示公式
- 创建一个 workbook,访问工作表,并在几个单元格中设置示例值
- 使用上述值也在单元格中设置公式
- Calculate 在单元格中显示结果值的公式
- 设置标志以显示公式而不是值并保存工作簿
这些步骤总结了如何使用 Node.js 在 Excel 中显示公式的过程。通过在工作表中设置值和公式,然后计算公式以在公式单元格中生成结果来实例化该过程。在最后一步中,通过提供值true”来调用 setShowFormulas() 方法,以在工作表中显示公式而不是值。
使用 Node.js 在 Excel 中显示公式的代码
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 first worksheet | |
var ws = wb.getWorksheets().get(0); | |
// Set cell values, and formulas and calculate formula | |
ws.getCells().get("A1").setValue(10); | |
ws.getCells().get("B1").setValue(20); | |
ws.getCells().get("C1").setFormula(" = A1 + B1"); | |
ws.calculateFormula(new aspose.cells.CalculationOptions(),false); | |
// Show formulas | |
ws.setShowFormulas(true); | |
// Save the workbook | |
wb.save("ExcelWithFormula.xlsx"); | |
console.log("Formulas displayed successfully"); |
此代码示例演示了使用 Node.js 在 Excel 中显示单元格公式的功能。您可以使用 setShowFormulas() 方法通过将标志分别设置为 true 或 false 来显示或隐藏目标工作表中的公式。同样,您可以使用 getShowFormulas() 方法来检查公式的显示状态,而无需在 Excel 或任何其他第三方工具中打开工作簿。
这个简短的教程描述了如何使用node.js在Excel中显示所有公式。如果您想了解删除公式但保留值的过程,请参阅有关 如何使用 Node.js 删除 Excel 中的列 的文章。