aspose.cells.node 24.12.0 → 25.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ## aspose.cells.node
2
+
1
3
  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.
2
4
 
3
5
  ## Key features
@@ -35,6 +37,46 @@ workbook.getWorksheets().get(0).getCells().get("A1").putValue("Hello World");
35
37
  workbook.save("hello-world.xlsx");
36
38
  ```
37
39
 
40
+ #### Open and save Excel file asynchronously
41
+ ``` js
42
+ const fs = require("fs");
43
+ const { Workbook, SaveFormat } = require("aspose.cells.node");
44
+
45
+ Workbook.openAsync("example.xlsx")
46
+ .then(workbook => {
47
+ workbook.calculateFormulaAsync()
48
+ .then(() => {
49
+ workbook.saveAsync(SaveFormat.Pdf)
50
+ .then((buffer) => {
51
+ var writeStream = fs.createWriteStream("example.pdf");
52
+ writeStream.write(buffer);
53
+ writeStream.end();
54
+ })
55
+ .catch(error => {
56
+ console.error(error);
57
+ });
58
+ })
59
+ .catch(error => {
60
+ console.error(error);
61
+ });
62
+
63
+ })
64
+ .catch(error => {
65
+ console.error(error);
66
+ });
67
+ ```
68
+
69
+ #### Use **import** of ES6
70
+ ``` js
71
+ import AsposeCells from "aspose.cells.node";
72
+ const { Workbook, FileFormatType } = AsposeCells;
73
+
74
+ var workbook = new Workbook(FileFormatType.Xlsx);
75
+ workbook.getWorksheets().get(0).getCells().get("A1").putValue("Hello World");
76
+ workbook.save("hello-world.xlsx");
77
+ ```
78
+ **Note**: Please save the above code as **example.mjs** file and run it using **`node example.mjs`**.
79
+
38
80
  ### Convert Excel XLSX File to PDF
39
81
  ``` js
40
82
  const { Workbook } = require("aspose.cells.node");
@@ -74,4 +116,107 @@ worksheet.getPictures().add(5, 5, "image.gif");
74
116
  workbook.save("picture-example.xls", SaveFormat.Excel97To2003);
75
117
  ```
76
118
 
119
+ ### Calculate Custom Functions
120
+ ```js
121
+ const { Workbook, CalculationOptions, AbstractCalculationEngine } = require("aspose.cells.node");
122
+
123
+ class CustomFunction extends AbstractCalculationEngine {
124
+ constructor() {
125
+ super();
126
+ }
127
+
128
+ calculate(data) {
129
+ var functionName = data.getFunctionName();
130
+ if (functionName == "myarrayfunch") {
131
+ var r = new Array();
132
+ r[0] = [1.0, 2.0, 3.0, 4.0, 5.0];
133
+ data.setCalculatedValue(r);
134
+ return;
135
+ }
136
+ else if (functionName == "myarrayfuncv") {
137
+ var r = new Array();
138
+ r[0] = [1.0];
139
+ r[1] = [2.0];
140
+ r[2] = [3.0];
141
+ r[3] = [4.0];
142
+ r[4] = [5.0];
143
+ data.setCalculatedValue(r);
144
+ return;
145
+ }
146
+ else if (functionName == "myrange") {
147
+ data.setCalculatedValue(data.getWorksheet().getCells().createRange("A1", "F1"));
148
+ return;
149
+ }
150
+ else if (functionName == "UDFTest") {
151
+ data.setCalculatedValue(data.getParamValue(0));
152
+ }
153
+ }
154
+ };
155
+
156
+ var wb = new Workbook();
157
+ var sheet = wb.getWorksheets().get(0);
158
+ var cells = sheet.getCells();
159
+
160
+ // Create table with data
161
+ var range = cells.createRange("B3:D5");
162
+ var arr = new Array();
163
+ arr[0] = ["AccountNum", "UDF", "Normal"];
164
+ arr[1] = ["Row01", "", ""];
165
+ arr[2] = ["Row02", "", ""];
166
+
167
+ range.setValue(arr);
168
+ var firstRow = range.getFirstRow();
169
+ var firstColumn = range.getFirstColumn();
170
+ var endRow = firstRow + range.getRowCount();
171
+ var endColumn = firstColumn + range.getColumnCount();
172
+ sheet.getListObjects().add(firstRow, firstColumn, endRow, endColumn, true);
173
+
174
+ // Populate formulas
175
+ cells.get("C5").setFormula("=UDFTest([@AccountNum])");
176
+ cells.get("C4").setFormula("=UDFTest([@AccountNum])"); // UDF formula
177
+
178
+ cells.get("D5").setFormula("=[@AccountNum]");
179
+ cells.get("D4").setFormula("=[@AccountNum]"); // Built-in formula comparison
180
+
181
+ // Calculate workbook
182
+ var opt = new CalculationOptions();
183
+ var customFunction = new CustomFunction();
184
+ opt.setCustomEngine(customFunction);
185
+ wb.calculateFormula(opt);
186
+
187
+ console.log("Row01" == cells.get("C4").getStringValue());
188
+ console.log("Row02" == cells.get("C5").getStringValue());
189
+ console.log("Row01" == cells.get("D4").getStringValue());
190
+ console.log("Row02" == cells.get("D5").getStringValue());
191
+
192
+
193
+ var workbook = new Workbook();
194
+ var worksheet = workbook.getWorksheets().get(0);
195
+
196
+ // Get the cells collection in the sheet
197
+ var cells = worksheet.getCells();
198
+ cells.get("A1").setArrayFormula("=myarrayfunch()", 1, 5);
199
+ cells.get("A2").setArrayFormula("=myarrayfuncv()", 5, 1);
200
+ cells.get("A7").setArrayFormula("=A1:E1*100", 1, 5);
201
+ cells.get("A8").setFormula("=sum(myrange())", 100);
202
+
203
+ var cf = new CustomFunction();
204
+ var cOpt = new CalculationOptions();
205
+ cOpt.setCustomEngine(cf);
206
+ workbook.calculateFormula(cOpt);
207
+ for (var i = 0; i < 5; i++) {
208
+ console.log(i + 1.0 == cells.get(0, i).getDoubleValue());
209
+ }
210
+ for (var i = 1; i < 6; i++) {
211
+ console.log(i == cells.get(i, 0).getDoubleValue());
212
+ }
213
+ for (var i = 0; i < 5; i++) {
214
+ console.log(i * 100 + 100.0 == cells.get(6, i).getDoubleValue());
215
+ }
216
+ console.log(cells.get("A8").getDoubleValue() == 15);
217
+ console.log("done");
218
+ ```
219
+
220
+ Please refer to [aspose.cells.node.samples](https://www.npmjs.com/package/aspose.cells.node.samples) package for more code samples.
221
+
77
222
  [Product Page](https://products.aspose.com/cells/nodejs-cpp) | [Product Documentation](https://docs.aspose.com/cells/nodejs-cpp/) | [Blog](https://blog.aspose.com/categories/aspose.cells-product-family/) |[API Reference](https://reference.aspose.com/cells/nodejs-cpp) | [Free Support](https://forum.aspose.com/c/cells) | [Temporary License](https://purchase.aspose.com/temporary-license)