aspose.cells.node.samples 25.1.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/End User License Agreement.html +10 -0
- package/README.md +222 -0
- package/input/AutoFilter.xlsx +0 -0
- package/input/Book1.xls +0 -0
- package/input/Chart.xls +0 -0
- package/input/CustomProperties.xlsx +0 -0
- package/input/DataSorter.xls +0 -0
- package/input/Externlink.xls +0 -0
- package/input/Replace.xls +0 -0
- package/input/example.png +0 -0
- package/input/image.gif +0 -0
- package/output/empty.txt +0 -0
- package/package.json +39 -0
- package/src/samples.js +2645 -0
package/src/samples.js
ADDED
|
@@ -0,0 +1,2645 @@
|
|
|
1
|
+
function sampleStyle() {
|
|
2
|
+
//First method
|
|
3
|
+
const { Workbook, Color } = require("aspose.cells.node");
|
|
4
|
+
|
|
5
|
+
var excel = new Workbook();
|
|
6
|
+
var style = excel.createStyle();
|
|
7
|
+
style.getFont().setName("Times New Roman");
|
|
8
|
+
style.getFont().setColor(Color.Blue);
|
|
9
|
+
for (var i = 0; i < 100; i++) {
|
|
10
|
+
excel.getWorksheets().get(0).getCells().get(0, i).setStyle(style);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//Second method
|
|
14
|
+
var style1 = excel.getWorksheets().get(0).getCells().get("A1").getStyle();
|
|
15
|
+
style1.getFont().setName("Times New Roman");
|
|
16
|
+
style1.getFont().setColor(Color.Blue);
|
|
17
|
+
excel.getWorksheets().get(0).getCells().get("A1").setStyle(style1);
|
|
18
|
+
|
|
19
|
+
//First method is a fast and efficient way to change several cell-formatting properties on multiple cells at the same time.
|
|
20
|
+
//If you want to change a single cell's style properties, second method can be used.
|
|
21
|
+
}
|
|
22
|
+
sampleStyle();
|
|
23
|
+
|
|
24
|
+
function sampleChartTitle() {
|
|
25
|
+
const { Workbook, Color, ChartType } = require("aspose.cells.node");
|
|
26
|
+
|
|
27
|
+
var excel = new Workbook();
|
|
28
|
+
var charts = excel.getWorksheets().get(0).getCharts();
|
|
29
|
+
//Create a chart
|
|
30
|
+
var chart = charts.get(charts.add(ChartType.Column, 1, 1, 10, 10));
|
|
31
|
+
|
|
32
|
+
//Setting the title of a chart
|
|
33
|
+
chart.getTitle().setText("Title");
|
|
34
|
+
//Setting the font color of the chart title to blue
|
|
35
|
+
chart.getTitle().getFont().setColor(Color.Blue);
|
|
36
|
+
//Setting the title of category axis of the chart
|
|
37
|
+
chart.getCategoryAxis().getTitle().setText("Category");
|
|
38
|
+
//Setting the title of value axis of the chart
|
|
39
|
+
chart.getValueAxis().getTitle().setText("Value");
|
|
40
|
+
}
|
|
41
|
+
sampleChartTitle();
|
|
42
|
+
|
|
43
|
+
function sampleTablesListObject() {
|
|
44
|
+
const { Workbook, CellsHelper, TotalsCalculation } = require("aspose.cells.node");
|
|
45
|
+
|
|
46
|
+
var workbook = new Workbook();
|
|
47
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
48
|
+
for (var i = 0; i < 5; i++) {
|
|
49
|
+
cells.get(0, i).putValue(CellsHelper.columnIndexToName(i));
|
|
50
|
+
}
|
|
51
|
+
for (var row = 1; row < 10; row++) {
|
|
52
|
+
for (var column = 0; column < 5; column++) {
|
|
53
|
+
cells.get(row, column).putValue(row * column);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
var tables = workbook.getWorksheets().get(0).getListObjects();
|
|
57
|
+
var index = tables.add(0, 0, 9, 4, true);
|
|
58
|
+
var table = tables.get(0);
|
|
59
|
+
table.setShowTotals(true);
|
|
60
|
+
table.getListColumns().get(4).setTotalsCalculation(TotalsCalculation.Sum);
|
|
61
|
+
workbook.save("output/Book1.xlsx");
|
|
62
|
+
}
|
|
63
|
+
sampleTablesListObject();
|
|
64
|
+
|
|
65
|
+
function sampleDrawingFormat() {
|
|
66
|
+
const { Workbook, ChartType, Color, GradientStyleType } = require("aspose.cells.node");
|
|
67
|
+
|
|
68
|
+
var excel = new Workbook();
|
|
69
|
+
var charts = excel.getWorksheets().get(0).getCharts();
|
|
70
|
+
//Create a chart
|
|
71
|
+
var chart = charts.get(charts.add(ChartType.Column, 1, 1, 10, 10));
|
|
72
|
+
chart.getNSeries().add("A1:C5", true);
|
|
73
|
+
|
|
74
|
+
//Filling the area of the 2nd NSeries with a gradient
|
|
75
|
+
chart.getNSeries().get(1).getArea().getFillFormat().setOneColorGradient(Color.Lime, 1, GradientStyleType.Horizontal, 1);
|
|
76
|
+
}
|
|
77
|
+
sampleDrawingFormat();
|
|
78
|
+
|
|
79
|
+
function samplePropertiesCustomDocumentPropertyCollection() {
|
|
80
|
+
const { Workbook } = require("aspose.cells.node");
|
|
81
|
+
|
|
82
|
+
//Instantiate a Workbook object
|
|
83
|
+
var workbook = new Workbook("input/CustomProperties.xlsx");
|
|
84
|
+
|
|
85
|
+
//Retrieve a list of all custom document properties of the Excel file
|
|
86
|
+
var customProperties = workbook.getWorksheets().getCustomDocumentProperties();
|
|
87
|
+
}
|
|
88
|
+
samplePropertiesCustomDocumentPropertyCollection();
|
|
89
|
+
|
|
90
|
+
function samplePropertyDocumentPropertyCollection() {
|
|
91
|
+
const { Workbook } = require("aspose.cells.node");
|
|
92
|
+
|
|
93
|
+
//Instantiate a Workbook object by calling its empty constructor
|
|
94
|
+
var workbook = new Workbook("input/CustomProperties.xlsx");
|
|
95
|
+
|
|
96
|
+
//Retrieve a list of all custom document properties of the Excel file
|
|
97
|
+
var customProperties = workbook.getWorksheets().getCustomDocumentProperties();
|
|
98
|
+
|
|
99
|
+
//Accessng a custom document property by using the property index
|
|
100
|
+
var customProperty1 = customProperties.get(3);
|
|
101
|
+
|
|
102
|
+
//Accessng a custom document property by using the property name
|
|
103
|
+
var customProperty2 = customProperties.get("rox_Meta1");
|
|
104
|
+
|
|
105
|
+
console.log("Custom Properties: " + customProperties.getCount());
|
|
106
|
+
}
|
|
107
|
+
samplePropertyDocumentPropertyCollection();
|
|
108
|
+
|
|
109
|
+
function sampleDrawingPicture() {
|
|
110
|
+
const { Workbook, SaveFormat } = require("aspose.cells.node");
|
|
111
|
+
|
|
112
|
+
//Instantiating a Workbook object
|
|
113
|
+
var workbook = new Workbook();
|
|
114
|
+
//Adding a new worksheet to the Workbook object
|
|
115
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
116
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
117
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
118
|
+
//Adding a picture at the location of a cell whose row and column indices
|
|
119
|
+
//are 5 in the worksheet. It is "F6" cell
|
|
120
|
+
worksheet.getPictures().add(5, 5, "input/image.gif");
|
|
121
|
+
//Saving the Excel file
|
|
122
|
+
workbook.save("output/Book1.xls", SaveFormat.Excel97To2003);
|
|
123
|
+
}
|
|
124
|
+
sampleDrawingPicture();
|
|
125
|
+
|
|
126
|
+
function sampleHorizontalPageBreak() {
|
|
127
|
+
const { Workbook } = require("aspose.cells.node");
|
|
128
|
+
|
|
129
|
+
//Instantiating a Workbook object
|
|
130
|
+
var workbook = new Workbook();
|
|
131
|
+
|
|
132
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
133
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
134
|
+
|
|
135
|
+
//Add a page break at cell Y30
|
|
136
|
+
var Index = worksheet.getHorizontalPageBreaks().add("Y30");
|
|
137
|
+
|
|
138
|
+
//get the newly added horizontal page break
|
|
139
|
+
var hPageBreak = worksheet.getHorizontalPageBreaks().get(Index);
|
|
140
|
+
}
|
|
141
|
+
sampleHorizontalPageBreak();
|
|
142
|
+
|
|
143
|
+
function sampleChartsFloor() {
|
|
144
|
+
const { License, Workbook, ChartType, Color, GradientPresetType, GradientStyleType } = require("aspose.cells.node");
|
|
145
|
+
|
|
146
|
+
//Instantiate the License class
|
|
147
|
+
var license = new License();
|
|
148
|
+
license.setLicense("input/Aspose.Cells.lic");
|
|
149
|
+
|
|
150
|
+
//Instantiate the workbook object
|
|
151
|
+
var workbook = new Workbook();
|
|
152
|
+
//Get cells collection
|
|
153
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
154
|
+
//Put values in cells
|
|
155
|
+
cells.get("A1").putValue(1);
|
|
156
|
+
cells.get("A2").putValue(2);
|
|
157
|
+
cells.get("A3").putValue(3);
|
|
158
|
+
|
|
159
|
+
//get charts colletion
|
|
160
|
+
var charts = workbook.getWorksheets().get(0).getCharts();
|
|
161
|
+
//add a new chart
|
|
162
|
+
var index = charts.add(ChartType.Column3DStacked, 5, 0, 15, 5);
|
|
163
|
+
//get the newly added chart
|
|
164
|
+
var chart = charts.get(index);
|
|
165
|
+
//set charts nseries
|
|
166
|
+
chart.getNSeries().add("A1:A3", true);
|
|
167
|
+
//Show data labels
|
|
168
|
+
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
|
|
169
|
+
|
|
170
|
+
//Get chart's floor
|
|
171
|
+
var floor = chart.getFloor();
|
|
172
|
+
//set floor's border as red
|
|
173
|
+
floor.getBorder().setColor(new Color("red"));
|
|
174
|
+
//set fill format
|
|
175
|
+
floor.getFillFormat().setPresetColorGradient(GradientPresetType.CalmWater, GradientStyleType.DiagonalDown, 2);
|
|
176
|
+
|
|
177
|
+
//save the file
|
|
178
|
+
workbook.save("output/ChartsFloor.xls");
|
|
179
|
+
}
|
|
180
|
+
sampleChartsFloor();
|
|
181
|
+
|
|
182
|
+
function sampleDrawingArea() {
|
|
183
|
+
const { Workbook, ChartType, Color } = require("aspose.cells.node");
|
|
184
|
+
|
|
185
|
+
//Instantiating a Workbook object
|
|
186
|
+
var workbook = new Workbook();
|
|
187
|
+
//Adding a new worksheet to the Workbook object
|
|
188
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
189
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
190
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
191
|
+
//Adding a sample value to "A1" cell
|
|
192
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
193
|
+
//Adding a sample value to "A2" cell
|
|
194
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
195
|
+
//Adding a sample value to "A3" cell
|
|
196
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
197
|
+
//Adding a sample value to "B1" cell
|
|
198
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
199
|
+
//Adding a sample value to "B2" cell
|
|
200
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
201
|
+
//Adding a sample value to "B3" cell
|
|
202
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
203
|
+
//Adding a chart to the worksheet
|
|
204
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
205
|
+
//Accessing the instance of the newly added chart
|
|
206
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
207
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
208
|
+
chart.getNSeries().add("A1:B3", true);
|
|
209
|
+
//Setting the foreground color of the plot area
|
|
210
|
+
chart.getPlotArea().getArea().setForegroundColor(Color.Blue);
|
|
211
|
+
//Setting the foreground color of the chart area
|
|
212
|
+
chart.getChartArea().getArea().setForegroundColor(Color.Yellow);
|
|
213
|
+
//Setting the foreground color of the 1st NSeries area
|
|
214
|
+
chart.getNSeries().get(0).getArea().setForegroundColor(Color.Red);
|
|
215
|
+
//Setting the foreground color of the area of the 1st NSeries point
|
|
216
|
+
chart.getNSeries().get(0).getPoints().get(0).getArea().setForegroundColor(Color.Cyan);
|
|
217
|
+
//Saving the Excel file
|
|
218
|
+
workbook.save("output/DrawingArea.xls");
|
|
219
|
+
}
|
|
220
|
+
sampleDrawingArea();
|
|
221
|
+
|
|
222
|
+
function sampleDrawingAreaInverseIfNegative() {
|
|
223
|
+
const { Workbook, ChartType, Color } = require("aspose.cells.node");
|
|
224
|
+
|
|
225
|
+
//Instantiating a Workbook object
|
|
226
|
+
var workbook = new Workbook();
|
|
227
|
+
//Adding a new worksheet to the Workbook object
|
|
228
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
229
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
230
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
231
|
+
//Adding a sample value to "A1" cell
|
|
232
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
233
|
+
//Adding a sample value to "A2" cell
|
|
234
|
+
worksheet.getCells().get("A2").putValue(-100);
|
|
235
|
+
//Adding a sample value to "A3" cell
|
|
236
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
237
|
+
//Adding a chart to the worksheet
|
|
238
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
239
|
+
//Accessing the instance of the newly added chart
|
|
240
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
241
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "A3"
|
|
242
|
+
chart.getNSeries().add("A1:A3", true);
|
|
243
|
+
chart.getNSeries().get(0).getArea().setInvertIfNegative(true);
|
|
244
|
+
//Setting the foreground color of the 1st NSeries area
|
|
245
|
+
chart.getNSeries().get(0).getArea().setForegroundColor(Color.Red);
|
|
246
|
+
//Setting the background color of the 1st NSeries area.
|
|
247
|
+
//The displayed area color of second chart point will be the background color.
|
|
248
|
+
chart.getNSeries().get(0).getArea().setBackgroundColor(Color.Yellow);
|
|
249
|
+
//Saving the Excel file
|
|
250
|
+
workbook.save("output/DrawingAreaInverseIfNegative.xls");
|
|
251
|
+
}
|
|
252
|
+
sampleDrawingAreaInverseIfNegative();
|
|
253
|
+
|
|
254
|
+
function sampleExternlink() {
|
|
255
|
+
const { Workbook } = require("aspose.cells.node");
|
|
256
|
+
|
|
257
|
+
//Open a file with external links
|
|
258
|
+
var workbook = new Workbook("input/Externlink.xls");
|
|
259
|
+
|
|
260
|
+
//Get External Link
|
|
261
|
+
var externalLink = workbook.getWorksheets().getExternalLinks().get(0);
|
|
262
|
+
//Change External Link's Data Source
|
|
263
|
+
externalLink.setDataSource("input/Book1.xls");
|
|
264
|
+
}
|
|
265
|
+
sampleExternlink();
|
|
266
|
+
|
|
267
|
+
function sampleComment() {
|
|
268
|
+
const { Workbook } = require("aspose.cells.node");
|
|
269
|
+
|
|
270
|
+
var workbook = new Workbook();
|
|
271
|
+
var comments = workbook.getWorksheets().get(0).getComments();
|
|
272
|
+
|
|
273
|
+
//Add comment to cell A1
|
|
274
|
+
var commentIndex = comments.add(0, 0);
|
|
275
|
+
var comment = comments.get(commentIndex);
|
|
276
|
+
comment.setNote("First note.");
|
|
277
|
+
comment.getFont().setName("Times New Roman");
|
|
278
|
+
|
|
279
|
+
//Add comment to cell B2
|
|
280
|
+
comments.add("B2");
|
|
281
|
+
comment = comments.get("B2");
|
|
282
|
+
comment.setNote("Second note.");
|
|
283
|
+
}
|
|
284
|
+
sampleComment();
|
|
285
|
+
|
|
286
|
+
function sampleIconSet() {
|
|
287
|
+
const { Workbook, CellArea, FormatConditionType, IconSetType } = require("aspose.cells.node");
|
|
288
|
+
|
|
289
|
+
//Instantiating a Workbook object
|
|
290
|
+
var workbook = new Workbook();
|
|
291
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
292
|
+
|
|
293
|
+
//Adds an empty conditional formatting
|
|
294
|
+
var index = sheet.getConditionalFormattings().add();
|
|
295
|
+
var fcs = sheet.getConditionalFormattings().get(index);
|
|
296
|
+
//Sets the conditional format range.
|
|
297
|
+
var ca = new CellArea();
|
|
298
|
+
ca.startRow = 0;
|
|
299
|
+
ca.endRow = 2;
|
|
300
|
+
ca.startColumn = 0;
|
|
301
|
+
ca.endColumn = 0;
|
|
302
|
+
fcs.addArea(ca);
|
|
303
|
+
|
|
304
|
+
//Adds condition.
|
|
305
|
+
var idx = fcs.addCondition(FormatConditionType.IconSet);
|
|
306
|
+
|
|
307
|
+
fcs.addArea(ca);
|
|
308
|
+
var cond = fcs.get(idx);
|
|
309
|
+
//Get Icon Set
|
|
310
|
+
var iconSet = cond.getIconSet();
|
|
311
|
+
//Set Icon Type
|
|
312
|
+
iconSet.setType(IconSetType.Arrows3);
|
|
313
|
+
|
|
314
|
+
//Put Cell Values
|
|
315
|
+
var cell1 = sheet.getCells().get("A1");
|
|
316
|
+
cell1.putValue(10);
|
|
317
|
+
var cell2 = sheet.getCells().get("A2");
|
|
318
|
+
cell2.putValue(120);
|
|
319
|
+
var cell3 = sheet.getCells().get("A3");
|
|
320
|
+
cell3.putValue(260);
|
|
321
|
+
|
|
322
|
+
//Saving the Excel file
|
|
323
|
+
workbook.save("output/IconSet.xlsx");
|
|
324
|
+
}
|
|
325
|
+
sampleIconSet();
|
|
326
|
+
|
|
327
|
+
function samplePageSetup() {
|
|
328
|
+
const { Workbook } = require("aspose.cells.node");
|
|
329
|
+
|
|
330
|
+
var workbook = new Workbook();
|
|
331
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
332
|
+
sheet.getPageSetup().setPrintArea("D1:K13");
|
|
333
|
+
sheet.getPageSetup().setPrintTitleRows("$5:$7");
|
|
334
|
+
sheet.getPageSetup().setPrintTitleColumns("$A:$B");
|
|
335
|
+
}
|
|
336
|
+
samplePageSetup();
|
|
337
|
+
|
|
338
|
+
function sampleDrawingOleObject() {
|
|
339
|
+
const fs = require("fs");
|
|
340
|
+
const { Workbook } = require("aspose.cells.node");
|
|
341
|
+
|
|
342
|
+
//Instantiate a new Workbook.
|
|
343
|
+
var workbook = new Workbook();
|
|
344
|
+
//Get the first worksheet.
|
|
345
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
346
|
+
|
|
347
|
+
//Obtain the picture into the array of bytes from a stream.
|
|
348
|
+
var imgBuf = new Uint8Array(fs.readFileSync("input/example.png"));
|
|
349
|
+
//Add an Ole object into the worksheet with the bytes
|
|
350
|
+
sheet.getOleObjects().add(14, 3, 200, 220, imgBuf);
|
|
351
|
+
//Set embedded ole object data from a stream.
|
|
352
|
+
var fileBuf = new Uint8Array(fs.readFileSync("input/Book1.xls"));
|
|
353
|
+
sheet.getOleObjects().get(0).setObjectData(fileBuf);
|
|
354
|
+
//Save the excel file
|
|
355
|
+
workbook.save("output/DrawingOleObject.xls");
|
|
356
|
+
}
|
|
357
|
+
sampleDrawingOleObject();
|
|
358
|
+
|
|
359
|
+
function sampleTextEffectFormat() {
|
|
360
|
+
const { Workbook, MsoPresetTextEffect } = require("aspose.cells.node");
|
|
361
|
+
|
|
362
|
+
//Instantiating a Workbook object
|
|
363
|
+
var workbook = new Workbook();
|
|
364
|
+
var shapes = workbook.getWorksheets().get(0).getShapes();
|
|
365
|
+
shapes.addTextEffect(MsoPresetTextEffect.TextEffect1, "Aspose", "Arial", 30, false, false, 0, 0, 0, 0, 100, 200);
|
|
366
|
+
var textEffectFormat = shapes.get(0).getTextEffect();
|
|
367
|
+
textEffectFormat.setTextEffect(MsoPresetTextEffect.TextEffect10);
|
|
368
|
+
workbook.save("output/TextEffectFormat.xls");
|
|
369
|
+
}
|
|
370
|
+
sampleTextEffectFormat();
|
|
371
|
+
|
|
372
|
+
function sampleChartsErrorBar() {
|
|
373
|
+
const { Workbook, ChartType, ErrorBarDisplayType, ErrorBarType } = require("aspose.cells.node");
|
|
374
|
+
|
|
375
|
+
var workbook = new Workbook();
|
|
376
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
377
|
+
cells.get("a1").putValue(2);
|
|
378
|
+
cells.get("a2").putValue(5);
|
|
379
|
+
cells.get("a3").putValue(3);
|
|
380
|
+
cells.get("a4").putValue(6);
|
|
381
|
+
cells.get("b1").putValue(4);
|
|
382
|
+
cells.get("b2").putValue(3);
|
|
383
|
+
cells.get("b3").putValue(6);
|
|
384
|
+
cells.get("b4").putValue(7);
|
|
385
|
+
|
|
386
|
+
cells.get("C1").putValue("Q1");
|
|
387
|
+
cells.get("C2").putValue("Q2");
|
|
388
|
+
cells.get("C3").putValue("Y1");
|
|
389
|
+
cells.get("C4").putValue("Y2");
|
|
390
|
+
|
|
391
|
+
var chartIndex = workbook.getWorksheets().get(0).getCharts().add(ChartType.Column, 11, 0, 27, 10);
|
|
392
|
+
var chart = workbook.getWorksheets().get(0).getCharts().get(chartIndex);
|
|
393
|
+
chart.getNSeries().add("A1:B4", true);
|
|
394
|
+
chart.getNSeries().setCategoryData("C1:C4");
|
|
395
|
+
|
|
396
|
+
for (var i = 0; i < chart.getNSeries().getCount(); i++) {
|
|
397
|
+
var aseries = chart.getNSeries().get(i);
|
|
398
|
+
aseries.getXErrorBar().setDisplayType(ErrorBarDisplayType.Minus);
|
|
399
|
+
aseries.getXErrorBar().setType(ErrorBarType.FixedValue);
|
|
400
|
+
aseries.getXErrorBar().setAmount(5);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
sampleChartsErrorBar();
|
|
404
|
+
|
|
405
|
+
function sampleDrawingLine() {
|
|
406
|
+
const { Workbook, ChartType, LineType, ChartMarkerType, WeightType } = require("aspose.cells.node");
|
|
407
|
+
|
|
408
|
+
var workbook = new Workbook();
|
|
409
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
410
|
+
cells.get("a1").putValue(2);
|
|
411
|
+
cells.get("a2").putValue(5);
|
|
412
|
+
cells.get("a3").putValue(3);
|
|
413
|
+
cells.get("a4").putValue(6);
|
|
414
|
+
cells.get("b1").putValue(4);
|
|
415
|
+
cells.get("b2").putValue(3);
|
|
416
|
+
cells.get("b3").putValue(6);
|
|
417
|
+
cells.get("b4").putValue(7);
|
|
418
|
+
var chartIndex = workbook.getWorksheets().get(0).getCharts().add(ChartType.Column, 11, 0, 27, 10);
|
|
419
|
+
var chart = workbook.getWorksheets().get(0).getCharts().get(chartIndex);
|
|
420
|
+
chart.getNSeries().add("A1:B4", true);
|
|
421
|
+
//Applying a dotted line style on the lines of an NSeries
|
|
422
|
+
chart.getNSeries().get(0).getBorder().setStyle(LineType.Dot);
|
|
423
|
+
//Applying a triangular marker style on the data markers of an NSeries
|
|
424
|
+
chart.getNSeries().get(0).getMarker().setMarkerStyle(ChartMarkerType.Triangle);
|
|
425
|
+
//Setting the weight of all lines in an NSeries to medium
|
|
426
|
+
chart.getNSeries().get(0).getBorder().setWeight(WeightType.MediumLine);
|
|
427
|
+
}
|
|
428
|
+
sampleDrawingLine();
|
|
429
|
+
|
|
430
|
+
function sampleChartsErrorBarType() {
|
|
431
|
+
const { Workbook, ChartType, ErrorBarType } = require("aspose.cells.node");
|
|
432
|
+
|
|
433
|
+
var workbook = new Workbook();
|
|
434
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
435
|
+
cells.get("a1").putValue(2);
|
|
436
|
+
cells.get("a2").putValue(5);
|
|
437
|
+
cells.get("a3").putValue(3);
|
|
438
|
+
cells.get("a4").putValue(6);
|
|
439
|
+
cells.get("b1").putValue(4);
|
|
440
|
+
cells.get("b2").putValue(3);
|
|
441
|
+
cells.get("b3").putValue(6);
|
|
442
|
+
cells.get("b4").putValue(7);
|
|
443
|
+
|
|
444
|
+
cells.get("C1").putValue("Q1");
|
|
445
|
+
cells.get("C2").putValue("Q2");
|
|
446
|
+
cells.get("C3").putValue("Y1");
|
|
447
|
+
cells.get("C4").putValue("Y2");
|
|
448
|
+
|
|
449
|
+
var chartIndex = workbook.getWorksheets().get(0).getCharts().add(ChartType.Column, 11, 0, 27, 10);
|
|
450
|
+
var chart = workbook.getWorksheets().get(0).getCharts().get(chartIndex);
|
|
451
|
+
chart.getNSeries().add("A1:B4", true);
|
|
452
|
+
chart.getNSeries().setCategoryData("C1:C4");
|
|
453
|
+
|
|
454
|
+
for (var i = 0; i < chart.getNSeries().getCount(); i++) {
|
|
455
|
+
var aseries = chart.getNSeries().get(i);
|
|
456
|
+
//Sets custom error bar type
|
|
457
|
+
aseries.getXErrorBar().setType(ErrorBarType.Custom);
|
|
458
|
+
aseries.getXErrorBar().setPlusValue("=Sheet1!A1");
|
|
459
|
+
aseries.getXErrorBar().setMinusValue("=Sheet1!A2");
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
sampleChartsErrorBarType();
|
|
463
|
+
|
|
464
|
+
function sampleDrawingButton() {
|
|
465
|
+
const { Workbook, MsoDrawingType, Color, PlacementType } = require("aspose.cells.node");
|
|
466
|
+
|
|
467
|
+
//Create a new Workbook.
|
|
468
|
+
var workbook = new Workbook();
|
|
469
|
+
//Get the first worksheet in the workbook.
|
|
470
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
471
|
+
|
|
472
|
+
//Add a new button to the worksheet.
|
|
473
|
+
var button = sheet.getShapes().addShape(MsoDrawingType.Button, 2, 0, 2, 0, 28, 80);
|
|
474
|
+
//Set the caption of the button.
|
|
475
|
+
button.setText("Aspose");
|
|
476
|
+
//Set the Placement Type, the way the
|
|
477
|
+
//button is attached to the cells.
|
|
478
|
+
button.setPlacement(PlacementType.FreeFloating);
|
|
479
|
+
//Set the font name.
|
|
480
|
+
button.getFont().setName("Tahoma");
|
|
481
|
+
//Set the caption string bold.
|
|
482
|
+
button.getFont().setIsBold(true);
|
|
483
|
+
//Set the color to blue.
|
|
484
|
+
button.getFont().setColor(Color.Blue);
|
|
485
|
+
//Set the hyperlink for the button.
|
|
486
|
+
button.addHyperlink("http://www.aspose.com/");
|
|
487
|
+
|
|
488
|
+
//Saves the file.
|
|
489
|
+
workbook.save("output/DrawingButton.xls");
|
|
490
|
+
}
|
|
491
|
+
sampleDrawingButton();
|
|
492
|
+
|
|
493
|
+
function sampleValidation() {
|
|
494
|
+
const { Workbook, ValidationType, CellArea } = require("aspose.cells.node");
|
|
495
|
+
|
|
496
|
+
var workbook = new Workbook();
|
|
497
|
+
var validations = workbook.getWorksheets().get(0).getValidations();
|
|
498
|
+
var area = CellArea.createCellArea(0, 0, 1, 1);
|
|
499
|
+
var validation = validations.get(validations.add(area));
|
|
500
|
+
validation.setType(ValidationType.List);
|
|
501
|
+
validation.setFormula1("a,b,c,d");
|
|
502
|
+
}
|
|
503
|
+
sampleValidation();
|
|
504
|
+
|
|
505
|
+
function sampleChartsSeriesCollection() {
|
|
506
|
+
const { Workbook, ChartType } = require("aspose.cells.node");
|
|
507
|
+
|
|
508
|
+
//Instantiating a Workbook object
|
|
509
|
+
var workbook = new Workbook();
|
|
510
|
+
//Adding a new worksheet to the Excel object
|
|
511
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
512
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
513
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
514
|
+
//Adding a sample value to "A1" cell
|
|
515
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
516
|
+
//Adding a sample value to "A2" cell
|
|
517
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
518
|
+
//Adding a sample value to "A3" cell
|
|
519
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
520
|
+
//Adding a sample value to "A4" cell
|
|
521
|
+
worksheet.getCells().get("A4").putValue(200);
|
|
522
|
+
//Adding a sample value to "B1" cell
|
|
523
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
524
|
+
//Adding a sample value to "B2" cell
|
|
525
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
526
|
+
//Adding a sample value to "B3" cell
|
|
527
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
528
|
+
//Adding a sample value to "B4" cell
|
|
529
|
+
worksheet.getCells().get("B4").putValue(40);
|
|
530
|
+
//Adding a sample value to "C1" cell as category data
|
|
531
|
+
worksheet.getCells().get("C1").putValue("Q1");
|
|
532
|
+
//Adding a sample value to "C2" cell as category data
|
|
533
|
+
worksheet.getCells().get("C2").putValue("Q2");
|
|
534
|
+
//Adding a sample value to "C3" cell as category data
|
|
535
|
+
worksheet.getCells().get("C3").putValue("Y1");
|
|
536
|
+
//Adding a sample value to "C4" cell as category data
|
|
537
|
+
worksheet.getCells().get("C4").putValue("Y2");
|
|
538
|
+
//Adding a chart to the worksheet
|
|
539
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
540
|
+
//Accessing the instance of the newly added chart
|
|
541
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
542
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
|
|
543
|
+
chart.getNSeries().add("A1:B4", true);
|
|
544
|
+
//Setting the data source for the category data of NSeries
|
|
545
|
+
chart.getNSeries().setCategoryData("C1:C4");
|
|
546
|
+
//Saving the Excel file
|
|
547
|
+
workbook.save("output/ChartsSeriesCollection.xls");
|
|
548
|
+
}
|
|
549
|
+
sampleChartsSeriesCollection();
|
|
550
|
+
|
|
551
|
+
function sampleHyperlinkCollection() {
|
|
552
|
+
const { Workbook } = require("aspose.cells.node");
|
|
553
|
+
|
|
554
|
+
//Instantiating a Workbook object
|
|
555
|
+
var workbook = new Workbook();
|
|
556
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
557
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
558
|
+
|
|
559
|
+
//Get Hyperlinks Collection
|
|
560
|
+
var hyperlinks = worksheet.getHyperlinks();
|
|
561
|
+
//Adding a hyperlink to a URL at "A1" cell
|
|
562
|
+
hyperlinks.add("A1", 1, 1, "http://www.aspose.com");
|
|
563
|
+
|
|
564
|
+
//Saving the Excel file
|
|
565
|
+
workbook.save("output/HyperlinkCollection.xls");
|
|
566
|
+
}
|
|
567
|
+
sampleHyperlinkCollection();
|
|
568
|
+
|
|
569
|
+
function sampleHyperlinkCollectionAddIntIntIntIntString() {
|
|
570
|
+
const { Workbook } = require("aspose.cells.node");
|
|
571
|
+
|
|
572
|
+
var excel = new Workbook();
|
|
573
|
+
var worksheet = excel.getWorksheets().get(0);
|
|
574
|
+
worksheet.getHyperlinks().add("A4", 1, 1, "http://www.aspose.com");
|
|
575
|
+
worksheet.getHyperlinks().add("A5", 1, 1, "c:\\book1.xls");
|
|
576
|
+
}
|
|
577
|
+
sampleHyperlinkCollectionAddIntIntIntIntString();
|
|
578
|
+
|
|
579
|
+
function sampleDataSorter() {
|
|
580
|
+
const { Workbook, CellArea, SortOrder } = require("aspose.cells.node");
|
|
581
|
+
|
|
582
|
+
//Instantiate a new Workbook object.
|
|
583
|
+
var workbook = new Workbook("input/DataSorter.xls");
|
|
584
|
+
//Get the workbook datasorter object.
|
|
585
|
+
var sorter = workbook.getDataSorter();
|
|
586
|
+
//Set the first order for datasorter object.
|
|
587
|
+
sorter.setOrder1(SortOrder.Descending);
|
|
588
|
+
//Define the first key.
|
|
589
|
+
sorter.setKey1(0);
|
|
590
|
+
//Create a cells area (range).
|
|
591
|
+
var ca = new CellArea();
|
|
592
|
+
//Specify the start row index.
|
|
593
|
+
ca.startRow = 0;
|
|
594
|
+
//Specify the start column index.
|
|
595
|
+
ca.startColumn = 0;
|
|
596
|
+
//Specify the last row index.
|
|
597
|
+
ca.endRow = 12;
|
|
598
|
+
//Specify the last column index.
|
|
599
|
+
ca.endColumn = 1;
|
|
600
|
+
//Sort data in the specified data range (A1:B14)
|
|
601
|
+
sorter.sort(workbook.getWorksheets().get(0).getCells(), ca);
|
|
602
|
+
//Save the excel file.
|
|
603
|
+
workbook.save("output/DataSorter.xls");
|
|
604
|
+
}
|
|
605
|
+
sampleDataSorter();
|
|
606
|
+
|
|
607
|
+
function sampleColumn() {
|
|
608
|
+
const { Workbook, Color, BackgroundType, StyleFlag } = require("aspose.cells.node");
|
|
609
|
+
|
|
610
|
+
//Instantiating a Workbook object
|
|
611
|
+
var workbook = new Workbook();
|
|
612
|
+
//Obtaining the reference of the first worksheet
|
|
613
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
614
|
+
|
|
615
|
+
//Add new Style to Workbook
|
|
616
|
+
var style = workbook.createStyle();
|
|
617
|
+
//Setting the background color to Blue
|
|
618
|
+
style.setBackgroundColor(Color.Blue);
|
|
619
|
+
//Setting the foreground color to Red
|
|
620
|
+
style.setForegroundColor(Color.Red);
|
|
621
|
+
//setting Background Pattern
|
|
622
|
+
style.setPattern(BackgroundType.DiagonalStripe);
|
|
623
|
+
//New Style Flag
|
|
624
|
+
var styleFlag = new StyleFlag();
|
|
625
|
+
//Set All Styles
|
|
626
|
+
styleFlag.setAll(true);
|
|
627
|
+
|
|
628
|
+
//Get first Column
|
|
629
|
+
var column = worksheet.getCells().getColumns().get(0);
|
|
630
|
+
//Apply Style to first Column
|
|
631
|
+
column.applyStyle(style, styleFlag);
|
|
632
|
+
|
|
633
|
+
//Saving the Excel file
|
|
634
|
+
workbook.save("output/Column.xls");
|
|
635
|
+
}
|
|
636
|
+
sampleColumn();
|
|
637
|
+
|
|
638
|
+
function sampleCellArea() {
|
|
639
|
+
const { CellArea } = require("aspose.cells.node");
|
|
640
|
+
|
|
641
|
+
//Create Cell Area
|
|
642
|
+
var ca = new CellArea();
|
|
643
|
+
ca.startRow = 0;
|
|
644
|
+
ca.endRow = 0;
|
|
645
|
+
ca.startColumn = 0;
|
|
646
|
+
ca.endColumn = 0;
|
|
647
|
+
}
|
|
648
|
+
sampleCellArea();
|
|
649
|
+
|
|
650
|
+
function sampleBorder() {
|
|
651
|
+
const { Workbook, BorderType, CellBorderType, Color } = require("aspose.cells.node");
|
|
652
|
+
|
|
653
|
+
var workbook = new Workbook();
|
|
654
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
655
|
+
var cell = worksheet.getCells().get(0, 0);
|
|
656
|
+
var style = workbook.createStyle();
|
|
657
|
+
//Set top border style and color
|
|
658
|
+
var border = style.getBorders().get(BorderType.TopBorder);
|
|
659
|
+
border.setLineStyle(CellBorderType.Medium);
|
|
660
|
+
border.setColor(Color.Red);
|
|
661
|
+
cell.setStyle(style);
|
|
662
|
+
}
|
|
663
|
+
sampleBorder();
|
|
664
|
+
|
|
665
|
+
function sampleDataBar() {
|
|
666
|
+
const { Workbook, CellArea, Color, FormatConditionType, FormatConditionValueType } = require("aspose.cells.node");
|
|
667
|
+
|
|
668
|
+
//Instantiating a Workbook object
|
|
669
|
+
var workbook = new Workbook();
|
|
670
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
671
|
+
|
|
672
|
+
//Adds an empty conditional formatting
|
|
673
|
+
var index = sheet.getConditionalFormattings().add();
|
|
674
|
+
var fcs = sheet.getConditionalFormattings().get(index);
|
|
675
|
+
|
|
676
|
+
//Sets the conditional format range.
|
|
677
|
+
var ca = new CellArea();
|
|
678
|
+
ca.startRow = 0;
|
|
679
|
+
ca.endRow = 2;
|
|
680
|
+
ca.startColumn = 0;
|
|
681
|
+
ca.endColumn = 0;
|
|
682
|
+
fcs.addArea(ca);
|
|
683
|
+
|
|
684
|
+
//Adds condition.
|
|
685
|
+
var idx = fcs.addCondition(FormatConditionType.DataBar);
|
|
686
|
+
fcs.addArea(ca);
|
|
687
|
+
var cond = fcs.get(idx);
|
|
688
|
+
|
|
689
|
+
//Get Databar
|
|
690
|
+
var dataBar = cond.getDataBar();
|
|
691
|
+
var orange = Color.Orange;
|
|
692
|
+
dataBar.setColor(orange);
|
|
693
|
+
|
|
694
|
+
//Set Databar properties
|
|
695
|
+
dataBar.getMinCfvo().setType(FormatConditionValueType.Percentile);
|
|
696
|
+
dataBar.getMinCfvo().setValue(30);
|
|
697
|
+
dataBar.setShowValue(false);
|
|
698
|
+
|
|
699
|
+
//Put Cell Values
|
|
700
|
+
var cell1 = sheet.getCells().get("A1");
|
|
701
|
+
cell1.putValue(10);
|
|
702
|
+
var cell2 = sheet.getCells().get("A2");
|
|
703
|
+
cell2.putValue(120);
|
|
704
|
+
var cell3 = sheet.getCells().get("A3");
|
|
705
|
+
cell3.putValue(260);
|
|
706
|
+
|
|
707
|
+
//Saving the Excel file
|
|
708
|
+
workbook.save("output/DataBar.xlsx");
|
|
709
|
+
}
|
|
710
|
+
sampleDataBar();
|
|
711
|
+
|
|
712
|
+
function sampleWorkbook() {
|
|
713
|
+
const { Workbook, XlsSaveOptions } = require("aspose.cells.node");
|
|
714
|
+
|
|
715
|
+
//Open a xls file
|
|
716
|
+
var workbook = new Workbook("input/Book1.xls");
|
|
717
|
+
|
|
718
|
+
//Set scroll bars
|
|
719
|
+
workbook.getSettings().setIsHScrollBarVisible(false);
|
|
720
|
+
workbook.getSettings().setIsVScrollBarVisible(false);
|
|
721
|
+
|
|
722
|
+
//Replace the placeholder string with new values
|
|
723
|
+
workbook.replace("OldInt", 100);
|
|
724
|
+
|
|
725
|
+
var newString = "Hello world";
|
|
726
|
+
workbook.replace("OldString", newString);
|
|
727
|
+
var saveOptions = new XlsSaveOptions();
|
|
728
|
+
workbook.save("output/result.xls", saveOptions);
|
|
729
|
+
}
|
|
730
|
+
sampleWorkbook();
|
|
731
|
+
|
|
732
|
+
function sampleWorkbookCtor() {
|
|
733
|
+
const { Workbook } = require("aspose.cells.node");
|
|
734
|
+
|
|
735
|
+
var workbook = new Workbook();
|
|
736
|
+
}
|
|
737
|
+
sampleWorkbookCtor();
|
|
738
|
+
|
|
739
|
+
function sampleWorkbookCtorFileFormatType() {
|
|
740
|
+
const { Workbook, FileFormatType } = require("aspose.cells.node");
|
|
741
|
+
|
|
742
|
+
var workbook = new Workbook(FileFormatType.Xlsx);
|
|
743
|
+
}
|
|
744
|
+
sampleWorkbookCtorFileFormatType();
|
|
745
|
+
|
|
746
|
+
function sampleWorkbookSaveFileFormatType() {
|
|
747
|
+
const { Workbook, SaveFormat } = require("aspose.cells.node");
|
|
748
|
+
|
|
749
|
+
var workbook = new Workbook();
|
|
750
|
+
var sheets = workbook.getWorksheets();
|
|
751
|
+
var cells = sheets.get(0).getCells();
|
|
752
|
+
cells.get("A1").putValue("Hello world!");
|
|
753
|
+
workbook.save("output/WorkbookSaveFileFormatType.xls", SaveFormat.Excel97To2003);
|
|
754
|
+
}
|
|
755
|
+
sampleWorkbookSaveFileFormatType();
|
|
756
|
+
|
|
757
|
+
function sampleWorkbookReplaceStringString() {
|
|
758
|
+
const { Workbook } = require("aspose.cells.node");
|
|
759
|
+
|
|
760
|
+
var workbook = new Workbook();
|
|
761
|
+
workbook.replace("AnOldValue", "NewValue");
|
|
762
|
+
}
|
|
763
|
+
sampleWorkbookReplaceStringString();
|
|
764
|
+
|
|
765
|
+
function sampleWorkbookReplaceStringInt() {
|
|
766
|
+
const { Workbook } = require("aspose.cells.node");
|
|
767
|
+
|
|
768
|
+
var workbook = new Workbook();
|
|
769
|
+
var newValue = 100;
|
|
770
|
+
workbook.replace("AnOldValue", newValue);
|
|
771
|
+
}
|
|
772
|
+
sampleWorkbookReplaceStringInt();
|
|
773
|
+
|
|
774
|
+
function sampleWorkbookReplaceStringDouble() {
|
|
775
|
+
const { Workbook } = require("aspose.cells.node");
|
|
776
|
+
|
|
777
|
+
var workbook = new Workbook();
|
|
778
|
+
var newValue = 100.0;
|
|
779
|
+
workbook.replace("AnOldValue", newValue);
|
|
780
|
+
}
|
|
781
|
+
sampleWorkbookReplaceStringDouble();
|
|
782
|
+
|
|
783
|
+
function sampleWorkbookReplaceStringStringArrayBool() {
|
|
784
|
+
const { Workbook } = require("aspose.cells.node");
|
|
785
|
+
|
|
786
|
+
var workbook = new Workbook("input/Replace.xls");
|
|
787
|
+
var newValues = ["Tom", "Alice", "Jerry"];
|
|
788
|
+
workbook.replace("AnOldValue", newValues, true);
|
|
789
|
+
|
|
790
|
+
workbook.save("output/ReplaceResult1.xls");
|
|
791
|
+
}
|
|
792
|
+
sampleWorkbookReplaceStringStringArrayBool();
|
|
793
|
+
|
|
794
|
+
function sampleWorkbookReplaceStringIntArrayBool() {
|
|
795
|
+
const { Workbook } = require("aspose.cells.node");
|
|
796
|
+
|
|
797
|
+
var workbook = new Workbook("input/Replace.xls");
|
|
798
|
+
var newValues = [1, 2, 3];
|
|
799
|
+
workbook.replace("AnOldValue", newValues, true);
|
|
800
|
+
|
|
801
|
+
workbook.save("output/ReplaceResult2.xls");
|
|
802
|
+
}
|
|
803
|
+
sampleWorkbookReplaceStringIntArrayBool();
|
|
804
|
+
|
|
805
|
+
function sampleWorkbookReplaceStringDoubleArrayBool() {
|
|
806
|
+
const { Workbook } = require("aspose.cells.node");
|
|
807
|
+
|
|
808
|
+
var workbook = new Workbook("input/Replace.xls");
|
|
809
|
+
var newValues = [1.23, 2.56, 3.14159];
|
|
810
|
+
workbook.replace("AnOldValue", newValues, true);
|
|
811
|
+
|
|
812
|
+
workbook.save("output/ReplaceResult3.xls");
|
|
813
|
+
}
|
|
814
|
+
sampleWorkbookReplaceStringDoubleArrayBool();
|
|
815
|
+
|
|
816
|
+
function sampleWorkbookDefaultStyle() {
|
|
817
|
+
const { Workbook } = require("aspose.cells.node");
|
|
818
|
+
|
|
819
|
+
var workbook = new Workbook();
|
|
820
|
+
var defaultStyle = workbook.getDefaultStyle();
|
|
821
|
+
defaultStyle.getFont().setName("Tahoma");
|
|
822
|
+
workbook.setDefaultStyle(defaultStyle);
|
|
823
|
+
}
|
|
824
|
+
sampleWorkbookDefaultStyle();
|
|
825
|
+
|
|
826
|
+
function sampleWorkbookBuildInDocumentProperties() {
|
|
827
|
+
const { Workbook } = require("aspose.cells.node");
|
|
828
|
+
|
|
829
|
+
var workbook = new Workbook();
|
|
830
|
+
var doc = workbook.getBuiltInDocumentProperties().get("Author");
|
|
831
|
+
doc.setValue("John Smith");
|
|
832
|
+
}
|
|
833
|
+
sampleWorkbookBuildInDocumentProperties();
|
|
834
|
+
|
|
835
|
+
function sampleWorkbookCustomDocumentProperties() {
|
|
836
|
+
const { Workbook } = require("aspose.cells.node");
|
|
837
|
+
|
|
838
|
+
var excel = new Workbook();
|
|
839
|
+
excel.getCustomDocumentProperties().add("Checked by", "Jane");
|
|
840
|
+
}
|
|
841
|
+
sampleWorkbookCustomDocumentProperties();
|
|
842
|
+
|
|
843
|
+
function sampleThemeColor() {
|
|
844
|
+
const { Workbook, ThemeColor, ThemeColorType, BackgroundType } = require("aspose.cells.node");
|
|
845
|
+
|
|
846
|
+
//Instantiating a Workbook object
|
|
847
|
+
var workbook = new Workbook();
|
|
848
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
849
|
+
cells.get("A1").putValue("Hello World");
|
|
850
|
+
var style = cells.get("A1").getStyle();
|
|
851
|
+
//Set ThemeColorType.Text2 color type with 40% lighten as the font color.
|
|
852
|
+
style.getFont().setThemeColor(new ThemeColor(ThemeColorType.Text2, 0.4));
|
|
853
|
+
style.setPattern(BackgroundType.Solid);
|
|
854
|
+
//Set ThemeColorType.Background2 color type with 75% darken as the foreground color
|
|
855
|
+
style.setForegroundThemeColor(new ThemeColor(ThemeColorType.Background2, -0.75));
|
|
856
|
+
cells.get("A1").setStyle(style);
|
|
857
|
+
//Saving the Excel file
|
|
858
|
+
workbook.save("output/ThemeColor.xlsx");
|
|
859
|
+
}
|
|
860
|
+
sampleThemeColor();
|
|
861
|
+
|
|
862
|
+
function sampleDrawingTextBox() {
|
|
863
|
+
const { Workbook, PlacementType, Color, MsoLineStyle, MsoLineDashStyle } = require("aspose.cells.node");
|
|
864
|
+
|
|
865
|
+
//Instantiate a new Workbook.
|
|
866
|
+
var workbook = new Workbook();
|
|
867
|
+
//Get the first worksheet in the book.
|
|
868
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
869
|
+
//Add a new textbox to the collection.
|
|
870
|
+
var textboxIndex = worksheet.getTextBoxes().add(2, 1, 160, 200);
|
|
871
|
+
//Get the textbox object.
|
|
872
|
+
var textbox0 = worksheet.getTextBoxes().get(textboxIndex);
|
|
873
|
+
//Fill the text.
|
|
874
|
+
textbox0.setText("ASPOSE CELLS");
|
|
875
|
+
//Set the textbox to adjust it according to its contents.
|
|
876
|
+
textbox0.getTextBody().getTextAlignment().setAutoSize(true);
|
|
877
|
+
//Set the placement.
|
|
878
|
+
textbox0.setPlacement(PlacementType.FreeFloating);
|
|
879
|
+
//Set the font color.
|
|
880
|
+
textbox0.getFont().setColor(Color.Blue);
|
|
881
|
+
//Set the font to bold.
|
|
882
|
+
textbox0.getFont().setIsBold(true);
|
|
883
|
+
//Set the font size.
|
|
884
|
+
textbox0.getFont().setSize(14);
|
|
885
|
+
//Set font attribute to italic.
|
|
886
|
+
textbox0.getFont().setIsItalic(true);
|
|
887
|
+
//Add a hyperlink to the textbox.
|
|
888
|
+
textbox0.addHyperlink("http://www.aspose.com/");
|
|
889
|
+
//Get the filformat of the textbox.
|
|
890
|
+
var fillformat = textbox0.getFill();
|
|
891
|
+
//Set the fillcolor.
|
|
892
|
+
fillformat.getSolidFill().setColor(Color.Silver);
|
|
893
|
+
//Get the lineformat type of the textbox.
|
|
894
|
+
var lineformat = textbox0.getLine();
|
|
895
|
+
//Set the line style.
|
|
896
|
+
lineformat.setCompoundType(MsoLineStyle.ThinThick);
|
|
897
|
+
//Set the line weight.
|
|
898
|
+
lineformat.setWeight(6);
|
|
899
|
+
//Set the dash style to squaredot.
|
|
900
|
+
lineformat.setDashStyle(MsoLineDashStyle.SquareDot);
|
|
901
|
+
//Add another textbox.
|
|
902
|
+
textboxIndex = worksheet.getTextBoxes().add(15, 4, 85, 120);
|
|
903
|
+
//Get the second textbox.
|
|
904
|
+
var textbox1 = worksheet.getTextBoxes().get(textboxIndex);
|
|
905
|
+
//Input some text to it.
|
|
906
|
+
textbox1.setText("This is another simple text box");
|
|
907
|
+
//Set the placement type as the textbox will move and
|
|
908
|
+
//resize with cells.
|
|
909
|
+
textbox1.setPlacement(PlacementType.MoveAndSize);
|
|
910
|
+
//Save the excel file.
|
|
911
|
+
workbook.save("output/DrawingTextBox.xlsx");
|
|
912
|
+
}
|
|
913
|
+
sampleDrawingTextBox();
|
|
914
|
+
|
|
915
|
+
function sampleTablesTableStyle() {
|
|
916
|
+
const { Workbook, BackgroundType, Color, TableStyleElementType, CellsHelper } = require("aspose.cells.node");
|
|
917
|
+
|
|
918
|
+
var workbook = new Workbook();
|
|
919
|
+
var firstColumnStyle = workbook.createStyle();
|
|
920
|
+
firstColumnStyle.setPattern(BackgroundType.Solid);
|
|
921
|
+
firstColumnStyle.setBackgroundColor(Color.Red);
|
|
922
|
+
|
|
923
|
+
var lastColumnStyle = workbook.createStyle();
|
|
924
|
+
lastColumnStyle.getFont().setIsBold(true);
|
|
925
|
+
lastColumnStyle.setPattern(BackgroundType.Solid);
|
|
926
|
+
lastColumnStyle.setBackgroundColor(Color.Red);
|
|
927
|
+
var tableStyleName = "Custom1";
|
|
928
|
+
var tableStyles = workbook.getWorksheets().getTableStyles();
|
|
929
|
+
var index1 = tableStyles.addTableStyle(tableStyleName);
|
|
930
|
+
var tableStyle = tableStyles.get(index1);
|
|
931
|
+
var elements = tableStyle.getTableStyleElements();
|
|
932
|
+
index1 = elements.add(TableStyleElementType.FirstColumn);
|
|
933
|
+
var element = elements.get(index1);
|
|
934
|
+
element.setElementStyle(firstColumnStyle);
|
|
935
|
+
index1 = elements.add(TableStyleElementType.LastColumn);
|
|
936
|
+
element = elements.get(index1);
|
|
937
|
+
element.setElementStyle(lastColumnStyle);
|
|
938
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
939
|
+
for (var i = 0; i < 5; i++) {
|
|
940
|
+
cells.get(0, i).putValue(CellsHelper.columnIndexToName(i));
|
|
941
|
+
}
|
|
942
|
+
for (var row = 1; row < 10; row++) {
|
|
943
|
+
for (var column = 0; column < 5; column++) {
|
|
944
|
+
cells.get(row, column).putValue(row * column);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
var tables = workbook.getWorksheets().get(0).getListObjects();
|
|
948
|
+
var index = tables.add(0, 0, 9, 4, true);
|
|
949
|
+
var table = tables.get(0);
|
|
950
|
+
table.setShowTableStyleFirstColumn(true);
|
|
951
|
+
table.setShowTableStyleLastColumn(true);
|
|
952
|
+
table.setTableStyleName(tableStyleName);
|
|
953
|
+
workbook.save("output/TablesTableStyle.xlsx");
|
|
954
|
+
}
|
|
955
|
+
sampleTablesTableStyle();
|
|
956
|
+
|
|
957
|
+
function sampleLicense() {
|
|
958
|
+
const { License } = require("aspose.cells.node");
|
|
959
|
+
|
|
960
|
+
var license = new License();
|
|
961
|
+
license.setLicense("input/Aspose.Cells.lic");
|
|
962
|
+
}
|
|
963
|
+
sampleLicense();
|
|
964
|
+
|
|
965
|
+
function sampleHyperlink() {
|
|
966
|
+
const { Workbook } = require("aspose.cells.node");
|
|
967
|
+
|
|
968
|
+
//Instantiating a Workbook object
|
|
969
|
+
var workbook = new Workbook();
|
|
970
|
+
//Adding a new worksheet to the Workbook object
|
|
971
|
+
workbook.getWorksheets().add();
|
|
972
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
973
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
974
|
+
//Adding a hyperlink to a URL at "A1" cell
|
|
975
|
+
worksheet.getHyperlinks().add("A1", 1, 1, "http://www.aspose.com");
|
|
976
|
+
//Saving the Excel file
|
|
977
|
+
workbook.save("output/Hyperlink.xls");
|
|
978
|
+
}
|
|
979
|
+
sampleHyperlink();
|
|
980
|
+
|
|
981
|
+
function sampleChartsDisplayUnitLabel() {
|
|
982
|
+
const { Workbook, ChartType, DisplayUnitType } = require("aspose.cells.node");
|
|
983
|
+
|
|
984
|
+
//Instantiating a Workbook object
|
|
985
|
+
var workbook = new Workbook();
|
|
986
|
+
//Adding a new worksheet to the Excel object
|
|
987
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
988
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
989
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
990
|
+
//Adding a sample value to "A1" cell
|
|
991
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
992
|
+
//Adding a sample value to "A2" cell
|
|
993
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
994
|
+
//Adding a sample value to "A3" cell
|
|
995
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
996
|
+
//Adding a sample value to "A4" cell
|
|
997
|
+
worksheet.getCells().get("A4").putValue(200);
|
|
998
|
+
//Adding a sample value to "B1" cell
|
|
999
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
1000
|
+
//Adding a sample value to "B2" cell
|
|
1001
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
1002
|
+
//Adding a sample value to "B3" cell
|
|
1003
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1004
|
+
//Adding a sample value to "B4" cell
|
|
1005
|
+
worksheet.getCells().get("B4").putValue(40);
|
|
1006
|
+
//Adding a sample value to "C1" cell as category data
|
|
1007
|
+
worksheet.getCells().get("C1").putValue("Q1");
|
|
1008
|
+
//Adding a sample value to "C2" cell as category data
|
|
1009
|
+
worksheet.getCells().get("C2").putValue("Q2");
|
|
1010
|
+
//Adding a sample value to "C3" cell as category data
|
|
1011
|
+
worksheet.getCells().get("C3").putValue("Y1");
|
|
1012
|
+
//Adding a sample value to "C4" cell as category data
|
|
1013
|
+
worksheet.getCells().get("C4").putValue("Y2");
|
|
1014
|
+
//Adding a chart to the worksheet
|
|
1015
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
1016
|
+
//Accessing the instance of the newly added chart
|
|
1017
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1018
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
|
|
1019
|
+
chart.getNSeries().add("A1:B4", true);
|
|
1020
|
+
//Setting the data source for the category data of NSeries
|
|
1021
|
+
chart.getNSeries().setCategoryData("C1:C4");
|
|
1022
|
+
//Setting the display unit of value(Y) axis.
|
|
1023
|
+
chart.getValueAxis().setDisplayUnit(DisplayUnitType.Hundreds);
|
|
1024
|
+
var displayUnitLabel = chart.getValueAxis().getDisplayUnitLabel();
|
|
1025
|
+
//Setting the custom display unit label
|
|
1026
|
+
displayUnitLabel.setText("100");
|
|
1027
|
+
//Saving the Excel file
|
|
1028
|
+
workbook.save("output/ChartsDisplayUnitLabel.xls");
|
|
1029
|
+
}
|
|
1030
|
+
sampleChartsDisplayUnitLabel();
|
|
1031
|
+
|
|
1032
|
+
function sampleWorkbookSettingShowTabs() {
|
|
1033
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1034
|
+
|
|
1035
|
+
var workbook = new Workbook();
|
|
1036
|
+
// Hide the spreadsheet tabs.
|
|
1037
|
+
workbook.getSettings().setShowTabs(false);
|
|
1038
|
+
}
|
|
1039
|
+
sampleWorkbookSettingShowTabs();
|
|
1040
|
+
|
|
1041
|
+
function sampleWorkbookSettingIsHScrollBarVisible() {
|
|
1042
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1043
|
+
|
|
1044
|
+
var workbook = new Workbook();
|
|
1045
|
+
// Hide the horizontal scroll bar of the Excel file.
|
|
1046
|
+
workbook.getSettings().setIsHScrollBarVisible(false);
|
|
1047
|
+
}
|
|
1048
|
+
sampleWorkbookSettingIsHScrollBarVisible();
|
|
1049
|
+
|
|
1050
|
+
function sampleWorkbookSettingIsVScrollBarVisible() {
|
|
1051
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1052
|
+
|
|
1053
|
+
var workbook = new Workbook();
|
|
1054
|
+
// Hide the vertical scroll bar of the Excel file.
|
|
1055
|
+
workbook.getSettings().setIsVScrollBarVisible(false);
|
|
1056
|
+
}
|
|
1057
|
+
sampleWorkbookSettingIsVScrollBarVisible();
|
|
1058
|
+
|
|
1059
|
+
function sampleProtection() {
|
|
1060
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1061
|
+
|
|
1062
|
+
var workbook = new Workbook();
|
|
1063
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1064
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1065
|
+
//Allowing users to select locked cells of the worksheet
|
|
1066
|
+
worksheet.getProtection().setAllowSelectingLockedCell(true);
|
|
1067
|
+
//Allowing users to select unlocked cells of the worksheet
|
|
1068
|
+
worksheet.getProtection().setAllowSelectingUnlockedCell(true);
|
|
1069
|
+
}
|
|
1070
|
+
sampleProtection();
|
|
1071
|
+
|
|
1072
|
+
function sampleDrawingListBox() {
|
|
1073
|
+
const { Workbook, PlacementType, SelectionType } = require("aspose.cells.node");
|
|
1074
|
+
|
|
1075
|
+
//Create a new Workbook.
|
|
1076
|
+
var workbook = new Workbook();
|
|
1077
|
+
//Get the first worksheet.
|
|
1078
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
1079
|
+
//Get the worksheet cells collection.
|
|
1080
|
+
var cells = sheet.getCells();
|
|
1081
|
+
|
|
1082
|
+
//Input a value.
|
|
1083
|
+
cells.get("B3").putValue("Choose Dept:");
|
|
1084
|
+
//Set it bold.
|
|
1085
|
+
cells.get("B3").getStyle().getFont().setIsBold(true);
|
|
1086
|
+
//Input some values that denote the input range
|
|
1087
|
+
//for the list box.
|
|
1088
|
+
cells.get("A2").putValue("Sales");
|
|
1089
|
+
cells.get("A3").putValue("Finance");
|
|
1090
|
+
cells.get("A4").putValue("MIS");
|
|
1091
|
+
cells.get("A5").putValue("R&D");
|
|
1092
|
+
cells.get("A6").putValue("Marketing");
|
|
1093
|
+
cells.get("A7").putValue("HRA");
|
|
1094
|
+
|
|
1095
|
+
//Add a new list box.
|
|
1096
|
+
var listBox = sheet.getShapes().addListBox(2, 0, 3, 0, 122, 100);
|
|
1097
|
+
//Set the placement type.
|
|
1098
|
+
listBox.setPlacement(PlacementType.FreeFloating);
|
|
1099
|
+
//Set the linked cell.
|
|
1100
|
+
listBox.setLinkedCell("A1");
|
|
1101
|
+
//Set the input range.
|
|
1102
|
+
listBox.setInputRange("A2:A7");
|
|
1103
|
+
//Set the selection tyle.
|
|
1104
|
+
listBox.setSelectionType(SelectionType.Single);
|
|
1105
|
+
//Set the list box with 3-D shading.
|
|
1106
|
+
listBox.setShadow(true);
|
|
1107
|
+
|
|
1108
|
+
//Saves the file.
|
|
1109
|
+
workbook.save("output/DrawingListBox.xls");
|
|
1110
|
+
}
|
|
1111
|
+
sampleDrawingListBox();
|
|
1112
|
+
|
|
1113
|
+
function sampleChartsLegend() {
|
|
1114
|
+
const { Workbook, ChartType, LegendPositionType } = require("aspose.cells.node");
|
|
1115
|
+
|
|
1116
|
+
//Set Legend's width and height
|
|
1117
|
+
var workbook = new Workbook();
|
|
1118
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1119
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1120
|
+
var charts = worksheet.getCharts();
|
|
1121
|
+
//Create a chart
|
|
1122
|
+
var chart = charts.get(charts.add(ChartType.Column, 1, 1, 10, 10));
|
|
1123
|
+
var legend = chart.getLegend();
|
|
1124
|
+
|
|
1125
|
+
//Legend is at right side of chart by default.
|
|
1126
|
+
//If the legend is at left or right side of the chart, setting Legend.X property will not take effect.
|
|
1127
|
+
//If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect.
|
|
1128
|
+
legend.setY(1500);
|
|
1129
|
+
legend.setWidth(50);
|
|
1130
|
+
legend.setHeight(50);
|
|
1131
|
+
//Set legend's position
|
|
1132
|
+
legend.setPosition(LegendPositionType.Left);
|
|
1133
|
+
}
|
|
1134
|
+
sampleChartsLegend();
|
|
1135
|
+
|
|
1136
|
+
function sampleChartsChartPoint() {
|
|
1137
|
+
const { Workbook, ChartType, Color } = require("aspose.cells.node");
|
|
1138
|
+
|
|
1139
|
+
//Instantiating a Workbook object
|
|
1140
|
+
var workbook = new Workbook();
|
|
1141
|
+
//Obtaining the reference of the first worksheet
|
|
1142
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
1143
|
+
|
|
1144
|
+
//Adding a sample value to "A1" cell
|
|
1145
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1146
|
+
//Adding a sample value to "A2" cell
|
|
1147
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1148
|
+
//Adding a sample value to "A3" cell
|
|
1149
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1150
|
+
//Adding a sample value to "B1" cell
|
|
1151
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
1152
|
+
//Adding a sample value to "B2" cell
|
|
1153
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
1154
|
+
//Adding a sample value to "B3" cell
|
|
1155
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1156
|
+
|
|
1157
|
+
//Adding a chart to the worksheet
|
|
1158
|
+
var chartIndex = worksheet.getCharts().add(ChartType.PieExploded, 5, 0, 25, 10);
|
|
1159
|
+
//Accessing the instance of the newly added chart
|
|
1160
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1161
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
1162
|
+
chart.getNSeries().add("A1:B3", true);
|
|
1163
|
+
//Show Data Labels
|
|
1164
|
+
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
|
|
1165
|
+
for (var i = 0; i < chart.getNSeries().get(0).getPoints().getCount(); i++) {
|
|
1166
|
+
//Get Data Point
|
|
1167
|
+
var point = chart.getNSeries().get(0).getPoints().get(i);
|
|
1168
|
+
//Set Pir Explosion
|
|
1169
|
+
point.setExplosion(15);
|
|
1170
|
+
//Set Border Color
|
|
1171
|
+
point.getBorder().setColor(Color.Red);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
//Saving the Excel file
|
|
1175
|
+
workbook.save("output/ChartsChartPoint.xls");
|
|
1176
|
+
}
|
|
1177
|
+
sampleChartsChartPoint();
|
|
1178
|
+
|
|
1179
|
+
function sampleDrawingArcShape() {
|
|
1180
|
+
const { Workbook, FillType, Color, PlacementType, MsoLineStyle, MsoLineDashStyle } = require("aspose.cells.node");
|
|
1181
|
+
|
|
1182
|
+
//Instantiate a new Workbook.
|
|
1183
|
+
var excelbook = new Workbook();
|
|
1184
|
+
//Add an arc shape.
|
|
1185
|
+
var arc1 = excelbook.getWorksheets().get(0).getShapes().addArc(2, 0, 2, 0, 130, 130);
|
|
1186
|
+
//Set the placement of the arc.
|
|
1187
|
+
arc1.setPlacement(PlacementType.FreeFloating);
|
|
1188
|
+
//Set the fill format.
|
|
1189
|
+
arc1.getFill().setFillType(FillType.Solid)
|
|
1190
|
+
arc1.getFill().getSolidFill().setColor(Color.Blue);
|
|
1191
|
+
//Set the line style.
|
|
1192
|
+
arc1.getLine().setCompoundType(MsoLineStyle.Single);
|
|
1193
|
+
//Set the line weight.
|
|
1194
|
+
arc1.getLine().setWeight(2);
|
|
1195
|
+
//Set the color of the arc line.
|
|
1196
|
+
arc1.getLine().setFillType(FillType.Solid)
|
|
1197
|
+
arc1.getLine().getSolidFill().setColor(Color.Red);
|
|
1198
|
+
//Set the dash style of the arc.
|
|
1199
|
+
arc1.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
1200
|
+
//Add another arc shape.
|
|
1201
|
+
var arc2 = excelbook.getWorksheets().get(0).getShapes().addArc(9, 0, 2, 0, 130, 130);
|
|
1202
|
+
//Set the placement of the arc.
|
|
1203
|
+
arc2.setPlacement(PlacementType.FreeFloating);
|
|
1204
|
+
//Set the line style.
|
|
1205
|
+
arc2.getLine().setCompoundType(MsoLineStyle.Single);
|
|
1206
|
+
//Set the line weight.
|
|
1207
|
+
arc2.getLine().setWeight(1);
|
|
1208
|
+
//Set the color of the arc line.
|
|
1209
|
+
arc2.getLine().setFillType(FillType.Solid);
|
|
1210
|
+
arc2.getLine().getSolidFill().setColor(Color.Blue);
|
|
1211
|
+
//Set the dash style of the arc.
|
|
1212
|
+
arc2.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
1213
|
+
//Save the excel file.
|
|
1214
|
+
excelbook.save("output/DrawingArcShape.xls");
|
|
1215
|
+
}
|
|
1216
|
+
sampleDrawingArcShape();
|
|
1217
|
+
|
|
1218
|
+
function sampleFormatConditionCollection() {
|
|
1219
|
+
const { Workbook, CellArea, FormatConditionType, OperatorType, Color } = require("aspose.cells.node");
|
|
1220
|
+
|
|
1221
|
+
//Adds an empty conditional formatting
|
|
1222
|
+
var workbook = new Workbook();
|
|
1223
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
1224
|
+
var index = sheet.getConditionalFormattings().add();
|
|
1225
|
+
var fcs = sheet.getConditionalFormattings().get(index);
|
|
1226
|
+
//Sets the conditional format range.
|
|
1227
|
+
var ca = new CellArea();
|
|
1228
|
+
ca.startRow = 0;
|
|
1229
|
+
ca.endRow = 0;
|
|
1230
|
+
ca.startColumn = 0;
|
|
1231
|
+
ca.endColumn = 0;
|
|
1232
|
+
fcs.addArea(ca);
|
|
1233
|
+
ca = new CellArea();
|
|
1234
|
+
ca.startRow = 1;
|
|
1235
|
+
ca.endRow = 1;
|
|
1236
|
+
ca.startColumn = 1;
|
|
1237
|
+
ca.endColumn = 1;
|
|
1238
|
+
fcs.addArea(ca);
|
|
1239
|
+
//Adds condition.
|
|
1240
|
+
var conditionIndex = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
|
|
1241
|
+
//Adds condition.
|
|
1242
|
+
var conditionIndex2 = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
|
|
1243
|
+
//Sets the background color.
|
|
1244
|
+
var fc = fcs.get(conditionIndex);
|
|
1245
|
+
fc.getStyle().setBackgroundColor(Color.Red);
|
|
1246
|
+
//Saving the Excel file
|
|
1247
|
+
workbook.save("output/FormatConditionCollection.xls");
|
|
1248
|
+
}
|
|
1249
|
+
sampleFormatConditionCollection();
|
|
1250
|
+
|
|
1251
|
+
function sampleCommentCollection() {
|
|
1252
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1253
|
+
|
|
1254
|
+
var workbook = new Workbook();
|
|
1255
|
+
var comments = workbook.getWorksheets().get(0).getComments();
|
|
1256
|
+
}
|
|
1257
|
+
sampleCommentCollection();
|
|
1258
|
+
|
|
1259
|
+
function sampleBorderCollection() {
|
|
1260
|
+
const { Workbook, BorderType, CellBorderType, Color } = require("aspose.cells.node");
|
|
1261
|
+
|
|
1262
|
+
//Instantiating a Workbook object
|
|
1263
|
+
var workbook = new Workbook();
|
|
1264
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
1265
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
1266
|
+
//Accessing the "A1" cell from the worksheet
|
|
1267
|
+
var cell = worksheet.getCells().get("A1");
|
|
1268
|
+
//Adding some value to the "A1" cell
|
|
1269
|
+
cell.putValue("Visit Aspose!");
|
|
1270
|
+
//Get style object from cell
|
|
1271
|
+
var style = cell.getStyle();
|
|
1272
|
+
//Setting the line style of the top border
|
|
1273
|
+
style.getBorders().get(BorderType.TopBorder).setLineStyle(CellBorderType.Thick);
|
|
1274
|
+
//Setting the color of the top border
|
|
1275
|
+
style.getBorders().get(BorderType.TopBorder).setColor(Color.Black);
|
|
1276
|
+
//Setting the line style of the bottom border
|
|
1277
|
+
style.getBorders().get(BorderType.BottomBorder).setLineStyle(CellBorderType.Thick);
|
|
1278
|
+
//Setting the color of the bottom border
|
|
1279
|
+
style.getBorders().get(BorderType.BottomBorder).setColor(Color.Black);
|
|
1280
|
+
//Setting the line style of the left border
|
|
1281
|
+
style.getBorders().get(BorderType.LeftBorder).setLineStyle(CellBorderType.Thick);
|
|
1282
|
+
//Setting the color of the left border
|
|
1283
|
+
style.getBorders().get(BorderType.LeftBorder).setColor(Color.Black);
|
|
1284
|
+
//Setting the line style of the right border
|
|
1285
|
+
style.getBorders().get(BorderType.RightBorder).setLineStyle(CellBorderType.Thick);
|
|
1286
|
+
//Setting the color of the right border
|
|
1287
|
+
style.getBorders().get(BorderType.RightBorder).setColor(Color.Black);
|
|
1288
|
+
//Set style object to cell
|
|
1289
|
+
cell.setStyle(style);
|
|
1290
|
+
|
|
1291
|
+
//Saving the Excel file
|
|
1292
|
+
workbook.save("output/BorderCollection.xls");
|
|
1293
|
+
}
|
|
1294
|
+
sampleBorderCollection();
|
|
1295
|
+
|
|
1296
|
+
function sampleChartsAxis() {
|
|
1297
|
+
const { Workbook, ChartType, CrossType } = require("aspose.cells.node");
|
|
1298
|
+
|
|
1299
|
+
//Instantiating a Workbook object
|
|
1300
|
+
var workbook = new Workbook();
|
|
1301
|
+
//Adding a new worksheet to the Excel object
|
|
1302
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1303
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
1304
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1305
|
+
//Adding a sample value to "A1" cell
|
|
1306
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1307
|
+
//Adding a sample value to "A2" cell
|
|
1308
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1309
|
+
//Adding a sample value to "A3" cell
|
|
1310
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1311
|
+
//Adding a sample value to "B1" cell
|
|
1312
|
+
worksheet.getCells().get("B1").putValue(4);
|
|
1313
|
+
//Adding a sample value to "B2" cell
|
|
1314
|
+
worksheet.getCells().get("B2").putValue(20);
|
|
1315
|
+
//Adding a sample value to "B3" cell
|
|
1316
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1317
|
+
//Adding a chart to the worksheet
|
|
1318
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 25, 5);
|
|
1319
|
+
//Accessing the instance of the newly added chart
|
|
1320
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1321
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
1322
|
+
chart.getNSeries().add("A1:B3", true);
|
|
1323
|
+
//Set the max value of value axis
|
|
1324
|
+
chart.getValueAxis().setMaxValue(200);
|
|
1325
|
+
//Set the min value of value axis
|
|
1326
|
+
chart.getValueAxis().setMinValue(0);
|
|
1327
|
+
//Set the major unit
|
|
1328
|
+
chart.getValueAxis().setMajorUnit(25);
|
|
1329
|
+
//Category(X) axis crosses at the maxinum value.
|
|
1330
|
+
chart.getValueAxis().setCrossType(CrossType.Maximum);
|
|
1331
|
+
//Set he number of categories or series between tick-mark labels.
|
|
1332
|
+
chart.getCategoryAxis().setTickLabelSpacing(2);
|
|
1333
|
+
//Saving the Excel file
|
|
1334
|
+
workbook.save("output/ChartsAxis.xlsx");
|
|
1335
|
+
}
|
|
1336
|
+
sampleChartsAxis();
|
|
1337
|
+
|
|
1338
|
+
function sampleChartsAxisMajorUnitScale() {
|
|
1339
|
+
const { Workbook, ChartType, CategoryType, TimeUnit } = require("aspose.cells.node");
|
|
1340
|
+
|
|
1341
|
+
var workbook = new Workbook();
|
|
1342
|
+
//Adding a new worksheet to the Excel object
|
|
1343
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1344
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
1345
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1346
|
+
//Adding a sample value to "A1" cell
|
|
1347
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1348
|
+
//Adding a sample value to "A2" cell
|
|
1349
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1350
|
+
//Adding a sample value to "A3" cell
|
|
1351
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1352
|
+
//Adding a sample value to "B1" cell
|
|
1353
|
+
worksheet.getCells().get("B1").putValue(4);
|
|
1354
|
+
//Adding a sample value to "B2" cell
|
|
1355
|
+
worksheet.getCells().get("B2").putValue(20);
|
|
1356
|
+
//Adding a sample value to "B3" cell
|
|
1357
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1358
|
+
|
|
1359
|
+
//Adding a chart to the worksheet
|
|
1360
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 25, 5);
|
|
1361
|
+
//Accessing the instance of the newly added chart
|
|
1362
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1363
|
+
chart.getCategoryAxis().setCategoryType(CategoryType.TimeScale);
|
|
1364
|
+
chart.getCategoryAxis().setMajorUnitScale(TimeUnit.Months);
|
|
1365
|
+
chart.getCategoryAxis().setMajorUnit(2);
|
|
1366
|
+
}
|
|
1367
|
+
sampleChartsAxisMajorUnitScale();
|
|
1368
|
+
|
|
1369
|
+
function sampleChartsAxisMinorUnitScale() {
|
|
1370
|
+
const { Workbook, ChartType, CategoryType, TimeUnit } = require("aspose.cells.node");
|
|
1371
|
+
|
|
1372
|
+
var workbook = new Workbook();
|
|
1373
|
+
//Adding a new worksheet to the Excel object
|
|
1374
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1375
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
1376
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1377
|
+
//Adding a sample value to "A1" cell
|
|
1378
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1379
|
+
//Adding a sample value to "A2" cell
|
|
1380
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1381
|
+
//Adding a sample value to "A3" cell
|
|
1382
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1383
|
+
//Adding a sample value to "B1" cell
|
|
1384
|
+
worksheet.getCells().get("B1").putValue(4);
|
|
1385
|
+
//Adding a sample value to "B2" cell
|
|
1386
|
+
worksheet.getCells().get("B2").putValue(20);
|
|
1387
|
+
//Adding a sample value to "B3" cell
|
|
1388
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1389
|
+
|
|
1390
|
+
//Adding a chart to the worksheet
|
|
1391
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 25, 5);
|
|
1392
|
+
//Accessing the instance of the newly added chart
|
|
1393
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1394
|
+
chart.getCategoryAxis().setCategoryType(CategoryType.TimeScale);
|
|
1395
|
+
chart.getCategoryAxis().setMinorUnitScale(TimeUnit.Months);
|
|
1396
|
+
chart.getCategoryAxis().setMinorUnit(2);
|
|
1397
|
+
}
|
|
1398
|
+
sampleChartsAxisMinorUnitScale();
|
|
1399
|
+
|
|
1400
|
+
function sampleChartsAxisMajorGridLines() {
|
|
1401
|
+
const { Workbook, ChartType } = require("aspose.cells.node");
|
|
1402
|
+
|
|
1403
|
+
var workbook = new Workbook();
|
|
1404
|
+
//Adding a new worksheet to the Excel object
|
|
1405
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1406
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
1407
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1408
|
+
//Adding a sample value to "A1" cell
|
|
1409
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1410
|
+
//Adding a sample value to "A2" cell
|
|
1411
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1412
|
+
//Adding a sample value to "A3" cell
|
|
1413
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1414
|
+
//Adding a sample value to "B1" cell
|
|
1415
|
+
worksheet.getCells().get("B1").putValue(4);
|
|
1416
|
+
//Adding a sample value to "B2" cell
|
|
1417
|
+
worksheet.getCells().get("B2").putValue(20);
|
|
1418
|
+
//Adding a sample value to "B3" cell
|
|
1419
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1420
|
+
|
|
1421
|
+
//Adding a chart to the worksheet
|
|
1422
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 25, 5);
|
|
1423
|
+
//Accessing the instance of the newly added chart
|
|
1424
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1425
|
+
chart.getValueAxis().getMajorGridLines().setIsVisible(false);
|
|
1426
|
+
chart.getCategoryAxis().getMajorGridLines().setIsVisible(true);
|
|
1427
|
+
}
|
|
1428
|
+
sampleChartsAxisMajorGridLines();
|
|
1429
|
+
|
|
1430
|
+
function sampleRenderingPdfBookmarkEntry() {
|
|
1431
|
+
// // // // const { Workbook, PdfBookmarkEntry, PdfSaveOptions } = require("aspose.cells.node");
|
|
1432
|
+
|
|
1433
|
+
// var workbook = new Workbook();
|
|
1434
|
+
// workbook.getWorksheets().add();
|
|
1435
|
+
// workbook.getWorksheets().add();
|
|
1436
|
+
// var cellInPage1 = workbook.getWorksheets().get(0).getCells().get("A1");
|
|
1437
|
+
// var cellInPage2 = workbook.getWorksheets().get(1).getCells().get("A1");
|
|
1438
|
+
// var cellInPage3 = workbook.getWorksheets().get(2).getCells().get("A1");
|
|
1439
|
+
// cellInPage1.putValue("page1");
|
|
1440
|
+
// cellInPage2.putValue("page2");
|
|
1441
|
+
// cellInPage3.putValue("page3");
|
|
1442
|
+
|
|
1443
|
+
// var pbeRoot = new PdfBookmarkEntry();
|
|
1444
|
+
// pbeRoot.setText("root");
|
|
1445
|
+
// pbeRoot.setDestination(cellInPage1);
|
|
1446
|
+
// var list = java.newInstanceSync("java.util.ArrayList");
|
|
1447
|
+
// pbeRoot.setSubEntry(list);
|
|
1448
|
+
// pbeRoot.setOpen(false);
|
|
1449
|
+
|
|
1450
|
+
// var subPbe1 = new PdfBookmarkEntry();
|
|
1451
|
+
// subPbe1.setText("section1");
|
|
1452
|
+
// subPbe1.setDestination(cellInPage2);
|
|
1453
|
+
|
|
1454
|
+
// var subPbe2 = new PdfBookmarkEntry();
|
|
1455
|
+
// subPbe2.setText("section2");
|
|
1456
|
+
// subPbe2.setDestination(cellInPage3);
|
|
1457
|
+
|
|
1458
|
+
// pbeRoot.getSubEntry().add(subPbe1);
|
|
1459
|
+
// pbeRoot.getSubEntry().add(subPbe2);
|
|
1460
|
+
|
|
1461
|
+
// var opts = new PdfSaveOptions();
|
|
1462
|
+
// opts.setBookmark(pbeRoot);
|
|
1463
|
+
// workbook.save("output/RenderingPdfBookmarkEntry.pdf", opts);
|
|
1464
|
+
//
|
|
1465
|
+
}
|
|
1466
|
+
sampleRenderingPdfBookmarkEntry();
|
|
1467
|
+
|
|
1468
|
+
function sampleFormatCondition() {
|
|
1469
|
+
const { Workbook, CellArea, FormatConditionType, OperatorType, Color } = require("aspose.cells.node");
|
|
1470
|
+
|
|
1471
|
+
//Instantiating a Workbook object
|
|
1472
|
+
var workbook = new Workbook();
|
|
1473
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
1474
|
+
|
|
1475
|
+
//Adds an empty conditional formatting
|
|
1476
|
+
var index = sheet.getConditionalFormattings().add();
|
|
1477
|
+
var fcs = sheet.getConditionalFormattings().get(index);
|
|
1478
|
+
|
|
1479
|
+
//Sets the conditional format range.
|
|
1480
|
+
var ca = new CellArea();
|
|
1481
|
+
ca.startRow = 0;
|
|
1482
|
+
ca.endRow = 0;
|
|
1483
|
+
ca.startColumn = 0;
|
|
1484
|
+
ca.endColumn = 0;
|
|
1485
|
+
fcs.addArea(ca);
|
|
1486
|
+
|
|
1487
|
+
ca = new CellArea();
|
|
1488
|
+
ca.startRow = 1;
|
|
1489
|
+
ca.endRow = 1;
|
|
1490
|
+
ca.startColumn = 1;
|
|
1491
|
+
ca.endColumn = 1;
|
|
1492
|
+
fcs.addArea(ca);
|
|
1493
|
+
|
|
1494
|
+
//Adds condition.
|
|
1495
|
+
var conditionIndex = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
|
|
1496
|
+
//Adds condition.
|
|
1497
|
+
var conditionIndex2 = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
|
|
1498
|
+
|
|
1499
|
+
//Sets the background color.
|
|
1500
|
+
var fc = fcs.get(conditionIndex);
|
|
1501
|
+
fc.getStyle().setBackgroundColor(Color.Red);
|
|
1502
|
+
|
|
1503
|
+
//Saving the Excel file
|
|
1504
|
+
workbook.save("output/FormatCondition.xls");
|
|
1505
|
+
}
|
|
1506
|
+
sampleFormatCondition();
|
|
1507
|
+
|
|
1508
|
+
function sampleChartsDataLabels() {
|
|
1509
|
+
const { Workbook, ChartType, LabelPositionType } = require("aspose.cells.node");
|
|
1510
|
+
|
|
1511
|
+
var workbook = new Workbook();
|
|
1512
|
+
//Adding a new worksheet to the Excel object
|
|
1513
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
1514
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
1515
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
1516
|
+
//Adding a sample value to "A1" cell
|
|
1517
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1518
|
+
//Adding a sample value to "A2" cell
|
|
1519
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1520
|
+
//Adding a sample value to "A3" cell
|
|
1521
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1522
|
+
//Adding a sample value to "B1" cell
|
|
1523
|
+
worksheet.getCells().get("B1").putValue(4);
|
|
1524
|
+
//Adding a sample value to "B2" cell
|
|
1525
|
+
worksheet.getCells().get("B2").putValue(20);
|
|
1526
|
+
//Adding a sample value to "B3" cell
|
|
1527
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1528
|
+
|
|
1529
|
+
//Adding a chart to the worksheet
|
|
1530
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 25, 5);
|
|
1531
|
+
//Accessing the instance of the newly added chart
|
|
1532
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1533
|
+
//Set the DataLabels in the chart
|
|
1534
|
+
var datalabels;
|
|
1535
|
+
for (var i = 0; i < chart.getNSeries().getCount(); i++) {
|
|
1536
|
+
datalabels = chart.getNSeries().get(i).getDataLabels();
|
|
1537
|
+
//Set the position of DataLabels
|
|
1538
|
+
datalabels.setPosition(LabelPositionType.InsideBase);
|
|
1539
|
+
//Show the category name in the DataLabels
|
|
1540
|
+
datalabels.setCategoryNameShown(true);
|
|
1541
|
+
//Show the value in the DataLabels
|
|
1542
|
+
datalabels.setShowValue(true);
|
|
1543
|
+
//Not show the percentage in the DataLabels
|
|
1544
|
+
datalabels.setPercentageShown(false);
|
|
1545
|
+
//Not show the legend key.
|
|
1546
|
+
datalabels.setLegendKeyShown(false);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
sampleChartsDataLabels();
|
|
1550
|
+
|
|
1551
|
+
function sampleWorksheet() {
|
|
1552
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1553
|
+
|
|
1554
|
+
var workbook = new Workbook();
|
|
1555
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
1556
|
+
//Freeze panes at "AS40" with 10 rows and 10 columns
|
|
1557
|
+
sheet.freezePanes("AS40", 10, 10);
|
|
1558
|
+
//Add a hyperlink in Cell A1
|
|
1559
|
+
sheet.getHyperlinks().add("A1", 1, 1, "http://www.aspose.com");
|
|
1560
|
+
}
|
|
1561
|
+
sampleWorksheet();
|
|
1562
|
+
|
|
1563
|
+
function sampleWorksheetProtectTypeStringString() {
|
|
1564
|
+
const { Workbook, ProtectionType } = require("aspose.cells.node");
|
|
1565
|
+
|
|
1566
|
+
//Instantiating a Workbook object
|
|
1567
|
+
var excel = new Workbook("input/Book1.xls");
|
|
1568
|
+
//Accessing the first worksheet in the Excel file
|
|
1569
|
+
var worksheet = excel.getWorksheets().get(0);
|
|
1570
|
+
//Protecting the worksheet with a password
|
|
1571
|
+
worksheet.protect(ProtectionType.All, "aspose", null);
|
|
1572
|
+
//Saving the modified Excel file in default (that is Excel 20003) format
|
|
1573
|
+
excel.save("output/WorksheetProtect.xls");
|
|
1574
|
+
}
|
|
1575
|
+
sampleWorksheetProtectTypeStringString();
|
|
1576
|
+
|
|
1577
|
+
function sampleHorizontalPageBreakCollection() {
|
|
1578
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1579
|
+
|
|
1580
|
+
var excel = new Workbook();
|
|
1581
|
+
//Add a pagebreak at G5
|
|
1582
|
+
excel.getWorksheets().get(0).getHorizontalPageBreaks().add("G5");
|
|
1583
|
+
excel.getWorksheets().get(0).getVerticalPageBreaks().add("G5");
|
|
1584
|
+
}
|
|
1585
|
+
sampleHorizontalPageBreakCollection();
|
|
1586
|
+
|
|
1587
|
+
function sampleDrawingCheckbox() {
|
|
1588
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1589
|
+
|
|
1590
|
+
var excel = new Workbook();
|
|
1591
|
+
var index = excel.getWorksheets().get(0).getCheckBoxes().add(15, 15, 20, 100);
|
|
1592
|
+
var checkBox = excel.getWorksheets().get(0).getCheckBoxes().get(index);
|
|
1593
|
+
checkBox.setText("Check Box 1");
|
|
1594
|
+
}
|
|
1595
|
+
sampleDrawingCheckbox();
|
|
1596
|
+
|
|
1597
|
+
function sampleCell() {
|
|
1598
|
+
const { Workbook, Color, TextAlignmentType } = require("aspose.cells.node");
|
|
1599
|
+
|
|
1600
|
+
var excel = new Workbook();
|
|
1601
|
+
var cells = excel.getWorksheets().get(0).getCells();
|
|
1602
|
+
|
|
1603
|
+
//Put a string into a cell
|
|
1604
|
+
var cell = cells.get(0, 0);
|
|
1605
|
+
cell.putValue("Hello");
|
|
1606
|
+
var first = cell.getStringValue();
|
|
1607
|
+
//Put an integer into a cell
|
|
1608
|
+
cell = cells.get("B1");
|
|
1609
|
+
cell.putValue(12);
|
|
1610
|
+
var second = cell.getIntValue();
|
|
1611
|
+
//Put a double into a cell
|
|
1612
|
+
cell = cells.get(0, 2);
|
|
1613
|
+
cell.putValue(-1.234);
|
|
1614
|
+
var third = cell.getDoubleValue();
|
|
1615
|
+
//Put a formula into a cell
|
|
1616
|
+
cell = cells.get("D1");
|
|
1617
|
+
cell.setFormula("=B1 + C1");
|
|
1618
|
+
//Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2
|
|
1619
|
+
cell = cells.get("b2");
|
|
1620
|
+
cell.setFormula("=sum(average(b1,c1), b1)");
|
|
1621
|
+
|
|
1622
|
+
//Set style of a cell
|
|
1623
|
+
var style = cell.getStyle();
|
|
1624
|
+
//Set background color
|
|
1625
|
+
style.setBackgroundColor(Color.Yellow);
|
|
1626
|
+
//Set format of a cell
|
|
1627
|
+
style.getFont().setName("Courier New");
|
|
1628
|
+
style.setVerticalAlignment(TextAlignmentType.Top);
|
|
1629
|
+
cell.setStyle(style);
|
|
1630
|
+
}
|
|
1631
|
+
sampleCell();
|
|
1632
|
+
|
|
1633
|
+
function sampleCellGetPrecedents() {
|
|
1634
|
+
const { Workbook, CellsHelper } = require("aspose.cells.node");
|
|
1635
|
+
|
|
1636
|
+
var workbook = new Workbook();
|
|
1637
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
1638
|
+
cells.get("A1").setFormula("= B1 + SUM(B1:B10)");
|
|
1639
|
+
var areas = cells.get("A1").getPrecedents();
|
|
1640
|
+
for (var i = 0; i < areas.getCount(); i++) {
|
|
1641
|
+
var area = areas.get(i);
|
|
1642
|
+
var stringBuilder = "";
|
|
1643
|
+
if (area.isExternalLink()) {
|
|
1644
|
+
stringBuilder += "[";
|
|
1645
|
+
stringBuilder += area.getExternalFileName();
|
|
1646
|
+
stringBuilder += "]";
|
|
1647
|
+
}
|
|
1648
|
+
stringBuilder += area.getSheetName();
|
|
1649
|
+
stringBuilder += "!";
|
|
1650
|
+
stringBuilder += CellsHelper.cellIndexToName(area.getStartRow(), area.getStartColumn());
|
|
1651
|
+
if (area.isArea()) {
|
|
1652
|
+
stringBuilder += ":";
|
|
1653
|
+
stringBuilder += CellsHelper.cellIndexToName(area.getEndRow(), area.getEndColumn());
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
workbook.save("output/CellGetPrecedents.xls");
|
|
1657
|
+
}
|
|
1658
|
+
sampleCellGetPrecedents();
|
|
1659
|
+
|
|
1660
|
+
function sampleCellCharactersIntInt() {
|
|
1661
|
+
const { Workbook, Color } = require("aspose.cells.node");
|
|
1662
|
+
|
|
1663
|
+
var excel = new Workbook();
|
|
1664
|
+
excel.getWorksheets().get(0).getCells().get("A1").putValue("Helloworld");
|
|
1665
|
+
excel.getWorksheets().get(0).getCells().get("A1").characters(5, 5).getFont().setIsBold(true);
|
|
1666
|
+
excel.getWorksheets().get(0).getCells().get("A1").characters(5, 5).getFont().setColor(Color.Blue);
|
|
1667
|
+
}
|
|
1668
|
+
sampleCellCharactersIntInt();
|
|
1669
|
+
|
|
1670
|
+
function sampleCellFormula() {
|
|
1671
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1672
|
+
|
|
1673
|
+
var excel = new Workbook();
|
|
1674
|
+
var cells = excel.getWorksheets().get(0).getCells();
|
|
1675
|
+
cells.get("B6").setFormula("=SUM(B2:B5, E1) + sheet2!A1");
|
|
1676
|
+
}
|
|
1677
|
+
sampleCellFormula();
|
|
1678
|
+
|
|
1679
|
+
function sampleDrawingLabel() {
|
|
1680
|
+
const { Workbook, MsoDrawingType, PlacementType, FillType, Color } = require("aspose.cells.node");
|
|
1681
|
+
|
|
1682
|
+
//Create a new Workbook.
|
|
1683
|
+
var workbook = new Workbook();
|
|
1684
|
+
//Get the first worksheet in the workbook.
|
|
1685
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
1686
|
+
//Add a new label to the worksheet.
|
|
1687
|
+
var label = sheet.getShapes().addShape(MsoDrawingType.Label, 2, 0, 2, 0, 60, 120);
|
|
1688
|
+
//Set the caption of the label.
|
|
1689
|
+
label.setText("This is a Label");
|
|
1690
|
+
//Set the Placement Type, the way the
|
|
1691
|
+
//label is attached to the cells.
|
|
1692
|
+
label.setPlacement(PlacementType.FreeFloating);
|
|
1693
|
+
//Set the fill color of the label.
|
|
1694
|
+
label.getFill().setFillType(FillType.Solid);
|
|
1695
|
+
label.getFill().getSolidFill().setColor(Color.Yellow);
|
|
1696
|
+
//Saves the file.
|
|
1697
|
+
workbook.save("output/DrawingLabel.xls");
|
|
1698
|
+
}
|
|
1699
|
+
sampleDrawingLabel();
|
|
1700
|
+
|
|
1701
|
+
function sampleDrawingGroupShape() {
|
|
1702
|
+
const { Workbook, PlacementType, FillType, Color, MsoLineStyle, MsoLineDashStyle } = require("aspose.cells.node");
|
|
1703
|
+
|
|
1704
|
+
//Instantiate a new Workbook.
|
|
1705
|
+
var excelbook = new Workbook();
|
|
1706
|
+
//Add a group box to the first worksheet.
|
|
1707
|
+
var box = excelbook.getWorksheets().get(0).getShapes().addGroupBox(1, 0, 1, 0, 300, 250);
|
|
1708
|
+
//Set the caption of the group box.
|
|
1709
|
+
box.setText("Age Groups");
|
|
1710
|
+
box.setPlacement(PlacementType.FreeFloating);
|
|
1711
|
+
//Make it 2-D box.
|
|
1712
|
+
box.setShadow(false);
|
|
1713
|
+
//Add a radio button.
|
|
1714
|
+
var radio1 = excelbook.getWorksheets().get(0).getShapes().addRadioButton(3, 0, 2, 0, 30, 110);
|
|
1715
|
+
//Set its text string.
|
|
1716
|
+
radio1.setText("20-29");
|
|
1717
|
+
//Set A1 cell as a linked cell for the radio button.
|
|
1718
|
+
radio1.setLinkedCell("A1");
|
|
1719
|
+
//Make the radio button 3-D.
|
|
1720
|
+
radio1.setShadow(true);
|
|
1721
|
+
//Set the foreground color of the radio button.
|
|
1722
|
+
radio1.getFill().setFillType(FillType.Solid);
|
|
1723
|
+
radio1.getFill().getSolidFill().setColor(Color.LightGreen);
|
|
1724
|
+
//Set the line style of the radio button.
|
|
1725
|
+
radio1.getLine().setCompoundType(MsoLineStyle.ThickThin);
|
|
1726
|
+
//Set the weight of the radio button.
|
|
1727
|
+
radio1.getLine().setWeight(4);
|
|
1728
|
+
//Set the line color of the radio button.
|
|
1729
|
+
radio1.getLine().setFillType(FillType.Solid);
|
|
1730
|
+
radio1.getLine().getSolidFill().setColor(Color.Blue);
|
|
1731
|
+
//Set the dash style of the radio button.
|
|
1732
|
+
radio1.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
1733
|
+
//Add another radio button.
|
|
1734
|
+
var radio2 = excelbook.getWorksheets().get(0).getShapes().addRadioButton(6, 0, 2, 0, 30, 110);
|
|
1735
|
+
//Set its text string.
|
|
1736
|
+
radio2.setText("30-39");
|
|
1737
|
+
//Set A1 cell as a linked cell for the radio button.
|
|
1738
|
+
radio2.setLinkedCell("A1");
|
|
1739
|
+
//Make the radio button 3-D.
|
|
1740
|
+
radio2.setShadow(true);
|
|
1741
|
+
//Set the foreground color of the radio button.
|
|
1742
|
+
radio2.getFill().setFillType(FillType.Solid);
|
|
1743
|
+
radio2.getFill().getSolidFill().setColor(Color.LightGreen);
|
|
1744
|
+
//Set the line style of the radio button.
|
|
1745
|
+
radio2.getLine().setCompoundType(MsoLineStyle.ThickThin);
|
|
1746
|
+
//Set the weight of the radio button.
|
|
1747
|
+
radio2.getLine().setWeight(4);
|
|
1748
|
+
//Set the line color of the radio button.
|
|
1749
|
+
radio2.getLine().setFillType(FillType.Solid);
|
|
1750
|
+
radio2.getLine().getSolidFill().setColor(Color.Blue);
|
|
1751
|
+
//Set the dash style of the radio button.
|
|
1752
|
+
radio2.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
1753
|
+
//Add another radio button.
|
|
1754
|
+
var radio3 = excelbook.getWorksheets().get(0).getShapes().addRadioButton(9, 0, 2, 0, 30, 110);
|
|
1755
|
+
//Set its text string.
|
|
1756
|
+
radio3.setText("40-49");
|
|
1757
|
+
//Set A1 cell as a linked cell for the radio button.
|
|
1758
|
+
radio3.setLinkedCell("A1");
|
|
1759
|
+
//Make the radio button 3-D.
|
|
1760
|
+
radio3.setShadow(true);
|
|
1761
|
+
//Set the foreground color of the radio button.
|
|
1762
|
+
radio3.getFill().setFillType(FillType.Solid);
|
|
1763
|
+
radio3.getFill().getSolidFill().setColor(Color.LightGreen);
|
|
1764
|
+
//Set the line style of the radio button.
|
|
1765
|
+
radio3.getLine().setCompoundType(MsoLineStyle.ThickThin);
|
|
1766
|
+
//Set the weight of the radio button.
|
|
1767
|
+
radio3.getLine().setWeight(4);
|
|
1768
|
+
//Set the line color of the radio button.
|
|
1769
|
+
radio3.getLine().setFillType(FillType.Solid);
|
|
1770
|
+
radio3.getLine().getSolidFill().setColor(Color.Blue);
|
|
1771
|
+
//Set the dash style of the radio button.
|
|
1772
|
+
radio3.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
1773
|
+
|
|
1774
|
+
//Get the shapes.
|
|
1775
|
+
var shapeobjects = [ box, radio1, radio2, radio3 ];
|
|
1776
|
+
//Group the shapes.
|
|
1777
|
+
var group = excelbook.getWorksheets().get(0).getShapes().group(shapeobjects);
|
|
1778
|
+
|
|
1779
|
+
//Save the excel file.
|
|
1780
|
+
excelbook.save("output/DrawingGroupShape.xls");
|
|
1781
|
+
}
|
|
1782
|
+
sampleDrawingGroupShape();
|
|
1783
|
+
|
|
1784
|
+
function sampleCells() {
|
|
1785
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1786
|
+
|
|
1787
|
+
var excel = new Workbook();
|
|
1788
|
+
var cells = excel.getWorksheets().get(0).getCells();
|
|
1789
|
+
//Set default row height
|
|
1790
|
+
cells.setStandardHeight(20);
|
|
1791
|
+
//Set row height
|
|
1792
|
+
cells.setRowHeight(2, 20.5);
|
|
1793
|
+
//Set default colum width
|
|
1794
|
+
cells.setStandardWidth(15);
|
|
1795
|
+
//Set column width
|
|
1796
|
+
cells.setColumnWidth(3, 12.57);
|
|
1797
|
+
//Merge cells
|
|
1798
|
+
cells.merge(5, 4, 2, 2);
|
|
1799
|
+
}
|
|
1800
|
+
sampleCells();
|
|
1801
|
+
|
|
1802
|
+
function sampleCellsItemIntInt() {
|
|
1803
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1804
|
+
|
|
1805
|
+
var excel = new Workbook();
|
|
1806
|
+
var cells = excel.getWorksheets().get(0).getCells();
|
|
1807
|
+
var cell = cells.get(0, 0); //Gets the cell at "A1"
|
|
1808
|
+
}
|
|
1809
|
+
sampleCellsItemIntInt();
|
|
1810
|
+
|
|
1811
|
+
function sampleCellsItemString() {
|
|
1812
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1813
|
+
|
|
1814
|
+
var excel = new Workbook();
|
|
1815
|
+
var cells = excel.getWorksheets().get(0).getCells();
|
|
1816
|
+
var cell = cells.get("A1"); //Gets the cell at "A1"
|
|
1817
|
+
}
|
|
1818
|
+
sampleCellsItemString();
|
|
1819
|
+
|
|
1820
|
+
function sampleWorksheetCollection() {
|
|
1821
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1822
|
+
|
|
1823
|
+
var workbook = new Workbook();
|
|
1824
|
+
var sheets = workbook.getWorksheets();
|
|
1825
|
+
//Add a worksheet
|
|
1826
|
+
sheets.add();
|
|
1827
|
+
//Change the name of a worksheet
|
|
1828
|
+
sheets.get(0).setName("First Sheet");
|
|
1829
|
+
//Set the active sheet to the second worksheet
|
|
1830
|
+
sheets.setActiveSheetIndex(1);
|
|
1831
|
+
}
|
|
1832
|
+
sampleWorksheetCollection();
|
|
1833
|
+
|
|
1834
|
+
function sampleWorksheetCollectionAddSheetType() {
|
|
1835
|
+
const { Workbook, SheetType, ChartType } = require("aspose.cells.node");
|
|
1836
|
+
|
|
1837
|
+
var workbook = new Workbook();
|
|
1838
|
+
workbook.getWorksheets().add(SheetType.Chart);
|
|
1839
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
1840
|
+
cells.get("c2").putValue(5000);
|
|
1841
|
+
cells.get("c3").putValue(3000);
|
|
1842
|
+
cells.get("c4").putValue(4000);
|
|
1843
|
+
cells.get("c5").putValue(5000);
|
|
1844
|
+
cells.get("c6").putValue(6000);
|
|
1845
|
+
var charts = workbook.getWorksheets().get(1).getCharts();
|
|
1846
|
+
var chartIndex = charts.add(ChartType.Column, 10, 10, 20, 20);
|
|
1847
|
+
var chart = charts.get(chartIndex);
|
|
1848
|
+
chart.getNSeries().add("Sheet1!C2:C6", true);
|
|
1849
|
+
}
|
|
1850
|
+
sampleWorksheetCollectionAddSheetType();
|
|
1851
|
+
|
|
1852
|
+
function sampleWorksheetCollectionBuiltInDocumentProperties() {
|
|
1853
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1854
|
+
|
|
1855
|
+
var workbook = new Workbook();
|
|
1856
|
+
var doc = workbook.getWorksheets().getBuiltInDocumentProperties().get("Author");
|
|
1857
|
+
doc.setValue("John Smith");
|
|
1858
|
+
}
|
|
1859
|
+
sampleWorksheetCollectionBuiltInDocumentProperties();
|
|
1860
|
+
|
|
1861
|
+
function sampleWorksheetCollectionCustomDocumentProperties() {
|
|
1862
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1863
|
+
|
|
1864
|
+
var excel = new Workbook();
|
|
1865
|
+
excel.getWorksheets().getCustomDocumentProperties().add("Checked by", "Jane");
|
|
1866
|
+
}
|
|
1867
|
+
sampleWorksheetCollectionCustomDocumentProperties();
|
|
1868
|
+
|
|
1869
|
+
function sampleVerticalPageBreak() {
|
|
1870
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1871
|
+
|
|
1872
|
+
var excel = new Workbook();
|
|
1873
|
+
//Add a pagebreak at G5
|
|
1874
|
+
excel.getWorksheets().get(0).getHorizontalPageBreaks().add("G5");
|
|
1875
|
+
excel.getWorksheets().get(0).getVerticalPageBreaks().add("G5");
|
|
1876
|
+
}
|
|
1877
|
+
sampleVerticalPageBreak();
|
|
1878
|
+
|
|
1879
|
+
function sampleExternalLinkCollection() {
|
|
1880
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1881
|
+
|
|
1882
|
+
//Open a file with external links
|
|
1883
|
+
var workbook = new Workbook("input/Externlink.xls");
|
|
1884
|
+
//Change external link data source
|
|
1885
|
+
workbook.getWorksheets().getExternalLinks().get(0).setDataSource("input/Book1.xls");
|
|
1886
|
+
}
|
|
1887
|
+
sampleExternalLinkCollection();
|
|
1888
|
+
|
|
1889
|
+
function sampleDrawingChartShape() {
|
|
1890
|
+
const { Workbook, ChartType } = require("aspose.cells.node");
|
|
1891
|
+
|
|
1892
|
+
//Instantiating a Workbook object
|
|
1893
|
+
var workbook = new Workbook();
|
|
1894
|
+
//Obtaining the reference of the first worksheet
|
|
1895
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
1896
|
+
//Adding a sample value to "A1" cell
|
|
1897
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1898
|
+
//Adding a sample value to "A2" cell
|
|
1899
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1900
|
+
//Adding a sample value to "A3" cell
|
|
1901
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1902
|
+
//Adding a sample value to "B1" cell
|
|
1903
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
1904
|
+
//Adding a sample value to "B2" cell
|
|
1905
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
1906
|
+
//Adding a sample value to "B3" cell
|
|
1907
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1908
|
+
//Adding a chart to the worksheet
|
|
1909
|
+
var chartIndex = worksheet.getCharts().add(ChartType.PieExploded, 5, 0, 25, 10);
|
|
1910
|
+
//Accessing the instance of the newly added chart
|
|
1911
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1912
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
1913
|
+
chart.getNSeries().add("A1:B3", true);
|
|
1914
|
+
//Show Data Labels
|
|
1915
|
+
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
|
|
1916
|
+
//Getting Chart Shape
|
|
1917
|
+
var chartShape = chart.getChartObject();
|
|
1918
|
+
//Set Lower Right Column
|
|
1919
|
+
chartShape.setLowerRightColumn(10);
|
|
1920
|
+
//Set LowerDeltaX
|
|
1921
|
+
chartShape.setLowerDeltaX(1024);
|
|
1922
|
+
//Saving the Excel file
|
|
1923
|
+
workbook.save("output/DrawingChartShape.xls");
|
|
1924
|
+
}
|
|
1925
|
+
sampleDrawingChartShape();
|
|
1926
|
+
|
|
1927
|
+
function sampleChartsChartDataTable() {
|
|
1928
|
+
const { Workbook, ChartType, Color } = require("aspose.cells.node");
|
|
1929
|
+
|
|
1930
|
+
//Instantiating a Workbook object
|
|
1931
|
+
var workbook = new Workbook();
|
|
1932
|
+
//Obtaining the reference of the first worksheet
|
|
1933
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
1934
|
+
//Adding a sample value to "A1" cell
|
|
1935
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
1936
|
+
//Adding a sample value to "A2" cell
|
|
1937
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
1938
|
+
//Adding a sample value to "A3" cell
|
|
1939
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
1940
|
+
//Adding a sample value to "B1" cell
|
|
1941
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
1942
|
+
//Adding a sample value to "B2" cell
|
|
1943
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
1944
|
+
//Adding a sample value to "B3" cell
|
|
1945
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
1946
|
+
//Adding a chart to the worksheet
|
|
1947
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 25, 10);
|
|
1948
|
+
//Accessing the instance of the newly added chart
|
|
1949
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
1950
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
1951
|
+
chart.getNSeries().add("A1:B3", true);
|
|
1952
|
+
chart.setShowDataTable(true);
|
|
1953
|
+
//Getting Chart Table
|
|
1954
|
+
var chartTable = chart.getChartDataTable();
|
|
1955
|
+
//Setting Chart Table Font Color
|
|
1956
|
+
chartTable.getFont().setColor(Color.Red);
|
|
1957
|
+
//Setting Legend Key Visibility
|
|
1958
|
+
chartTable.setShowLegendKey(false);
|
|
1959
|
+
//Saving the Excel file
|
|
1960
|
+
workbook.save("output/ChartsChartDataTable.xls");
|
|
1961
|
+
}
|
|
1962
|
+
sampleChartsChartDataTable();
|
|
1963
|
+
|
|
1964
|
+
function sampleRenderingImageOrPrintOptions() {
|
|
1965
|
+
const { Workbook, ImageOrPrintOptions } = require("aspose.cells.node");
|
|
1966
|
+
|
|
1967
|
+
//Set Image Or Print Options
|
|
1968
|
+
var options = new ImageOrPrintOptions();
|
|
1969
|
+
//set Horizontal resolution
|
|
1970
|
+
options.setHorizontalResolution(200);
|
|
1971
|
+
//set Vertica; Resolution
|
|
1972
|
+
options.setVerticalResolution(300);
|
|
1973
|
+
|
|
1974
|
+
//Instantiate Workbook
|
|
1975
|
+
var book = new Workbook("input/Chart.xls");
|
|
1976
|
+
//Save chart as Image using ImageOrPrint Options
|
|
1977
|
+
book.getWorksheets().get(0).getCharts().get(0).toImage("output/chart.png", options);
|
|
1978
|
+
}
|
|
1979
|
+
sampleRenderingImageOrPrintOptions();
|
|
1980
|
+
|
|
1981
|
+
function sampleName() {
|
|
1982
|
+
const { Workbook } = require("aspose.cells.node");
|
|
1983
|
+
|
|
1984
|
+
//Instantiating a Workbook object
|
|
1985
|
+
var workbook = new Workbook();
|
|
1986
|
+
//Accessing the first worksheet in the Excel file
|
|
1987
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
1988
|
+
//Creating a named range
|
|
1989
|
+
var range = worksheet.getCells().createRange("B4", "G14");
|
|
1990
|
+
//Setting the name of the named range
|
|
1991
|
+
range.setName("TestRange");
|
|
1992
|
+
//Saving the modified Excel file in default (that is Excel 2000) format
|
|
1993
|
+
workbook.save("output/Name.xls");
|
|
1994
|
+
}
|
|
1995
|
+
sampleName();
|
|
1996
|
+
|
|
1997
|
+
function sampleChartsChartArea() {
|
|
1998
|
+
const { Workbook, ChartType, Color } = require("aspose.cells.node");
|
|
1999
|
+
|
|
2000
|
+
//Instantiating a Workbook object
|
|
2001
|
+
var workbook = new Workbook();
|
|
2002
|
+
//Obtaining the reference of the first worksheet
|
|
2003
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2004
|
+
//Adding a sample value to "A1" cell
|
|
2005
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
2006
|
+
//Adding a sample value to "A2" cell
|
|
2007
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
2008
|
+
//Adding a sample value to "A3" cell
|
|
2009
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
2010
|
+
//Adding a sample value to "B1" cell
|
|
2011
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
2012
|
+
//Adding a sample value to "B2" cell
|
|
2013
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
2014
|
+
//Adding a sample value to "B3" cell
|
|
2015
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
2016
|
+
//Adding a chart to the worksheet
|
|
2017
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
2018
|
+
//Accessing the instance of the newly added chart
|
|
2019
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
2020
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
2021
|
+
chart.getNSeries().add("A1:B3", true);
|
|
2022
|
+
//Getting Chart Area
|
|
2023
|
+
var chartArea = chart.getChartArea();
|
|
2024
|
+
//Setting the foreground color of the chart area
|
|
2025
|
+
chartArea.getArea().setForegroundColor(Color.Yellow);
|
|
2026
|
+
//Setting Chart Area Shadow
|
|
2027
|
+
chartArea.setShadow(true);
|
|
2028
|
+
//Saving the Excel file
|
|
2029
|
+
workbook.save("output/ChartsChartArea.xls");
|
|
2030
|
+
}
|
|
2031
|
+
sampleChartsChartArea();
|
|
2032
|
+
|
|
2033
|
+
function sampleChartsChart() {
|
|
2034
|
+
const { Workbook, ChartType } = require("aspose.cells.node");
|
|
2035
|
+
|
|
2036
|
+
var workbook = new Workbook();
|
|
2037
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
2038
|
+
var cells = sheet.getCells();
|
|
2039
|
+
cells.get(0, 1).putValue("Income");
|
|
2040
|
+
cells.get(1, 0).putValue("Company A");
|
|
2041
|
+
cells.get(2, 0).putValue("Company B");
|
|
2042
|
+
cells.get(3, 0).putValue("Company C");
|
|
2043
|
+
cells.get(1, 1).putValue(10000);
|
|
2044
|
+
cells.get(2, 1).putValue(20000);
|
|
2045
|
+
cells.get(3, 1).putValue(30000);
|
|
2046
|
+
var chartIndex = sheet.getCharts().add(ChartType.Column, 9, 9, 21, 15);
|
|
2047
|
+
var chart = sheet.getCharts().get(chartIndex);
|
|
2048
|
+
chart.getNSeries().add("B2:B4", true);
|
|
2049
|
+
chart.getNSeries().setCategoryData("A2:A4");
|
|
2050
|
+
var aSeries = chart.getNSeries().get(0);
|
|
2051
|
+
aSeries.setName("=B1");
|
|
2052
|
+
chart.setShowLegend(true);
|
|
2053
|
+
chart.getTitle().setText("Income Analysis");
|
|
2054
|
+
}
|
|
2055
|
+
sampleChartsChart();
|
|
2056
|
+
|
|
2057
|
+
function sampleChartsChartToImageImageOrPrintOptions() {
|
|
2058
|
+
const fs = require("fs");
|
|
2059
|
+
const { Workbook, ImageOrPrintOptions, ImageType } = require("aspose.cells.node");
|
|
2060
|
+
|
|
2061
|
+
var options = new ImageOrPrintOptions();
|
|
2062
|
+
options.setImageType(ImageType.Jpeg);
|
|
2063
|
+
options.setHorizontalResolution(400);
|
|
2064
|
+
options.setVerticalResolution(300);
|
|
2065
|
+
|
|
2066
|
+
var book = new Workbook("input/Chart.xls");
|
|
2067
|
+
var uint8Array = book.getWorksheets().get(0).getCharts().get(0).toImage(options);
|
|
2068
|
+
const buffer = Buffer.from(uint8Array);
|
|
2069
|
+
fs.writeFileSync("output/chart-stream.jpg", buffer);
|
|
2070
|
+
}
|
|
2071
|
+
sampleChartsChartToImageImageOrPrintOptions();
|
|
2072
|
+
|
|
2073
|
+
function sampleChartsChartToImageStringImageOrPrintOptions() {
|
|
2074
|
+
const { Workbook, ImageOrPrintOptions } = require("aspose.cells.node");
|
|
2075
|
+
|
|
2076
|
+
var options = new ImageOrPrintOptions();
|
|
2077
|
+
options.setHorizontalResolution(400);
|
|
2078
|
+
options.setVerticalResolution(300);
|
|
2079
|
+
options.setQuality(80);
|
|
2080
|
+
|
|
2081
|
+
var book = new Workbook("input/Chart.xls");
|
|
2082
|
+
book.getWorksheets().get(0).getCharts().get(0).toImage("output/chart-r-400x300.png", options);
|
|
2083
|
+
}
|
|
2084
|
+
sampleChartsChartToImageStringImageOrPrintOptions();
|
|
2085
|
+
|
|
2086
|
+
function sampleFontSetting() {
|
|
2087
|
+
const { Workbook, Color } = require("aspose.cells.node");
|
|
2088
|
+
|
|
2089
|
+
//Instantiating a Workbook object
|
|
2090
|
+
var workbook = new Workbook();
|
|
2091
|
+
//Adding a new worksheet to the Excel object
|
|
2092
|
+
workbook.getWorksheets().add();
|
|
2093
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
2094
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2095
|
+
//Accessing the "A1" cell from the worksheet
|
|
2096
|
+
var cell = worksheet.getCells().get("A1");
|
|
2097
|
+
//Adding some value to the "A1" cell
|
|
2098
|
+
cell.putValue("Visit Aspose!");
|
|
2099
|
+
//getting charactor
|
|
2100
|
+
var charactor = cell.characters(6, 7);
|
|
2101
|
+
//Setting the font of selected characters to bold
|
|
2102
|
+
charactor.getFont().setIsBold(true);
|
|
2103
|
+
//Setting the font color of selected characters to blue
|
|
2104
|
+
charactor.getFont().setColor(Color.Blue);
|
|
2105
|
+
//Saving the Excel file
|
|
2106
|
+
workbook.save("output/FontSetting.xls");
|
|
2107
|
+
}
|
|
2108
|
+
sampleFontSetting();
|
|
2109
|
+
|
|
2110
|
+
function sampleDrawingLineShape() {
|
|
2111
|
+
const { Workbook, MsoDrawingType, PlacementType, MsoLineDashStyle } = require("aspose.cells.node");
|
|
2112
|
+
|
|
2113
|
+
//Instantiate a new Workbook.
|
|
2114
|
+
var workbook = new Workbook();
|
|
2115
|
+
//Get the first worksheet in the book.
|
|
2116
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2117
|
+
//Add a new line to the worksheet.
|
|
2118
|
+
var line1 = worksheet.getShapes().addLine(5, 0, 1, 0, 0, 250);
|
|
2119
|
+
//Set the line dash style
|
|
2120
|
+
line1.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
2121
|
+
//Set the placement.
|
|
2122
|
+
line1.setPlacement(PlacementType.FreeFloating);
|
|
2123
|
+
//Add another line to the worksheet.
|
|
2124
|
+
var line2 = worksheet.getShapes().addLine(7, 0, 1, 0, 85, 250);
|
|
2125
|
+
//Set the line dash style.
|
|
2126
|
+
line2.getLine().setDashStyle(MsoLineDashStyle.DashLongDash);
|
|
2127
|
+
//Set the weight of the line.
|
|
2128
|
+
line2.getLine().setWeight(4);
|
|
2129
|
+
//Set the placement.
|
|
2130
|
+
line2.setPlacement(PlacementType.FreeFloating);
|
|
2131
|
+
//Add the third line to the worksheet.
|
|
2132
|
+
var line3 = worksheet.getShapes().addShape(MsoDrawingType.Line, 13, 0, 1, 0, 0, 250);
|
|
2133
|
+
//Set the line dash style
|
|
2134
|
+
line3.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
2135
|
+
//Set the placement.
|
|
2136
|
+
line3.setPlacement(PlacementType.FreeFloating);
|
|
2137
|
+
//Make the gridlines invisible in the first worksheet.
|
|
2138
|
+
workbook.getWorksheets().get(0).setIsGridlinesVisible(false);
|
|
2139
|
+
//Save the excel file.
|
|
2140
|
+
workbook.save("output/DrawingLineShape.xls");
|
|
2141
|
+
}
|
|
2142
|
+
sampleDrawingLineShape();
|
|
2143
|
+
|
|
2144
|
+
function sampleDrawingGroupBox() {
|
|
2145
|
+
const { Workbook, PlacementType, FillType, Color, MsoLineDashStyle, MsoLineStyle } = require("aspose.cells.node");
|
|
2146
|
+
|
|
2147
|
+
//Instantiate a new Workbook.
|
|
2148
|
+
var excelbook = new Workbook();
|
|
2149
|
+
//Add a group box to the first worksheet.
|
|
2150
|
+
var box = excelbook.getWorksheets().get(0).getShapes().addGroupBox(1, 0, 1, 0, 300, 250);
|
|
2151
|
+
//Set the caption of the group box.
|
|
2152
|
+
box.setText("Age Groups");
|
|
2153
|
+
box.setPlacement(PlacementType.FreeFloating);
|
|
2154
|
+
//Make it 2-D box.
|
|
2155
|
+
box.setShadow(false);
|
|
2156
|
+
//Add a radio button.
|
|
2157
|
+
var radio1 = excelbook.getWorksheets().get(0).getShapes().addRadioButton(3, 0, 2, 0, 30, 110);
|
|
2158
|
+
//Set its text string.
|
|
2159
|
+
radio1.setText("20-29");
|
|
2160
|
+
//Set A1 cell as a linked cell for the radio button.
|
|
2161
|
+
radio1.setLinkedCell("A1");
|
|
2162
|
+
//Make the radio button 3-D.
|
|
2163
|
+
radio1.setShadow(true);
|
|
2164
|
+
//Set the foreground color of the radio button.
|
|
2165
|
+
radio1.getFill().setFillType(FillType.Solid);
|
|
2166
|
+
radio1.getFill().getSolidFill().setColor(Color.LightGreen);
|
|
2167
|
+
//Set the line style of the radio button.
|
|
2168
|
+
radio1.getLine().setCompoundType(MsoLineStyle.ThickThin);
|
|
2169
|
+
//Set the weight of the radio button.
|
|
2170
|
+
radio1.getLine().setWeight(4);
|
|
2171
|
+
//Set the line color of the radio button.
|
|
2172
|
+
radio1.getLine().setFillType(FillType.Solid);
|
|
2173
|
+
radio1.getLine().getSolidFill().setColor(Color.Blue);
|
|
2174
|
+
//Set the dash style of the radio button.
|
|
2175
|
+
radio1.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
2176
|
+
//Add another radio button.
|
|
2177
|
+
var radio2 = excelbook.getWorksheets().get(0).getShapes().addRadioButton(6, 0, 2, 0, 30, 110);
|
|
2178
|
+
//Set its text string.
|
|
2179
|
+
radio2.setText("30-39");
|
|
2180
|
+
//Set A1 cell as a linked cell for the radio button.
|
|
2181
|
+
radio2.setLinkedCell("A1");
|
|
2182
|
+
//Make the radio button 3-D.
|
|
2183
|
+
radio2.setShadow(true);
|
|
2184
|
+
//Set the foreground color of the radio button.
|
|
2185
|
+
radio2.getFill().setFillType(FillType.Solid);
|
|
2186
|
+
radio2.getFill().getSolidFill().setColor(Color.LightGreen);
|
|
2187
|
+
//Set the line style of the radio button.
|
|
2188
|
+
radio2.getLine().setCompoundType(MsoLineStyle.ThickThin);
|
|
2189
|
+
//Set the weight of the radio button.
|
|
2190
|
+
radio2.getLine().setWeight(4);
|
|
2191
|
+
//Set the line color of the radio button.
|
|
2192
|
+
radio2.getLine().setFillType(FillType.Solid);
|
|
2193
|
+
radio2.getLine().getSolidFill().setColor(Color.Blue);
|
|
2194
|
+
//Set the dash style of the radio button.
|
|
2195
|
+
radio2.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
2196
|
+
//Add another radio button.
|
|
2197
|
+
var radio3 = excelbook.getWorksheets().get(0).getShapes().addRadioButton(9, 0, 2, 0, 30, 110);
|
|
2198
|
+
//Set its text string.
|
|
2199
|
+
radio3.setText("40-49");
|
|
2200
|
+
//Set A1 cell as a linked cell for the radio button.
|
|
2201
|
+
radio3.setLinkedCell("A1");
|
|
2202
|
+
//Make the radio button 3-D.
|
|
2203
|
+
radio3.setShadow(true);
|
|
2204
|
+
//Set the foreground color of the radio button.
|
|
2205
|
+
radio3.getFill().setFillType(FillType.Solid);
|
|
2206
|
+
radio3.getFill().getSolidFill().setColor(Color.LightGreen);
|
|
2207
|
+
//Set the line style of the radio button.
|
|
2208
|
+
radio3.getLine().setCompoundType(MsoLineStyle.ThickThin);
|
|
2209
|
+
//Set the weight of the radio button.
|
|
2210
|
+
radio3.getLine().setWeight(4);
|
|
2211
|
+
//Set the line color of the radio button.
|
|
2212
|
+
radio3.getLine().setFillType(FillType.Solid);
|
|
2213
|
+
radio3.getLine().getSolidFill().setColor(Color.Blue);
|
|
2214
|
+
//Set the dash style of the radio button.
|
|
2215
|
+
radio3.getLine().setDashStyle(MsoLineDashStyle.Solid);
|
|
2216
|
+
//Get the shapes.
|
|
2217
|
+
var shapeobjects = [ box, radio1, radio2, radio3 ];
|
|
2218
|
+
//Group the shapes.
|
|
2219
|
+
var group = excelbook.getWorksheets().get(0).getShapes().group(shapeobjects);
|
|
2220
|
+
|
|
2221
|
+
//Save the excel file.
|
|
2222
|
+
excelbook.save("output/DrawingGroupBox.xls");
|
|
2223
|
+
}
|
|
2224
|
+
sampleDrawingGroupBox();
|
|
2225
|
+
|
|
2226
|
+
function sampleFont() {
|
|
2227
|
+
const { Workbook, Color } = require("aspose.cells.node");
|
|
2228
|
+
|
|
2229
|
+
//Instantiating a Workbook object
|
|
2230
|
+
var workbook = new Workbook();
|
|
2231
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
2232
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2233
|
+
//Accessing the "A1" cell from the worksheet
|
|
2234
|
+
var cell = worksheet.getCells().get("A1");
|
|
2235
|
+
//Adding some value to the "A1" cell
|
|
2236
|
+
cell.putValue("Hello Aspose!");
|
|
2237
|
+
var style = cell.getStyle();
|
|
2238
|
+
var font = style.getFont();
|
|
2239
|
+
//Setting the font name to "Times New Roman"
|
|
2240
|
+
font.setName("Times New Roman");
|
|
2241
|
+
//Setting font size to 14
|
|
2242
|
+
font.setSize(14);
|
|
2243
|
+
//setting font color as Red
|
|
2244
|
+
font.setColor(Color.Red);
|
|
2245
|
+
cell.setStyle(style);
|
|
2246
|
+
//Saving the Excel file
|
|
2247
|
+
workbook.save("output/Font.xls");
|
|
2248
|
+
}
|
|
2249
|
+
sampleFont();
|
|
2250
|
+
|
|
2251
|
+
function sampleFontName() {
|
|
2252
|
+
const { Workbook } = require("aspose.cells.node");
|
|
2253
|
+
|
|
2254
|
+
var workbook = new Workbook();
|
|
2255
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
2256
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2257
|
+
//Accessing the "A1" cell from the worksheet
|
|
2258
|
+
var cell = worksheet.getCells().get("A1");
|
|
2259
|
+
//Adding some value to the "A1" cell
|
|
2260
|
+
cell.putValue("Hello Aspose!");
|
|
2261
|
+
var style = cell.getStyle();
|
|
2262
|
+
var font = style.getFont();
|
|
2263
|
+
font.setName("Times New Roman");
|
|
2264
|
+
cell.setStyle(style);
|
|
2265
|
+
}
|
|
2266
|
+
sampleFontName();
|
|
2267
|
+
|
|
2268
|
+
function sampleConditionalFormattingCollection() {
|
|
2269
|
+
const { Workbook, CellArea, FormatConditionType, OperatorType, Color } = require("aspose.cells.node");
|
|
2270
|
+
|
|
2271
|
+
//Instantiating a Workbook object
|
|
2272
|
+
var workbook = new Workbook();
|
|
2273
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
2274
|
+
//Get Conditional Formattings
|
|
2275
|
+
var cformattings = sheet.getConditionalFormattings();
|
|
2276
|
+
//Adds an empty conditional formatting
|
|
2277
|
+
var index = cformattings.add();
|
|
2278
|
+
//Get newly added Conditional formatting
|
|
2279
|
+
var fcs = cformattings.get(index);
|
|
2280
|
+
//Sets the conditional format range.
|
|
2281
|
+
var ca = new CellArea();
|
|
2282
|
+
ca.startRow = 0;
|
|
2283
|
+
ca.endRow = 0;
|
|
2284
|
+
ca.startColumn = 0;
|
|
2285
|
+
ca.endColumn = 0;
|
|
2286
|
+
fcs.addArea(ca);
|
|
2287
|
+
ca = new CellArea();
|
|
2288
|
+
ca.startRow = 1;
|
|
2289
|
+
ca.endRow = 1;
|
|
2290
|
+
ca.startColumn = 1;
|
|
2291
|
+
ca.endColumn = 1;
|
|
2292
|
+
fcs.addArea(ca);
|
|
2293
|
+
//Add condition.
|
|
2294
|
+
var conditionIndex = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
|
|
2295
|
+
//Add condition.
|
|
2296
|
+
var conditionIndex2 = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
|
|
2297
|
+
//Sets the background color.
|
|
2298
|
+
var fc = fcs.get(conditionIndex);
|
|
2299
|
+
fc.getStyle().setBackgroundColor(Color.Red);
|
|
2300
|
+
//Saving the Excel file
|
|
2301
|
+
workbook.save("output/ConditionalFormattingCollection.xls");
|
|
2302
|
+
}
|
|
2303
|
+
sampleConditionalFormattingCollection();
|
|
2304
|
+
|
|
2305
|
+
function sampleDrawingComboBox() {
|
|
2306
|
+
const { Workbook } = require("aspose.cells.node");
|
|
2307
|
+
|
|
2308
|
+
//Create a new Workbook.
|
|
2309
|
+
var workbook = new Workbook();
|
|
2310
|
+
//Get the first worksheet.
|
|
2311
|
+
var sheet = workbook.getWorksheets().get(0);
|
|
2312
|
+
//Get the worksheet cells collection.
|
|
2313
|
+
var cells = sheet.getCells();
|
|
2314
|
+
//Input a value.
|
|
2315
|
+
cells.get("B3").putValue("Employee:");
|
|
2316
|
+
//Set it bold.
|
|
2317
|
+
cells.get("B3").getStyle().getFont().setIsBold(true);
|
|
2318
|
+
//Input some values that denote the input range
|
|
2319
|
+
//for the combo box.
|
|
2320
|
+
cells.get("A2").putValue("Emp001");
|
|
2321
|
+
cells.get("A3").putValue("Emp002");
|
|
2322
|
+
cells.get("A4").putValue("Emp003");
|
|
2323
|
+
cells.get("A5").putValue("Emp004");
|
|
2324
|
+
cells.get("A6").putValue("Emp005");
|
|
2325
|
+
cells.get("A7").putValue("Emp006");
|
|
2326
|
+
|
|
2327
|
+
//Add a new combo box.
|
|
2328
|
+
var comboBox = sheet.getShapes().addComboBox(2, 0, 2, 0, 22, 100);
|
|
2329
|
+
//Set the linked cell;
|
|
2330
|
+
comboBox.setLinkedCell("A1");
|
|
2331
|
+
//Set the input range.
|
|
2332
|
+
comboBox.setInputRange("A2:A7");
|
|
2333
|
+
//Set no. of list lines displayed in the combo
|
|
2334
|
+
//box's list portion.
|
|
2335
|
+
comboBox.setDropDownLines(5);
|
|
2336
|
+
//Set the combo box with 3-D shading.
|
|
2337
|
+
comboBox.setShadow(true);
|
|
2338
|
+
//AutoFit Columns
|
|
2339
|
+
sheet.autoFitColumns();
|
|
2340
|
+
//Saves the file.
|
|
2341
|
+
workbook.save("output/DrawingComboBox.xls");
|
|
2342
|
+
}
|
|
2343
|
+
sampleDrawingComboBox();
|
|
2344
|
+
|
|
2345
|
+
function sampleColumnCollection() {
|
|
2346
|
+
const { Workbook, Color, BackgroundType, StyleFlag } = require("aspose.cells.node");
|
|
2347
|
+
|
|
2348
|
+
//Instantiating a Workbook object
|
|
2349
|
+
var workbook = new Workbook();
|
|
2350
|
+
//Obtaining the reference of the first worksheet
|
|
2351
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2352
|
+
//Add new Style to Workbook
|
|
2353
|
+
var style = workbook.createStyle();
|
|
2354
|
+
//Setting the background color to Blue
|
|
2355
|
+
style.setForegroundColor(Color.Blue);
|
|
2356
|
+
//setting Background Pattern
|
|
2357
|
+
style.setPattern(BackgroundType.Solid);
|
|
2358
|
+
//New Style Flag
|
|
2359
|
+
var styleFlag = new StyleFlag();
|
|
2360
|
+
//Set All Styles
|
|
2361
|
+
styleFlag.setAll(true);
|
|
2362
|
+
|
|
2363
|
+
//Change the default width of first ten columns
|
|
2364
|
+
for (var i = 0; i < 10; i++) {
|
|
2365
|
+
worksheet.getCells().getColumns().get(i).setWidth(20);
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
//Get the Column with non default formatting
|
|
2369
|
+
var columns = worksheet.getCells().getColumns();
|
|
2370
|
+
var count = columns.getCount();
|
|
2371
|
+
for (var i = 0; i < count; i++) {
|
|
2372
|
+
var column = columns.getColumnByIndex(i);
|
|
2373
|
+
//Apply Style to first ten Columns
|
|
2374
|
+
column.applyStyle(style, styleFlag);
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
//Saving the Excel file
|
|
2378
|
+
workbook.save("output/ColumnCollection.xls");
|
|
2379
|
+
}
|
|
2380
|
+
sampleColumnCollection();
|
|
2381
|
+
|
|
2382
|
+
function sampleFindOptions() {
|
|
2383
|
+
const { Workbook, FindOptions, CellArea, LookInType } = require("aspose.cells.node");
|
|
2384
|
+
|
|
2385
|
+
//Instantiate the workbook object
|
|
2386
|
+
var workbook = new Workbook("input/Book1.xls");
|
|
2387
|
+
//Get Cells collection
|
|
2388
|
+
var cells = workbook.getWorksheets().get(0).getCells();
|
|
2389
|
+
//Instantiate FindOptions Object
|
|
2390
|
+
var findOptions = new FindOptions();
|
|
2391
|
+
//Create a Cells Area
|
|
2392
|
+
var ca = new CellArea();
|
|
2393
|
+
ca.startRow = 8;
|
|
2394
|
+
ca.startColumn = 2;
|
|
2395
|
+
ca.endRow = 17;
|
|
2396
|
+
ca.endColumn = 13;
|
|
2397
|
+
|
|
2398
|
+
//Set cells area for find options
|
|
2399
|
+
findOptions.setRange(ca);
|
|
2400
|
+
//Set searching properties
|
|
2401
|
+
findOptions.setSearchBackward(false);
|
|
2402
|
+
findOptions.setSearchOrderByRows(true);
|
|
2403
|
+
findOptions.setLookInType(LookInType.Values);
|
|
2404
|
+
//Find the cell with 0 value
|
|
2405
|
+
var cell = cells.find(0, null, findOptions);
|
|
2406
|
+
}
|
|
2407
|
+
sampleFindOptions();
|
|
2408
|
+
|
|
2409
|
+
function sampleChartsSeries() {
|
|
2410
|
+
const { Workbook, ChartType, ChartMarkerType, FormattingType, Color } = require("aspose.cells.node");
|
|
2411
|
+
|
|
2412
|
+
//Instantiating a Workbook object
|
|
2413
|
+
var workbook = new Workbook();
|
|
2414
|
+
//Adding a new worksheet to the Excel object
|
|
2415
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
2416
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
2417
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
2418
|
+
//Adding a sample value to "A1" cell
|
|
2419
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
2420
|
+
//Adding a sample value to "A2" cell
|
|
2421
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
2422
|
+
//Adding a sample value to "A3" cell
|
|
2423
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
2424
|
+
//Adding a sample value to "A4" cell
|
|
2425
|
+
worksheet.getCells().get("A4").putValue(200);
|
|
2426
|
+
//Adding a sample value to "B1" cell
|
|
2427
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
2428
|
+
//Adding a sample value to "B2" cell
|
|
2429
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
2430
|
+
//Adding a sample value to "B3" cell
|
|
2431
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
2432
|
+
//Adding a sample value to "B4" cell
|
|
2433
|
+
worksheet.getCells().get("B4").putValue(40);
|
|
2434
|
+
//Adding a sample value to "C1" cell as category data
|
|
2435
|
+
worksheet.getCells().get("C1").putValue("Q1");
|
|
2436
|
+
//Adding a sample value to "C2" cell as category data
|
|
2437
|
+
worksheet.getCells().get("C2").putValue("Q2");
|
|
2438
|
+
//Adding a sample value to "C3" cell as category data
|
|
2439
|
+
worksheet.getCells().get("C3").putValue("Y1");
|
|
2440
|
+
//Adding a sample value to "C4" cell as category data
|
|
2441
|
+
worksheet.getCells().get("C4").putValue("Y2");
|
|
2442
|
+
//Adding a chart to the worksheet
|
|
2443
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
2444
|
+
//Accessing the instance of the newly added chart
|
|
2445
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
2446
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
|
|
2447
|
+
chart.getNSeries().add("A1:B4", true);
|
|
2448
|
+
//Setting the data source for the category data of NSeries
|
|
2449
|
+
chart.getNSeries().setCategoryData("C1:C4");
|
|
2450
|
+
var series = chart.getNSeries().get(1);
|
|
2451
|
+
//Setting the values of the series.
|
|
2452
|
+
series.setValues("=B1:B4");
|
|
2453
|
+
//Changing the chart type of the series.
|
|
2454
|
+
series.setType(ChartType.Line);
|
|
2455
|
+
//Setting marker properties.
|
|
2456
|
+
series.getMarker().setMarkerStyle(ChartMarkerType.Circle);
|
|
2457
|
+
series.getMarker().setForegroundColorSetType(FormattingType.Automatic);
|
|
2458
|
+
series.getMarker().setForegroundColor(Color.Black);
|
|
2459
|
+
series.getMarker().setBackgroundColorSetType(FormattingType.Automatic);
|
|
2460
|
+
//Saving the Excel file
|
|
2461
|
+
workbook.save("output/ChartsSeries.xls");
|
|
2462
|
+
}
|
|
2463
|
+
sampleChartsSeries();
|
|
2464
|
+
|
|
2465
|
+
function sampleChartsSeriesName() {
|
|
2466
|
+
const { Workbook, ChartType } = require("aspose.cells.node");
|
|
2467
|
+
|
|
2468
|
+
var workbook = new Workbook();
|
|
2469
|
+
//Get the first worksheet.
|
|
2470
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2471
|
+
//Adding a chart to the worksheet
|
|
2472
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
2473
|
+
//Accessing the instance of the newly added chart
|
|
2474
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
2475
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
|
|
2476
|
+
chart.getNSeries().add("A1:B4", true);
|
|
2477
|
+
//Reference name to a cell
|
|
2478
|
+
chart.getNSeries().get(0).setName("=A1");
|
|
2479
|
+
//Set a string to name
|
|
2480
|
+
chart.getNSeries().get(0).setName("First Series");
|
|
2481
|
+
}
|
|
2482
|
+
sampleChartsSeriesName();
|
|
2483
|
+
|
|
2484
|
+
function sampleChartsTrendlineCollection() {
|
|
2485
|
+
const { Workbook, ChartType, TrendlineType, Color } = require("aspose.cells.node");
|
|
2486
|
+
|
|
2487
|
+
var excel = new Workbook();
|
|
2488
|
+
var chartIndex = excel.getWorksheets().get(0).getCharts().add(ChartType.Column, 3, 3, 15, 10);
|
|
2489
|
+
var chart = excel.getWorksheets().get(0).getCharts().get(chartIndex);
|
|
2490
|
+
chart.getNSeries().add("A1:a3", true);
|
|
2491
|
+
chart.getNSeries().get(0).getTrendLines().add(TrendlineType.Linear, "MyTrendLine");
|
|
2492
|
+
var line = chart.getNSeries().get(0).getTrendLines().get(0);
|
|
2493
|
+
line.setDisplayEquation(true);
|
|
2494
|
+
line.setDisplayRSquared(true);
|
|
2495
|
+
line.setColor(Color.Red);
|
|
2496
|
+
}
|
|
2497
|
+
sampleChartsTrendlineCollection();
|
|
2498
|
+
|
|
2499
|
+
function sampleChartsTrendline() {
|
|
2500
|
+
const { Workbook, ChartType, TrendlineType } = require("aspose.cells.node");
|
|
2501
|
+
|
|
2502
|
+
//Instantiating a Workbook object
|
|
2503
|
+
var workbook = new Workbook();
|
|
2504
|
+
//Adding a new worksheet to the Excel object
|
|
2505
|
+
var sheetIndex = workbook.getWorksheets().add();
|
|
2506
|
+
//Obtaining the reference of the newly added worksheet by passing its sheet index
|
|
2507
|
+
var worksheet = workbook.getWorksheets().get(sheetIndex);
|
|
2508
|
+
//Adding a sample value to "A1" cell
|
|
2509
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
2510
|
+
//Adding a sample value to "A2" cell
|
|
2511
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
2512
|
+
//Adding a sample value to "A3" cell
|
|
2513
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
2514
|
+
//Adding a sample value to "A4" cell
|
|
2515
|
+
worksheet.getCells().get("A4").putValue(200);
|
|
2516
|
+
//Adding a sample value to "B1" cell
|
|
2517
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
2518
|
+
//Adding a sample value to "B2" cell
|
|
2519
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
2520
|
+
//Adding a sample value to "B3" cell
|
|
2521
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
2522
|
+
//Adding a sample value to "B4" cell
|
|
2523
|
+
worksheet.getCells().get("B4").putValue(40);
|
|
2524
|
+
//Adding a sample value to "C1" cell as category data
|
|
2525
|
+
worksheet.getCells().get("C1").putValue("Q1");
|
|
2526
|
+
//Adding a sample value to "C2" cell as category data
|
|
2527
|
+
worksheet.getCells().get("C2").putValue("Q2");
|
|
2528
|
+
//Adding a sample value to "C3" cell as category data
|
|
2529
|
+
worksheet.getCells().get("C3").putValue("Y1");
|
|
2530
|
+
//Adding a sample value to "C4" cell as category data
|
|
2531
|
+
worksheet.getCells().get("C4").putValue("Y2");
|
|
2532
|
+
//Adding a chart to the worksheet
|
|
2533
|
+
var chartIndex = worksheet.getCharts().add(ChartType.Column, 5, 0, 15, 5);
|
|
2534
|
+
//Accessing the instance of the newly added chart
|
|
2535
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
2536
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
|
|
2537
|
+
chart.getNSeries().add("A1:B4", true);
|
|
2538
|
+
//Setting the data source for the category data of NSeries
|
|
2539
|
+
chart.getNSeries().setCategoryData("C1:C4");
|
|
2540
|
+
//adding a linear trendline
|
|
2541
|
+
var index = chart.getNSeries().get(0).getTrendLines().add(TrendlineType.Linear);
|
|
2542
|
+
var trendline = chart.getNSeries().get(0).getTrendLines().get(index);
|
|
2543
|
+
//Setting the custom name of the trendline.
|
|
2544
|
+
trendline.setName("Linear");
|
|
2545
|
+
//Displaying the equation on chart
|
|
2546
|
+
trendline.setDisplayEquation(true);
|
|
2547
|
+
//Displaying the R-Squared value on chart
|
|
2548
|
+
trendline.setDisplayRSquared(true);
|
|
2549
|
+
//Saving the Excel file
|
|
2550
|
+
workbook.save("output/ChartsTrendline.xls");
|
|
2551
|
+
}
|
|
2552
|
+
sampleChartsTrendline();
|
|
2553
|
+
|
|
2554
|
+
function sampleCommentCollection() {
|
|
2555
|
+
const { Workbook } = require("aspose.cells.node");
|
|
2556
|
+
|
|
2557
|
+
var excel = new Workbook();
|
|
2558
|
+
var index = excel.getWorksheets().get(0).getCheckBoxes().add(15, 15, 20, 100);
|
|
2559
|
+
var checkBox = excel.getWorksheets().get(0).getCheckBoxes().get(index);
|
|
2560
|
+
checkBox.setText("Check Box 1");
|
|
2561
|
+
}
|
|
2562
|
+
sampleCommentCollection();
|
|
2563
|
+
|
|
2564
|
+
function sampleAutoFilter() {
|
|
2565
|
+
const { Workbook } = require("aspose.cells.node");
|
|
2566
|
+
|
|
2567
|
+
//Instantiating a Workbook object
|
|
2568
|
+
var workbook = new Workbook("input/AutoFilter.xlsx");
|
|
2569
|
+
//Accessing the first worksheet in the Excel file
|
|
2570
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2571
|
+
//Creating AutoFilter by giving the cells range of the heading row
|
|
2572
|
+
worksheet.getAutoFilter().setRange("A1:C1");
|
|
2573
|
+
//Filtering columns with specified values
|
|
2574
|
+
worksheet.getAutoFilter().filter(2, "present");
|
|
2575
|
+
// Refreshing auto filters to hide or unhide the rows.
|
|
2576
|
+
worksheet.getAutoFilter().refresh();
|
|
2577
|
+
//Saving the modified Excel file.
|
|
2578
|
+
workbook.save("output/AutoFilter.xlsx");
|
|
2579
|
+
}
|
|
2580
|
+
sampleAutoFilter();
|
|
2581
|
+
|
|
2582
|
+
function samplePropertiesDocumentProperty() {
|
|
2583
|
+
const { Workbook } = require("aspose.cells.node");
|
|
2584
|
+
|
|
2585
|
+
//Instantiate a Workbook object
|
|
2586
|
+
var workbook = new Workbook("input/CustomProperties.xlsx");
|
|
2587
|
+
//Retrieve a list of all custom document properties of the Excel file
|
|
2588
|
+
var customProperties = workbook.getWorksheets().getCustomDocumentProperties();
|
|
2589
|
+
//Accessng a custom document property by using the property index
|
|
2590
|
+
var customProperty1 = customProperties.get(3);
|
|
2591
|
+
//Accessng a custom document property by using the property name
|
|
2592
|
+
var customProperty2 = customProperties.get("Owner");
|
|
2593
|
+
}
|
|
2594
|
+
samplePropertiesDocumentProperty();
|
|
2595
|
+
|
|
2596
|
+
function sampleChartsChartCollection() {
|
|
2597
|
+
const { Workbook } = require("aspose.cells.node");
|
|
2598
|
+
|
|
2599
|
+
var workbook = new Workbook();
|
|
2600
|
+
var charts = workbook.getWorksheets().get(0).getCharts();
|
|
2601
|
+
}
|
|
2602
|
+
sampleChartsChartCollection();
|
|
2603
|
+
|
|
2604
|
+
function sampleChartsChartPointCollection() {
|
|
2605
|
+
const { Workbook, ChartType, Color } = require("aspose.cells.node");
|
|
2606
|
+
|
|
2607
|
+
//Instantiating a Workbook object
|
|
2608
|
+
var workbook = new Workbook();
|
|
2609
|
+
//Obtaining the reference of the first worksheet
|
|
2610
|
+
var worksheet = workbook.getWorksheets().get(0);
|
|
2611
|
+
//Adding a sample value to "A1" cell
|
|
2612
|
+
worksheet.getCells().get("A1").putValue(50);
|
|
2613
|
+
//Adding a sample value to "A2" cell
|
|
2614
|
+
worksheet.getCells().get("A2").putValue(100);
|
|
2615
|
+
//Adding a sample value to "A3" cell
|
|
2616
|
+
worksheet.getCells().get("A3").putValue(150);
|
|
2617
|
+
//Adding a sample value to "B1" cell
|
|
2618
|
+
worksheet.getCells().get("B1").putValue(60);
|
|
2619
|
+
//Adding a sample value to "B2" cell
|
|
2620
|
+
worksheet.getCells().get("B2").putValue(32);
|
|
2621
|
+
//Adding a sample value to "B3" cell
|
|
2622
|
+
worksheet.getCells().get("B3").putValue(50);
|
|
2623
|
+
//Adding a chart to the worksheet
|
|
2624
|
+
var chartIndex = worksheet.getCharts().add(ChartType.PieExploded, 5, 0, 25, 10);
|
|
2625
|
+
//Accessing the instance of the newly added chart
|
|
2626
|
+
var chart = worksheet.getCharts().get(chartIndex);
|
|
2627
|
+
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
|
|
2628
|
+
chart.getNSeries().add("A1:B3", true);
|
|
2629
|
+
//Show Data Labels
|
|
2630
|
+
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
|
|
2631
|
+
var points = chart.getNSeries().get(0).getPoints();
|
|
2632
|
+
var red = Color.Red;
|
|
2633
|
+
for (var i = 0; i < points.getCount(); i++) {
|
|
2634
|
+
//Get Data Point
|
|
2635
|
+
var point = points.get(i);
|
|
2636
|
+
//Set Pir Explosion
|
|
2637
|
+
point.setExplosion(15);
|
|
2638
|
+
//Set Border Color
|
|
2639
|
+
point.getBorder().setColor(red);
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
//Saving the Excel file
|
|
2643
|
+
workbook.save("output/ChartsChartPointCollection.xls");
|
|
2644
|
+
}
|
|
2645
|
+
sampleChartsChartPointCollection();
|