UNPKG

aspose.cells.node.samples

Version:

This is the sample code using aspose.cells.node library.

1,364 lines (1,180 loc) 99.7 kB
function sampleStyle() { //First method const { Workbook, Color } = require("aspose.cells.node"); var excel = new Workbook(); var style = excel.createStyle(); style.font.setName("Times New Roman"); style.font.setColor(Color.Blue); for (var i = 0; i < 100; i++) { excel.worksheets.get(0).cells.get(0, i).setStyle(style); } //Second method var style1 = excel.worksheets.get(0).cells.get("A1").getStyle(); style1.font.setName("Times New Roman"); style1.font.color = Color.Blue; excel.worksheets.get(0).cells.get("A1").setStyle(style1); //First method is a fast and efficient way to change several cell-formatting properties on multiple cells at the same time. //If you want to change a single cell's style properties, second method can be used. } sampleStyle(); function sampleChartTitle() { const { Workbook, Color, ChartType } = require("aspose.cells.node"); var excel = new Workbook(); var charts = excel.worksheets.get(0).charts; //Create a chart var chart = charts.get(charts.add(ChartType.Column, 1, 1, 10, 10)); //Setting the title of a chart chart.title.text = "Title"; //Setting the font color of the chart title to blue chart.title.getFont().color = Color.Blue; //Setting the title of category axis of the chart chart.categoryAxis.title.text = "Category"; //Setting the title of value axis of the chart chart.valueAxis.title.text = "Value"; } sampleChartTitle(); function sampleTablesListObject() { const { Workbook, CellsHelper, TotalsCalculation } = require("aspose.cells.node"); var workbook = new Workbook(); var cells = workbook.worksheets.get(0).cells; for (var i = 0; i < 5; i++) { cells.get(0, i).putValue(CellsHelper.columnIndexToName(i)); } for (var row = 1; row < 10; row++) { for (var column = 0; column < 5; column++) { cells.get(row, column).putValue(row * column); } } var tables = workbook.worksheets.get(0).getListObjects(); var index = tables.add(0, 0, 9, 4, true); var table = tables.get(0); table.showTotals = true; table.listColumns.get(4).totalsCalculation = TotalsCalculation.Sum; workbook.save("output/Book1.xlsx"); } sampleTablesListObject(); function sampleDrawingFormat() { const { Workbook, ChartType, Color, GradientStyleType } = require("aspose.cells.node"); var excel = new Workbook(); var charts = excel.worksheets.get(0).charts; //Create a chart var chart = charts.get(charts.add(ChartType.Column, 1, 1, 10, 10)); chart.nSeries.add("A1:C5", true); //Filling the area of the 2nd NSeries with a gradient chart.nSeries.get(1).area.fillFormat.setOneColorGradient(Color.Lime, 1, GradientStyleType.Horizontal, 1); } sampleDrawingFormat(); function samplePropertiesCustomDocumentPropertyCollection() { const { Workbook } = require("aspose.cells.node"); //Instantiate a Workbook object var workbook = new Workbook("input/CustomProperties.xlsx"); //Retrieve a list of all custom document properties of the Excel file var customProperties = workbook.worksheets.customDocumentProperties; } samplePropertiesCustomDocumentPropertyCollection(); function samplePropertyDocumentPropertyCollection() { const { Workbook } = require("aspose.cells.node"); //Instantiate a Workbook object by calling its empty constructor var workbook = new Workbook("input/CustomProperties.xlsx"); //Retrieve a list of all custom document properties of the Excel file var customProperties = workbook.worksheets.customDocumentProperties; //Accessng a custom document property by using the property index var customProperty1 = customProperties.get(3); //Accessng a custom document property by using the property name var customProperty2 = customProperties.get("rox_Meta1"); console.log("Custom Properties: " + customProperties.count); } samplePropertyDocumentPropertyCollection(); function sampleDrawingPicture() { const { Workbook, SaveFormat } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Workbook object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a picture at the location of a cell whose row and column indices //are 5 in the worksheet. It is "F6" cell worksheet.pictures.add(5, 5, "input/image.gif"); //Saving the Excel file workbook.save("output/Book1.xls", SaveFormat.Excel97To2003); } sampleDrawingPicture(); function sampleHorizontalPageBreak() { const { Workbook } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(0); //Add a page break at cell Y30 var Index = worksheet.horizontalPageBreaks.add("Y30"); //get the newly added horizontal page break var hPageBreak = worksheet.horizontalPageBreaks.get(Index); } sampleHorizontalPageBreak(); function sampleChartsFloor() { const { License, Workbook, ChartType, Color, GradientPresetType, GradientStyleType } = require("aspose.cells.node"); //Instantiate the License class var license = new License(); license.setLicense("input/Aspose.Cells.lic"); //Instantiate the workbook object var workbook = new Workbook(); //Get cells collection var cells = workbook.worksheets.get(0).cells; //Put values in cells cells.get("A1").putValue(1); cells.get("A2").putValue(2); cells.get("A3").putValue(3); //get charts colletion var charts = workbook.worksheets.get(0).charts; //add a new chart var index = charts.add(ChartType.Column3DStacked, 5, 0, 15, 5); //get the newly added chart var chart = charts.get(index); //set charts nseries chart.nSeries.add("A1:A3", true); //Show data labels chart.nSeries.get(0).dataLabels.showValue = true; //Get chart's floor var floor = chart.floor; //set floor's border as red floor.border.color = new Color("red"); //set fill format floor.fillFormat.setPresetColorGradient(GradientPresetType.CalmWater, GradientStyleType.DiagonalDown, 2); //save the file workbook.save("output/ChartsFloor.xls"); } sampleChartsFloor(); function sampleDrawingArea() { const { Workbook, ChartType, Color } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Workbook object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a sample value to "B1" cell worksheet.cells.get("B1").putValue(60); //Adding a sample value to "B2" cell worksheet.cells.get("B2").putValue(32); //Adding a sample value to "B3" cell worksheet.cells.get("B3").putValue(50); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3" chart.nSeries.add("A1:B3", true); //Setting the foreground color of the plot area chart.plotArea.getArea().foregroundColor = Color.Blue; //Setting the foreground color of the chart area chart.chartArea.getArea().foregroundColor = Color.Yellow; //Setting the foreground color of the 1st NSeries area chart.nSeries.get(0).area.foregroundColor = Color.Red; //Setting the foreground color of the area of the 1st NSeries point chart.nSeries.get(0).points.get(0).area.foregroundColor = Color.Cyan; //Saving the Excel file workbook.save("output/DrawingArea.xls"); } sampleDrawingArea(); function sampleDrawingAreaInverseIfNegative() { const { Workbook, ChartType, Color } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Workbook object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(-100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "A3" chart.nSeries.add("A1:A3", true); chart.nSeries.get(0).area.invertIfNegative = true; //Setting the foreground color of the 1st NSeries area chart.nSeries.get(0).area.foregroundColor = Color.Red; //Setting the background color of the 1st NSeries area. //The displayed area color of second chart point will be the background color. chart.nSeries.get(0).area.backgroundColor = Color.Yellow; //Saving the Excel file workbook.save("output/DrawingAreaInverseIfNegative.xls"); } sampleDrawingAreaInverseIfNegative(); function sampleExternlink() { const { Workbook } = require("aspose.cells.node"); //Open a file with external links var workbook = new Workbook("input/Externlink.xls"); //Get External Link var externalLink = workbook.worksheets.externalLinks.get(0); //Change External Link's Data Source externalLink.dataSource = "input/Book1.xls"; } sampleExternlink(); function sampleComment() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var comments = workbook.worksheets.get(0).comments; //Add comment to cell A1 var commentIndex = comments.add(0, 0); var comment = comments.get(commentIndex); comment.note = "First note."; comment.font.setName("Times New Roman"); //Add comment to cell B2 comments.add("B2"); comment = comments.get("B2"); comment.note = "Second note."; } sampleComment(); function sampleIconSet() { const { Workbook, CellArea, FormatConditionType, IconSetType } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); var sheet = workbook.worksheets.get(0); //Adds an empty conditional formatting var index = sheet.conditionalFormattings.add(); var fcs = sheet.conditionalFormattings.get(index); //Sets the conditional format range. var ca = new CellArea(); ca.startRow = 0; ca.endRow = 2; ca.startColumn = 0; ca.endColumn = 0; fcs.addArea(ca); //Adds condition. var idx = fcs.addCondition(FormatConditionType.IconSet); fcs.addArea(ca); var cond = fcs.get(idx); //Get Icon Set var iconSet = cond.iconSet; //Set Icon Type iconSet.type = IconSetType.Arrows3; //Put Cell Values var cell1 = sheet.cells.get("A1"); cell1.putValue(10); var cell2 = sheet.cells.get("A2"); cell2.putValue(120); var cell3 = sheet.cells.get("A3"); cell3.putValue(260); //Saving the Excel file workbook.save("output/IconSet.xlsx"); } sampleIconSet(); function samplePageSetup() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var sheet = workbook.worksheets.get(0); sheet.pageSetup.printArea = "D1:K13"; sheet.pageSetup.printTitleRows = "$5:$7"; sheet.pageSetup.printTitleColumns = "$A:$B"; } samplePageSetup(); function sampleDrawingOleObject() { const fs = require("fs"); const { Workbook } = require("aspose.cells.node"); //Instantiate a new Workbook. var workbook = new Workbook(); //Get the first worksheet. var sheet = workbook.worksheets.get(0); //Obtain the picture into the array of bytes from a stream. var imgBuf = new Uint8Array(fs.readFileSync("input/example.png")); //Add an Ole object into the worksheet with the bytes sheet.oleObjects.add(14, 3, 200, 220, imgBuf); //Set embedded ole object data from a stream. var fileBuf = new Uint8Array(fs.readFileSync("input/Book1.xls")); sheet.oleObjects.get(0).objectData = fileBuf; //Save the excel file workbook.save("output/DrawingOleObject.xls"); } sampleDrawingOleObject(); function sampleTextEffectFormat() { const { Workbook, MsoPresetTextEffect } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); var shapes = workbook.worksheets.get(0).shapes; shapes.addTextEffect(MsoPresetTextEffect.TextEffect1, "Aspose", "Arial", 30, false, false, 0, 0, 0, 0, 100, 200); var textEffectFormat = shapes.get(0).textEffect; textEffectFormat.setTextEffect(MsoPresetTextEffect.TextEffect10); workbook.save("output/TextEffectFormat.xls"); } sampleTextEffectFormat(); function sampleChartsErrorBar() { const { Workbook, ChartType, ErrorBarDisplayType, ErrorBarType } = require("aspose.cells.node"); var workbook = new Workbook(); var cells = workbook.worksheets.get(0).cells; cells.get("a1").putValue(2); cells.get("a2").putValue(5); cells.get("a3").putValue(3); cells.get("a4").putValue(6); cells.get("b1").putValue(4); cells.get("b2").putValue(3); cells.get("b3").putValue(6); cells.get("b4").putValue(7); cells.get("C1").putValue("Q1"); cells.get("C2").putValue("Q2"); cells.get("C3").putValue("Y1"); cells.get("C4").putValue("Y2"); var chartIndex = workbook.worksheets.get(0).charts.add(ChartType.Column, 11, 0, 27, 10); var chart = workbook.worksheets.get(0).charts.get(chartIndex); chart.nSeries.add("A1:B4", true); chart.nSeries.categoryData = "C1:C4"; for (var i = 0; i < chart.nSeries.count; i++) { var aseries = chart.nSeries.get(i); aseries.xErrorBar.displayType = ErrorBarDisplayType.Minus; aseries.xErrorBar.type = ErrorBarType.FixedValue; aseries.xErrorBar.amount = 5; } } sampleChartsErrorBar(); function sampleDrawingLine() { const { Workbook, ChartType, LineType, ChartMarkerType, WeightType } = require("aspose.cells.node"); var workbook = new Workbook(); var cells = workbook.worksheets.get(0).cells; cells.get("a1").putValue(2); cells.get("a2").putValue(5); cells.get("a3").putValue(3); cells.get("a4").putValue(6); cells.get("b1").putValue(4); cells.get("b2").putValue(3); cells.get("b3").putValue(6); cells.get("b4").putValue(7); var chartIndex = workbook.worksheets.get(0).charts.add(ChartType.Column, 11, 0, 27, 10); var chart = workbook.worksheets.get(0).charts.get(chartIndex); chart.nSeries.add("A1:B4", true); //Applying a dotted line style on the lines of an NSeries chart.nSeries.get(0).border.style = LineType.Dot; //Applying a triangular marker style on the data markers of an NSeries chart.nSeries.get(0).marker.markerStyle = ChartMarkerType.Triangle; //Setting the weight of all lines in an NSeries to medium chart.nSeries.get(0).border.weight = WeightType.MediumLine; } sampleDrawingLine(); function sampleChartsErrorBarType() { const { Workbook, ChartType, ErrorBarType } = require("aspose.cells.node"); var workbook = new Workbook(); var cells = workbook.worksheets.get(0).cells; cells.get("a1").putValue(2); cells.get("a2").putValue(5); cells.get("a3").putValue(3); cells.get("a4").putValue(6); cells.get("b1").putValue(4); cells.get("b2").putValue(3); cells.get("b3").putValue(6); cells.get("b4").putValue(7); cells.get("C1").putValue("Q1"); cells.get("C2").putValue("Q2"); cells.get("C3").putValue("Y1"); cells.get("C4").putValue("Y2"); var chartIndex = workbook.worksheets.get(0).charts.add(ChartType.Column, 11, 0, 27, 10); var chart = workbook.worksheets.get(0).charts.get(chartIndex); chart.nSeries.add("A1:B4", true); chart.nSeries.categoryData = "C1:C4"; for (var i = 0; i < chart.nSeries.count; i++) { var aseries = chart.nSeries.get(i); //Sets custom error bar type aseries.xErrorBar.type = ErrorBarType.Custom; aseries.xErrorBar.plusValue = "=Sheet1!A1"; aseries.xErrorBar.minusValue = "=Sheet1!A2"; } } sampleChartsErrorBarType(); function sampleDrawingButton() { const { Workbook, MsoDrawingType, Color, PlacementType } = require("aspose.cells.node"); //Create a new Workbook. var workbook = new Workbook(); //Get the first worksheet in the workbook. var sheet = workbook.worksheets.get(0); //Add a new button to the worksheet. var button = sheet.shapes.addShape(MsoDrawingType.Button, 2, 0, 2, 0, 28, 80); //Set the caption of the button. button.text = "Aspose"; //Set the Placement Type, the way the //button is attached to the cells. button.placement = PlacementType.FreeFloating; //Set the font name. button.font.setName("Tahoma"); //Set the caption string bold. button.font.isBold = true; //Set the color to blue. button.font.color = Color.Blue; //Set the hyperlink for the button. button.addHyperlink("http://www.aspose.com/"); //Saves the file. workbook.save("output/DrawingButton.xls"); } sampleDrawingButton(); function sampleValidation() { const { Workbook, ValidationType, CellArea } = require("aspose.cells.node"); var workbook = new Workbook(); var validations = workbook.worksheets.get(0).validations; var area = CellArea.createCellArea(0, 0, 1, 1); var validation = validations.get(validations.add(area)); validation.type = ValidationType.List; validation.formula1 = "a,b,c,d"; } sampleValidation(); function sampleChartsSeriesCollection() { const { Workbook, ChartType } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Excel object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a sample value to "A4" cell worksheet.cells.get("A4").putValue(200); //Adding a sample value to "B1" cell worksheet.cells.get("B1").putValue(60); //Adding a sample value to "B2" cell worksheet.cells.get("B2").putValue(32); //Adding a sample value to "B3" cell worksheet.cells.get("B3").putValue(50); //Adding a sample value to "B4" cell worksheet.cells.get("B4").putValue(40); //Adding a sample value to "C1" cell as category data worksheet.cells.get("C1").putValue("Q1"); //Adding a sample value to "C2" cell as category data worksheet.cells.get("C2").putValue("Q2"); //Adding a sample value to "C3" cell as category data worksheet.cells.get("C3").putValue("Y1"); //Adding a sample value to "C4" cell as category data worksheet.cells.get("C4").putValue("Y2"); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4" chart.nSeries.add("A1:B4", true); //Setting the data source for the category data of NSeries chart.nSeries.categoryData = "C1:C4"; //Saving the Excel file workbook.save("output/ChartsSeriesCollection.xls"); } sampleChartsSeriesCollection(); function sampleHyperlinkCollection() { const { Workbook } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(0); //Get Hyperlinks Collection var hyperlinks = worksheet.hyperlinks; //Adding a hyperlink to a URL at "A1" cell hyperlinks.add("A1", 1, 1, "https://www.aspose.com"); //Saving the Excel file workbook.save("output/HyperlinkCollection.xls"); } sampleHyperlinkCollection(); function sampleHyperlinkCollectionAddIntIntIntIntString() { const { Workbook } = require("aspose.cells.node"); var excel = new Workbook(); var worksheet = excel.worksheets.get(0); worksheet.hyperlinks.add("A4", 1, 1, "https://www.aspose.com"); worksheet.hyperlinks.add("A5", 1, 1, "c:\\book1.xls"); } sampleHyperlinkCollectionAddIntIntIntIntString(); function sampleDataSorter() { const { Workbook, CellArea, SortOrder } = require("aspose.cells.node"); //Instantiate a new Workbook object. var workbook = new Workbook("input/DataSorter.xls"); //Get the workbook datasorter object. var sorter = workbook.dataSorter; //Set the first order for datasorter object. sorter.order1 = SortOrder.Descending; //Define the first key. sorter.key1 = 0; //Create a cells area (range). var ca = new CellArea(); //Specify the start row index. ca.startRow = 0; //Specify the start column index. ca.startColumn = 0; //Specify the last row index. ca.endRow = 12; //Specify the last column index. ca.endColumn = 1; //Sort data in the specified data range (A1:B14) sorter.sort(workbook.worksheets.get(0).cells, ca); //Save the excel file. workbook.save("output/DataSorter.xls"); } sampleDataSorter(); function sampleColumn() { const { Workbook, Color, BackgroundType, StyleFlag } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Obtaining the reference of the first worksheet var worksheet = workbook.worksheets.get(0); //Add new Style to Workbook var style = workbook.createStyle(); //Setting the background color to Blue style.backgroundColor = Color.Blue; //Setting the foreground color to Red style.foregroundColor = Color.Red; //setting Background Pattern style.pattern = BackgroundType.DiagonalStripe; //New Style Flag var styleFlag = new StyleFlag(); //Set All Styles styleFlag.all = true; //Get first Column var column = worksheet.cells.columns.get(0); //Apply Style to first Column column.applyStyle(style, styleFlag); //Saving the Excel file workbook.save("output/Column.xls"); } sampleColumn(); function sampleCellArea() { const { CellArea } = require("aspose.cells.node"); //Create Cell Area var ca = new CellArea(); ca.startRow = 0; ca.endRow = 0; ca.startColumn = 0; ca.endColumn = 0; } sampleCellArea(); function sampleBorder() { const { Workbook, BorderType, CellBorderType, Color } = require("aspose.cells.node"); var workbook = new Workbook(); var worksheet = workbook.worksheets.get(0); var cell = worksheet.cells.get(0, 0); var style = workbook.createStyle(); //Set top border style and color var border = style.borders.get(BorderType.TopBorder); border.lineStyle = CellBorderType.Medium; border.color = Color.Red; cell.setStyle(style); } sampleBorder(); function sampleDataBar() { const { Workbook, CellArea, Color, FormatConditionType, FormatConditionValueType } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); var sheet = workbook.worksheets.get(0); //Adds an empty conditional formatting var index = sheet.conditionalFormattings.add(); var fcs = sheet.conditionalFormattings.get(index); //Sets the conditional format range. var ca = new CellArea(); ca.startRow = 0; ca.endRow = 2; ca.startColumn = 0; ca.endColumn = 0; fcs.addArea(ca); //Adds condition. var idx = fcs.addCondition(FormatConditionType.DataBar); fcs.addArea(ca); var cond = fcs.get(idx); //Get Databar var dataBar = cond.dataBar; var orange = Color.Orange; dataBar.color = orange; //Set Databar properties dataBar.minCfvo.type = FormatConditionValueType.Percentile; dataBar.minCfvo.value = 30; dataBar.showValue = false; //Put Cell Values var cell1 = sheet.cells.get("A1"); cell1.putValue(10); var cell2 = sheet.cells.get("A2"); cell2.putValue(120); var cell3 = sheet.cells.get("A3"); cell3.putValue(260); //Saving the Excel file workbook.save("output/DataBar.xlsx"); } sampleDataBar(); function sampleWorkbook() { const { Workbook, XlsSaveOptions } = require("aspose.cells.node"); //Open a xls file var workbook = new Workbook("input/Book1.xls"); //Set scroll bars workbook.settings.isHScrollBarVisible = false; workbook.settings.isVScrollBarVisible = false; //Replace the placeholder string with new values workbook.replace("OldInt", 100); var newString = "Hello world"; workbook.replace("OldString", newString); var saveOptions = new XlsSaveOptions(); workbook.save("output/result.xls", saveOptions); } sampleWorkbook(); function sampleWorkbookCtor() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); } sampleWorkbookCtor(); function sampleWorkbookCtorFileFormatType() { const { Workbook, FileFormatType } = require("aspose.cells.node"); var workbook = new Workbook(FileFormatType.Xlsx); } sampleWorkbookCtorFileFormatType(); function sampleWorkbookSaveFileFormatType() { const { Workbook, SaveFormat } = require("aspose.cells.node"); var workbook = new Workbook(); var sheets = workbook.worksheets; var cells = sheets.get(0).cells; cells.get("A1").putValue("Hello world!"); workbook.save("output/WorkbookSaveFileFormatType.xls", SaveFormat.Excel97To2003); } sampleWorkbookSaveFileFormatType(); function sampleWorkbookReplaceStringString() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); workbook.replace("AnOldValue", "NewValue"); } sampleWorkbookReplaceStringString(); function sampleWorkbookReplaceStringInt() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var newValue = 100; workbook.replace("AnOldValue", newValue); } sampleWorkbookReplaceStringInt(); function sampleWorkbookReplaceStringDouble() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var newValue = 100.0; workbook.replace("AnOldValue", newValue); } sampleWorkbookReplaceStringDouble(); function sampleWorkbookReplaceStringStringArrayBool() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook("input/Replace.xls"); var newValues = ["Tom", "Alice", "Jerry"]; workbook.replace("AnOldValue", newValues, true); workbook.save("output/ReplaceResult1.xls"); } sampleWorkbookReplaceStringStringArrayBool(); function sampleWorkbookReplaceStringIntArrayBool() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook("input/Replace.xls"); var newValues = [1, 2, 3]; workbook.replace("AnOldValue", newValues, true); workbook.save("output/ReplaceResult2.xls"); } sampleWorkbookReplaceStringIntArrayBool(); function sampleWorkbookReplaceStringDoubleArrayBool() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook("input/Replace.xls"); var newValues = [1.23, 2.56, 3.14159]; workbook.replace("AnOldValue", newValues, true); workbook.save("output/ReplaceResult3.xls"); } sampleWorkbookReplaceStringDoubleArrayBool(); function sampleWorkbookDefaultStyle() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var defaultStyle = workbook.defaultStyle; defaultStyle.font.setName("Tahoma"); workbook.defaultStyle = defaultStyle; } sampleWorkbookDefaultStyle(); function sampleWorkbookBuildInDocumentProperties() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var doc = workbook.builtInDocumentProperties.get("Author"); doc.value = "John Smith"; } sampleWorkbookBuildInDocumentProperties(); function sampleWorkbookCustomDocumentProperties() { const { Workbook } = require("aspose.cells.node"); var excel = new Workbook(); excel.customDocumentProperties.add("Checked by", "Jane"); } sampleWorkbookCustomDocumentProperties(); function sampleThemeColor() { const { Workbook, ThemeColor, ThemeColorType, BackgroundType } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); var cells = workbook.worksheets.get(0).cells; cells.get("A1").putValue("Hello World"); var style = cells.get("A1").getStyle(); //Set ThemeColorType.Text2 color type with 40% lighten as the font color. style.font.themeColor = new ThemeColor(ThemeColorType.Text2, 0.4); style.pattern = BackgroundType.Solid; //Set ThemeColorType.Background2 color type with 75% darken as the foreground color style.foregroundThemeColor = new ThemeColor(ThemeColorType.Background2, -0.75); cells.get("A1").setStyle(style); //Saving the Excel file workbook.save("output/ThemeColor.xlsx"); } sampleThemeColor(); function sampleDrawingTextBox() { const { Workbook, PlacementType, Color, MsoLineStyle, MsoLineDashStyle } = require("aspose.cells.node"); //Instantiate a new Workbook. var workbook = new Workbook(); //Get the first worksheet in the book. var worksheet = workbook.worksheets.get(0); //Add a new textbox to the collection. var textboxIndex = worksheet.textBoxes.add(2, 1, 160, 200); //Get the textbox object. var textbox0 = worksheet.textBoxes.get(textboxIndex); //Fill the text. textbox0.text = "ASPOSE CELLS"; //Set the textbox to adjust it according to its contents. textbox0.textBody.textAlignment.autoSize = true; //Set the placement. textbox0.placement = PlacementType.FreeFloating; //Set the font color. textbox0.font.color = Color.Blue; //Set the font to bold. textbox0.font.isBold = true; //Set the font size. textbox0.font.size = 14; //Set font attribute to italic. textbox0.font.isItalic = true; //Add a hyperlink to the textbox. textbox0.addHyperlink("https://www.aspose.com/"); //Get the filformat of the textbox. var fillformat = textbox0.fill; //Set the fillcolor. fillformat.solidFill.color = Color.Silver; //Get the lineformat type of the textbox. var lineformat = textbox0.line; //Set the line style. lineformat.compoundType = MsoLineStyle.ThinThick; //Set the line weight. lineformat.weight = 6; //Set the dash style to squaredot. lineformat.dashStyle = MsoLineDashStyle.SquareDot; //Add another textbox. textboxIndex = worksheet.textBoxes.add(15, 4, 85, 120); //Get the second textbox. var textbox1 = worksheet.textBoxes.get(textboxIndex); //Input some text to it. textbox1.text = "This is another simple text box"; //Set the placement type as the textbox will move and //resize with cells. textbox1.placement = PlacementType.MoveAndSize; //Save the excel file. workbook.save("output/DrawingTextBox.xlsx"); } sampleDrawingTextBox(); function sampleTablesTableStyle() { const { Workbook, BackgroundType, Color, TableStyleElementType, CellsHelper } = require("aspose.cells.node"); var workbook = new Workbook(); var firstColumnStyle = workbook.createStyle(); firstColumnStyle.pattern = BackgroundType.Solid; firstColumnStyle.backgroundColor = Color.Red; var lastColumnStyle = workbook.createStyle(); lastColumnStyle.font.isBold = true; lastColumnStyle.pattern = BackgroundType.Solid; lastColumnStyle.backgroundColor = Color.Red; var tableStyleName = "Custom1"; var tableStyles = workbook.worksheets.getTableStyles(); var index1 = tableStyles.addTableStyle(tableStyleName); var tableStyle = tableStyles.get(index1); var elements = tableStyle.getTableStyleElements(); index1 = elements.add(TableStyleElementType.FirstColumn); var element = elements.get(index1); element.setElementStyle(firstColumnStyle); index1 = elements.add(TableStyleElementType.LastColumn); element = elements.get(index1); element.setElementStyle(lastColumnStyle); var cells = workbook.worksheets.get(0).cells; for (var i = 0; i < 5; i++) { cells.get(0, i).putValue(CellsHelper.columnIndexToName(i)); } for (var row = 1; row < 10; row++) { for (var column = 0; column < 5; column++) { cells.get(row, column).putValue(row * column); } } var tables = workbook.worksheets.get(0).getListObjects(); var index = tables.add(0, 0, 9, 4, true); var table = tables.get(0); table.showTableStyleFirstColumn = true; table.showTableStyleLastColumn = true; table.tableStyleName = tableStyleName; workbook.save("output/TablesTableStyle.xlsx"); } sampleTablesTableStyle(); function sampleLicense() { const { License } = require("aspose.cells.node"); var license = new License(); license.setLicense("input/Aspose.Cells.lic"); } sampleLicense(); function sampleHyperlink() { const { Workbook } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Workbook object workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(0); //Adding a hyperlink to a URL at "A1" cell worksheet.hyperlinks.add("A1", 1, 1, "https://www.aspose.com"); //Saving the Excel file workbook.save("output/Hyperlink.xls"); } sampleHyperlink(); function sampleChartsDisplayUnitLabel() { const { Workbook, ChartType, DisplayUnitType } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Excel object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a sample value to "A4" cell worksheet.cells.get("A4").putValue(200); //Adding a sample value to "B1" cell worksheet.cells.get("B1").putValue(60); //Adding a sample value to "B2" cell worksheet.cells.get("B2").putValue(32); //Adding a sample value to "B3" cell worksheet.cells.get("B3").putValue(50); //Adding a sample value to "B4" cell worksheet.cells.get("B4").putValue(40); //Adding a sample value to "C1" cell as category data worksheet.cells.get("C1").putValue("Q1"); //Adding a sample value to "C2" cell as category data worksheet.cells.get("C2").putValue("Q2"); //Adding a sample value to "C3" cell as category data worksheet.cells.get("C3").putValue("Y1"); //Adding a sample value to "C4" cell as category data worksheet.cells.get("C4").putValue("Y2"); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 15, 5); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4" chart.nSeries.add("A1:B4", true); //Setting the data source for the category data of NSeries chart.nSeries.categoryData = "C1:C4"; //Setting the display unit of value(Y) axis. chart.valueAxis.sisplayUnit = DisplayUnitType.Hundreds; var displayUnitLabel = chart.valueAxis.displayUnitLabel; //Setting the custom display unit label displayUnitLabel.text = "100"; //Saving the Excel file workbook.save("output/ChartsDisplayUnitLabel.xls"); } sampleChartsDisplayUnitLabel(); function sampleWorkbookSettingShowTabs() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); // Hide the spreadsheet tabs. workbook.settings.showTabs = false; } sampleWorkbookSettingShowTabs(); function sampleWorkbookSettingIsHScrollBarVisible() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); // Hide the horizontal scroll bar of the Excel file. workbook.settings.isHScrollBarVisible = false; } sampleWorkbookSettingIsHScrollBarVisible(); function sampleWorkbookSettingIsVScrollBarVisible() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); // Hide the vertical scroll bar of the Excel file. workbook.settings.isVScrollBarVisible = false; } sampleWorkbookSettingIsVScrollBarVisible(); function sampleProtection() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var sheetIndex = workbook.worksheets.add(); var worksheet = workbook.worksheets.get(sheetIndex); //Allowing users to select locked cells of the worksheet worksheet.protection.allowSelectingLockedCell = true; //Allowing users to select unlocked cells of the worksheet worksheet.protection.allowSelectingUnlockedCell = true; } sampleProtection(); function sampleDrawingListBox() { const { Workbook, PlacementType, SelectionType } = require("aspose.cells.node"); //Create a new Workbook. var workbook = new Workbook(); //Get the first worksheet. var sheet = workbook.worksheets.get(0); //Get the worksheet cells collection. var cells = sheet.cells; //Input a value. cells.get("B3").putValue("Choose Dept:"); //Set it bold. cells.get("B3").getStyle().font.isBold = true; //Input some values that denote the input range //for the list box. cells.get("A2").putValue("Sales"); cells.get("A3").putValue("Finance"); cells.get("A4").putValue("MIS"); cells.get("A5").putValue("R&amp;D"); cells.get("A6").putValue("Marketing"); cells.get("A7").putValue("HRA"); //Add a new list box. var listBox = sheet.shapes.addListBox(2, 0, 3, 0, 122, 100); //Set the placement type. listBox.placement = PlacementType.FreeFloating; //Set the linked cell. listBox.linkedCell = "A1"; //Set the input range. listBox.inputRange = "A2:A7"; //Set the selection tyle. listBox.selectionType = SelectionType.Single; //Set the list box with 3-D shading. listBox.shadow = true; //Saves the file. workbook.save("output/DrawingListBox.xls"); } sampleDrawingListBox(); function sampleChartsLegend() { const { Workbook, ChartType, LegendPositionType } = require("aspose.cells.node"); //Set Legend's width and height var workbook = new Workbook(); var sheetIndex = workbook.worksheets.add(); var worksheet = workbook.worksheets.get(sheetIndex); var charts = worksheet.charts; //Create a chart var chart = charts.get(charts.add(ChartType.Column, 1, 1, 10, 10)); var legend = chart.getLegend(); //Legend is at right side of chart by default. //If the legend is at left or right side of the chart, setting Legend.X property will not take effect. //If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect. legend.y = 1500; legend.width = 50; legend.height = 50; //Set legend's position legend.position = LegendPositionType.Left; } sampleChartsLegend(); function sampleChartsChartPoint() { const { Workbook, ChartType, Color } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Obtaining the reference of the first worksheet var worksheet = workbook.worksheets.get(0); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a sample value to "B1" cell worksheet.cells.get("B1").putValue(60); //Adding a sample value to "B2" cell worksheet.cells.get("B2").putValue(32); //Adding a sample value to "B3" cell worksheet.cells.get("B3").putValue(50); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.PieExploded, 5, 0, 25, 10); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3" chart.nSeries.add("A1:B3", true); //Show Data Labels chart.nSeries.get(0).dataLabels.showValue = true; for (var i = 0; i < chart.nSeries.get(0).points.count; i++) { //Get Data Point var point = chart.nSeries.get(0).points.get(i); //Set Pir Explosion point.explosion = 15; //Set Border Color point.border.color = Color.Red; } //Saving the Excel file workbook.save("output/ChartsChartPoint.xls"); } sampleChartsChartPoint(); function sampleDrawingArcShape() { const { Workbook, FillType, Color, PlacementType, MsoLineStyle, MsoLineDashStyle } = require("aspose.cells.node"); //Instantiate a new Workbook. var excelbook = new Workbook(); //Add an arc shape. var arc1 = excelbook.worksheets.get(0).shapes.addArc(2, 0, 2, 0, 130, 130); //Set the placement of the arc. arc1.placement = PlacementType.FreeFloating; //Set the fill format. arc1.fill.fillType = FillType.Solid; arc1.fill.solidFill.color = Color.Blue; //Set the line style. arc1.line.compoundType = MsoLineStyle.Single; //Set the line weight. arc1.line.weight = 2; //Set the color of the arc line. arc1.line.fillType = FillType.Solid; arc1.line.solidFill.color = Color.Red; //Set the dash style of the arc. arc1.line.dashStyle = MsoLineDashStyle.Solid; //Add another arc shape. var arc2 = excelbook.worksheets.get(0).shapes.addArc(9, 0, 2, 0, 130, 130); //Set the placement of the arc. arc2.placement = PlacementType.FreeFloating; //Set the line style. arc2.line.compoundType = MsoLineStyle.Single; //Set the line weight. arc2.line.weight = 1; //Set the color of the arc line. arc2.line.fillType = FillType.Solid; arc2.line.solidFill.color = Color.Blue; //Set the dash style of the arc. arc2.line.dashStyle = MsoLineDashStyle.Solid; //Save the excel file. excelbook.save("output/DrawingArcShape.xls"); } sampleDrawingArcShape(); function sampleFormatConditionCollection() { const { Workbook, CellArea, FormatConditionType, OperatorType, Color } = require("aspose.cells.node"); //Adds an empty conditional formatting var workbook = new Workbook(); var sheet = workbook.worksheets.get(0); var index = sheet.conditionalFormattings.add(); var fcs = sheet.conditionalFormattings.get(index); //Sets the conditional format range. var ca = new CellArea(); ca.startRow = 0; ca.endRow = 0; ca.startColumn = 0; ca.endColumn = 0; fcs.addArea(ca); ca = new CellArea(); ca.startRow = 1; ca.endRow = 1; ca.startColumn = 1; ca.endColumn = 1; fcs.addArea(ca); //Adds condition. var conditionIndex = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100"); //Adds condition. var conditionIndex2 = fcs.addCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100"); //Sets the background color. var fc = fcs.get(conditionIndex); fc.style.backgroundColor = Color.Red; //Saving the Excel file workbook.save("output/FormatConditionCollection.xls"); } sampleFormatConditionCollection(); function sampleCommentCollection() { const { Workbook } = require("aspose.cells.node"); var workbook = new Workbook(); var comments = workbook.worksheets.get(0).comments; } sampleCommentCollection(); function sampleBorderCollection() { const { Workbook, BorderType, CellBorderType, Color } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(0); //Accessing the "A1" cell from the worksheet var cell = worksheet.cells.get("A1"); //Adding some value to the "A1" cell cell.putValue("Visit Aspose!"); //Get style object from cell var style = cell.getStyle(); //Setting the line style of the top border style.borders.get(BorderType.TopBorder).lineStyle = CellBorderType.Thick; //Setting the color of the top border style.borders.get(BorderType.TopBorder).color = Color.Black; //Setting the line style of the bottom border style.borders.get(BorderType.BottomBorder).lineStyle = CellBorderType.Thick; //Setting the color of the bottom border style.borders.get(BorderType.BottomBorder).color = Color.Black; //Setting the line style of the left border style.borders.get(BorderType.LeftBorder).lineStyle = CellBorderType.Thick; //Setting the color of the left border style.borders.get(BorderType.LeftBorder).color = Color.Black; //Setting the line style of the right border style.borders.get(BorderType.RightBorder).lineStyle = CellBorderType.Thick; //Setting the color of the right border style.borders.get(BorderType.RightBorder).color = Color.Black; //Set style object to cell cell.setStyle(style); //Saving the Excel file workbook.save("output/BorderCollection.xls"); } sampleBorderCollection(); function sampleChartsAxis() { const { Workbook, ChartType, CrossType } = require("aspose.cells.node"); //Instantiating a Workbook object var workbook = new Workbook(); //Adding a new worksheet to the Excel object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a sample value to "B1" cell worksheet.cells.get("B1").putValue(4); //Adding a sample value to "B2" cell worksheet.cells.get("B2").putValue(20); //Adding a sample value to "B3" cell worksheet.cells.get("B3").putValue(50); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 25, 5); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3" chart.nSeries.add("A1:B3", true); //Set the max value of value axis chart.valueAxis.maxValue = 200; //Set the min value of value axis chart.valueAxis.minValue = 0; //Set the major unit chart.valueAxis.majorUnit = 25; //Category(X) axis crosses at the maxinum value. chart.valueAxis.crossType = CrossType.Maximum; //Set he number of categories or series between tick-mark labels. chart.categoryAxis.tickLabelSpacing = 2; //Saving the Excel file workbook.save("output/ChartsAxis.xlsx"); } sampleChartsAxis(); function sampleChartsAxisMajorUnitScale() { const { Workbook, ChartType, CategoryType, TimeUnit } = require("aspose.cells.node"); var workbook = new Workbook(); //Adding a new worksheet to the Excel object var sheetIndex = workbook.worksheets.add(); //Obtaining the reference of the newly added worksheet by passing its sheet index var worksheet = workbook.worksheets.get(sheetIndex); //Adding a sample value to "A1" cell worksheet.cells.get("A1").putValue(50); //Adding a sample value to "A2" cell worksheet.cells.get("A2").putValue(100); //Adding a sample value to "A3" cell worksheet.cells.get("A3").putValue(150); //Adding a sample value to "B1" cell worksheet.cells.get("B1").putValue(4); //Adding a sample value to "B2" cell worksheet.cells.get("B2").putValue(20); //Adding a sample value to "B3" cell worksheet.cells.get("B3").putValue(50); //Adding a chart to the worksheet var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 25, 5); //Accessing the instance of the newly added chart var chart = worksheet.charts.get(chartIndex); chart.categoryAxis.categoryType = CategoryType.TimeScale; c