
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
aspose.cells.node.samples
Advanced tools
Aspose.Cells for Node.js via C++ is a powerful and robust library designed for high-performance spreadsheet manipulation and management within Node.js applications. It offers a comprehensive set of features that enable developers to create, edit, convert, and render Excel files programmatically. Supporting all major Excel formats, including XLS, XLSX, XLSM, and more, it ensures compatibility and flexibility. This makes Aspose.Cells for Node.js via C++ a versatile tool for a wide range of data processing and management tasks, providing developers with a complete and efficient solution for integrating comprehensive Excel functionality into their Node.js applications.
const AsposeCells = require("aspose.cells.node");
var workbook = new AsposeCells.Workbook(AsposeCells.FileFormatType.Xlsx);
workbook.worksheets.get(0).cells.get("A1").putValue("Hello World");
workbook.save("hello-world.xlsx");
const fs = require("fs");
const { Workbook, SaveFormat } = require("aspose.cells.node");
Workbook.openAsync("example.xlsx")
.then(workbook => {
workbook.calculateFormulaAsync()
.then(() => {
workbook.saveAsync(SaveFormat.Pdf)
.then((buffer) => {
var writeStream = fs.createWriteStream("example.pdf");
writeStream.write(buffer);
writeStream.end();
})
.catch(error => {
console.error(error);
});
})
.catch(error => {
console.error(error);
});
})
.catch(error => {
console.error(error);
});
import AsposeCells from "aspose.cells.node";
const { Workbook, FileFormatType } = AsposeCells;
var workbook = new Workbook(FileFormatType.Xlsx);
workbook.worksheets.get(0).cells.get("A1").putValue("Hello World");
workbook.save("hello-world.xlsx");
Note: Please save the above code as example.mjs file and run it using node example.mjs
.
const { Workbook } = require("aspose.cells.node");
var workbook = new Workbook("example.xlsx");
workbook.save("pdf-example.pdf");
const { Workbook, Color } = require("aspose.cells.node");
var workbook = new Workbook();
var style = workbook.createStyle();
style.font.setName("Times New Roman");
style.font.color = Color.Blue;
for (var i = 0; i < 10; i++) {
var cell = workbook.worksheets.get(0).cells.get(0, i);
cell.putValue(i);
cell.setStyle(style);
}
workbook.save("style-example.xlsx");
const { Workbook, SaveFormat } = require("aspose.cells.node");
var workbook = new Workbook();
var sheetIndex = workbook.worksheets.add();
var worksheet = workbook.worksheets.get(sheetIndex);
// adding a picture at "F6" cell
worksheet.pictures.add(5, 5, "image.gif");
workbook.save("picture-example.xls", SaveFormat.Excel97To2003);
const { Workbook, CalculationOptions, AbstractCalculationEngine } = require("aspose.cells.node");
class CustomFunction extends AbstractCalculationEngine {
constructor() {
super();
}
calculate(data) {
var functionName = data.functionName;
if (functionName == "myarrayfunch") {
var r = new Array();
r[0] = [1.0, 2.0, 3.0, 4.0, 5.0];
data.calculatedValue = r;
return;
}
else if (functionName == "myarrayfuncv") {
var r = new Array();
r[0] = [1.0];
r[1] = [2.0];
r[2] = [3.0];
r[3] = [4.0];
r[4] = [5.0];
data.calculatedValue = r;
return;
}
else if (functionName == "myrange") {
data.calculatedValue = data.worksheet.cells.createRange("A1", "F1");
return;
}
else if (functionName == "UDFTest") {
data.calculatedValue = data.getParamValue(0);
}
}
};
var wb = new Workbook();
var sheet = wb.worksheets.get(0);
var cells = sheet.cells;
// Create table with data
var range = cells.createRange("B3:D5");
var arr = new Array();
arr[0] = ["AccountNum", "UDF", "Normal"];
arr[1] = ["Row01", "", ""];
arr[2] = ["Row02", "", ""];
range.value = arr;
var firstRow = range.firstRow;
var firstColumn = range.firstColumn;
var endRow = firstRow + range.rowCount;
var endColumn = firstColumn + range.columnCount;
sheet.listObjects.add(firstRow, firstColumn, endRow, endColumn, true);
// Populate formulas
cells.get("C5").formula = "=UDFTest([@AccountNum])";
cells.get("C4").formula = "=UDFTest([@AccountNum])"; // UDF formula
cells.get("D5").formula = "=[@AccountNum]";
cells.get("D4").formula = "=[@AccountNum]"; // Built-in formula comparison
// Calculate workbook
var opt = new CalculationOptions();
var customFunction = new CustomFunction();
opt.customEngine = customFunction;
wb.calculateFormula(opt);
console.log("Row01" == cells.get("C4").stringValue);
console.log("Row02" == cells.get("C5").stringValue);
console.log("Row01" == cells.get("D4").stringValue);
console.log("Row02" == cells.get("D5").stringValue);
var workbook = new Workbook();
var worksheet = workbook.worksheets.get(0);
// Get the cells collection in the sheet
var cells = worksheet.cells;
cells.get("A1").setArrayFormula("=myarrayfunch()", 1, 5);
cells.get("A2").setArrayFormula("=myarrayfuncv()", 5, 1);
cells.get("A7").setArrayFormula("=A1:E1*100", 1, 5);
cells.get("A8").setFormula("=sum(myrange())", 100);
var cf = new CustomFunction();
var cOpt = new CalculationOptions();
cOpt.customEngine = cf;
workbook.calculateFormula(cOpt);
for (var i = 0; i < 5; i++) {
console.log(i + 1.0 == cells.get(0, i).doubleValue);
}
for (var i = 1; i < 6; i++) {
console.log(i == cells.get(i, 0).doubleValue);
}
for (var i = 0; i < 5; i++) {
console.log(i * 100 + 100.0 == cells.get(6, i).doubleValue);
}
console.log(cells.get("A8").doubleValue == 15);
console.log("done");
Please refer to aspose.cells.node.samples package for more code samples.
Product Page | Product Documentation | Blog |API Reference | Free Support | Temporary License
FAQs
This is the sample code using aspose.cells.node library.
The npm package aspose.cells.node.samples receives a total of 8 weekly downloads. As such, aspose.cells.node.samples popularity was classified as not popular.
We found that aspose.cells.node.samples demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.