Last active
March 4, 2025 09:15
-
-
Save aspose-cells-gists/c7b55cbeb75eaaae989115230a7619eb to your computer and use it in GitHub Desktop.
Aspose.Cells for Node.js via C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This Gist contains code example snippets for Aspose.Cells for Node.js via C++. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook("Book1.xlsx") | |
| //Access the first workbook | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Access the Maximum Display Range | |
| var range = worksheet.getCells().getMaxDisplayRange(); | |
| //Print the Maximum Display Range RefersTo property | |
| console.log("Maximum Display Range: " + range.getRefersTo()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| //Open an existing worksheet | |
| var workbook = new AsposeCells.Workbook("book1.xls"); | |
| //Using the Sheet 1 in Workbook | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Accessing a cell using its row and column. | |
| var cell = worksheet.getCells().get(0, 0); | |
| console.log(cell.getStringValue()); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| var workbook = new AsposeCells.Workbook("book1.xls"); | |
| //Using the Sheet 1 in Workbook | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Accessing a cell using its name | |
| var cell = worksheet.getCells().get("A1"); | |
| console.log(cell.getStringValue()); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook("book1.xls"); | |
| //Using the Sheet 1 in Workbook | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Accessing a cell using its row and column | |
| var cell = worksheet.getCells().get(0, 0); | |
| //Printing the value of the cell | |
| console.log(cell.getStringValue()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the first worksheet | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Adding a string value to the cell | |
| worksheet.getCells().get("A1").putValue("Hello World"); | |
| // Adding a double value to the cell | |
| worksheet.getCells().get("A2").putValue(20.5); | |
| // Adding an integer value to the cell | |
| worksheet.getCells().get("A3").putValue(15); | |
| // Adding a boolean value to the cell | |
| worksheet.getCells().get("A4").putValue(true); | |
| // Adding a date/time value to the cell | |
| worksheet.getCells().get("A5").putValue(new Date()); | |
| // Setting the display format of the date | |
| let style = worksheet.getCells().get("A5").getStyle(); | |
| style.setNumber(15); | |
| worksheet.getCells().get("A5").setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| // The path to the documents directory. | |
| const AsposeCells = require("aspose.cells.node"); | |
| // Create workbook from source Excel file | |
| var workbook = new AsposeCells.Workbook("Book1.xlsx"); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Get the Cells collection in the first worksheet | |
| var cells = worksheet.getCells(); | |
| // Create a cellarea i.e.., A2:B11 | |
| var ca = AsposeCells.CellArea.createCellArea("A2", "B11"); | |
| // Apply subtotal, the consolidation function is Sum and it will applied to Second column (B) in the list | |
| cells.subtotal(ca, 0, AsposeCells.ConsolidationFunction.Sum, [1], true, false, true); | |
| // Set the direction of outline summary | |
| worksheet.getOutline().setSummaryRowBelow(true); | |
| // Save the excel file | |
| workbook.save("output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "output"); | |
| // Load your source workbook | |
| const wb = new AsposeCells.Workbook(path.join(sourceDir, "sampleAdvancedFilter.xlsx")); | |
| // Access first worksheet | |
| const ws = wb.getWorksheets().get(0); | |
| // Apply advanced filter on range A5:D19 and criteria range is A1:D2 | |
| // Besides, we want to filter in place | |
| // And, we want all filtered records not just unique records | |
| ws.advanced_Filter(true, "A5:D19", "A1:D2", "", false); | |
| // Save the workbook in xlsx format | |
| wb.save(path.join(outputDir, "outputAdvancedFilter.xlsx"), AsposeCells.SaveFormat.Xlsx); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Source directory | |
| const sourceDir = path.join(dataDir, "source/"); | |
| // Output directory | |
| const outputDir = path.join(dataDir, "output/"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(sourceDir + "Blank.xlsx"); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call MatchBlanks function to apply the filter | |
| worksheet.getAutoFilter().matchBlanks(0); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredBlank.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data/"); | |
| const outputDir = path.join(__dirname, "output/"); | |
| // Instantiating a Workbook object containing sample data | |
| let workbook = new AsposeCells.Workbook(sourceDir + "sourseSampleCountryNames.xlsx"); | |
| // Accessing the first worksheet in the Excel file | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Creating AutoFilter by giving the cells range | |
| worksheet.getAutoFilter().setRange("A1:A18"); | |
| // Initialize filter for rows starting with string "Ba" | |
| worksheet.getAutoFilter().custom(0, AsposeCells.FilterOperatorType.BeginsWith, "Ba"); | |
| // Refresh the filter to show/hide filtered rows | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(outputDir + "outSourseSampleCountryNames.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object containing sample data | |
| let workbook = new AsposeCells.Workbook(path.join(dataDir, "sourseSampleCountryNames.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Creating AutoFilter by giving the cells range | |
| worksheet.getAutoFilter().setRange("A1:A18"); | |
| // Initialize filter for rows containing string "Ba" | |
| worksheet.getAutoFilter().custom(0, AsposeCells.FilterOperatorType.Contains, "Ba"); | |
| // Refresh the filter to show/hide filtered rows | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(dataDir, "outSourseSampleCountryNames.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data/"); | |
| const outputDir = path.join(__dirname, "output/"); | |
| // Instantiating a Workbook object containing sample data | |
| const workbook = new AsposeCells.Workbook(sourceDir + "sourseSampleCountryNames.xlsx"); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Creating AutoFilter by giving the cells range | |
| worksheet.getAutoFilter().setRange("A1:A18"); | |
| // Initialize filter for rows end with string "ia" | |
| worksheet.getAutoFilter().custom(0, AsposeCells.FilterOperatorType.BeginsWith, "ia"); | |
| // Refresh the filter to show/hide filtered rows | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(outputDir + "outSourseSampleCountryNames.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object containing sample data | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "sourseSampleCountryNames.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Creating AutoFilter by giving the cells range | |
| worksheet.getAutoFilter().setRange("A1:A18"); | |
| // Initialize filter for rows containing string "Ba" | |
| worksheet.getAutoFilter().custom(0, AsposeCells.FilterOperatorType.NotContains, "Be"); | |
| // Refresh the filter to show/hide filtered rows | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(dataDir, "outSourseSampleCountryNames.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "output"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "Date.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call AddDateFilter function to apply the filter | |
| worksheet.getAutoFilter().addDateFilter(0, AsposeCells.DateTimeGroupingType.Month, 2018, 1, 0, 0, 0, 0); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(outputDir, "FilteredDate.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data/"); | |
| const outputDir = path.join(__dirname, "output/"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(`${sourceDir}Date.xlsx`); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call DynamicFilter function to apply the filter | |
| worksheet.getAutoFilter().dynamic_Filter(0, AsposeCells.DynamicFilterType.January); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(`${outputDir}FilteredDynamicDate.xlsx`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Source directory | |
| const sourceDir = dataDir; | |
| // Output directory | |
| const outputDir = dataDir; | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| let workbook = new AsposeCells.Workbook(path.join(sourceDir, "ColouredCells.xlsx")); | |
| // Instantiating a CellsColor object for foreground color | |
| let clrForeground = workbook.createCellsColor(); | |
| clrForeground.color = AsposeCells.Color.fromArgb(255, 0, 0); // Red color | |
| // Instantiating a CellsColor object for background color | |
| let clrBackground = workbook.createCellsColor(); | |
| clrBackground.color = AsposeCells.Color.fromArgb(255, 255, 255); // White color | |
| // Accessing the first worksheet in the Excel file | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Call AddFillColorFilter function to apply the filter | |
| worksheet.getAutoFilter().addFillColorFilter(0, AsposeCells.BackgroundType.Solid, clrForeground, clrBackground); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(outputDir, "FilteredColouredCells.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Method 1: Call MatchBlanks function to apply the filter | |
| // worksheet.getAutoFilter().matchBlanks(1); | |
| // Method 2: Call AddFilter function and set criteria to "" | |
| // worksheet.getAutoFilter().addFilter(1, ""); | |
| // Method 3: Call AddFilter function and set criteria to null | |
| worksheet.getAutoFilter().addFilter(1, null); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(dataDir, "FilteredBlanks.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call MatchNonBlanks function to apply the filter | |
| worksheet.getAutoFilter().matchNonBlanks(1); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(dataDir, "FilteredNonBlanks.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Source directory | |
| const sourceDir = dataDir + "/"; // Assuming sourceDir is stored here | |
| // Output directory | |
| const outputDir = dataDir + "/"; // Assuming outputDir is stored here | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(sourceDir + "Blank.xlsx"); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call MatchNonBlanks function to apply the filter | |
| worksheet.getAutoFilter().matchNonBlanks(0); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredNonBlank.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "Number.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call Custom function to apply the filter | |
| worksheet.getAutoFilter().custom(0, AsposeCells.FilterOperatorType.GreaterOrEqual, 5, true, AsposeCells.FilterOperatorType.LessOrEqual, 10); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(outputDir, "FilteredNumber.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "output"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "Text.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Call Filter function to apply the filter | |
| worksheet.getAutoFilter().filter(0, "Angola"); | |
| // Call refresh function to update the worksheet | |
| worksheet.getAutoFilter().refresh(); | |
| // Saving the modified Excel file | |
| workbook.save(path.join(outputDir, "FilteredText.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| // Opening the Excel file through the file stream | |
| const workbook = new AsposeCells.Workbook(dataDir + "book1.xls"); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Creating AutoFilter by giving the cells range of the heading row | |
| worksheet.getAutoFilter().setRange("A1:B1"); | |
| // Saving the modified Excel file | |
| workbook.save(dataDir + "output.out.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Long name will be truncated to 31 characters | |
| var name1 = AsposeCells.CellsHelper.createSafeSheetName("this is first name which is created using CellsHelper.CreateSafeSheetName and truncated to 31 characters"); | |
| //Any invalid character will be replaced with _ | |
| var name2 = AsposeCells.CellsHelper.createSafeSheetName(" <> + (adj.Private ? \" Private\" : \")", '_'); | |
| // Display first name | |
| console.log(name1); | |
| // Display second name | |
| console.log(name2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| var row = 3; | |
| var column = 5; | |
| var name = AsposeCells.CellsHelper.cellIndexToName(row, column); | |
| console.log("Cell name: " + name) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| var name = "C4"; | |
| //get row and column index of current cell | |
| var rowCol = AsposeCells.CellsHelper.cellNameToIndex(name); | |
| var currRow = rowCol[0]; | |
| var currCol = rowCol[1]; | |
| console.log("Row: " + currRow + " , Column: " + currCol) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Instantiate workbook object with an Excel file | |
| var workbook = new AsposeCells.Workbook("SampleBook.xlsx"); | |
| var sheets = workbook.getWorksheets(); | |
| var sheetcount = sheets.getCount(); | |
| for (var i = 0; i < sheetcount; i++) | |
| { | |
| sheets.get(i).getCells().convertStringToNumericValue(); | |
| } | |
| workbook.save("output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Instantiate a new workbook | |
| // Open the template file | |
| var workbook = new AsposeCells.Workbook("book1.xlsx"); | |
| // Get the Cells collection in the first worksheet | |
| var cells = workbook.getWorksheets().get(0).getCells(); | |
| // Create a cellarea i.e.., B3:C19 | |
| var ca = new AsposeCells.CellArea(); | |
| ca.startRow = 2; | |
| ca.startColumn = 1; | |
| ca.endRow = 18; | |
| ca.endColumn = 2; | |
| // Apply subtotal, the consolidation function is Sum and it will applied to | |
| // Second column (C) in the list | |
| cells.subtotal(ca, 0, AsposeCells.ConsolidationFunction.Sum, [1]); | |
| // Save the excel file | |
| workbook.save("output.out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| // Instantiate a new Workbook object. | |
| // Load a template file. | |
| var workbook = new AsposeCells.Workbook("book1.xls"); | |
| // Get the workbook datasorter object. | |
| var sorter = workbook.getDataSorter(); | |
| // Set the first order for datasorter object. | |
| sorter.setOrder1(AsposeCells.SortOrder.Descending); | |
| // Define the first key. | |
| sorter.setKey1(0); | |
| // Set the second order for datasorter object. | |
| sorter.setOrder2(AsposeCells.SortOrder.Ascending); | |
| // Define the second key. | |
| sorter.setKey2(1); | |
| // Create a cells area (range). | |
| var ca = new AsposeCells.CellArea(); | |
| // Specify the start row index. | |
| ca.startRow = 0; | |
| // Specify the start column index. | |
| ca.startColumn = 0; | |
| // Specify the last row index. | |
| ca.endRow = 13; | |
| // Specify the last column index. | |
| ca.endColumn = 1; | |
| // Sort data in the specified data range (A1:B14) | |
| sorter.sort(workbook.getWorksheets().get(0).getCells(), ca); | |
| // Save the excel file. | |
| workbook.save("output.out.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "output"); | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "ValidationsSample.xlsx")); | |
| // Access first worksheet. | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the Validations collection of the worksheet | |
| const validation = worksheet.getValidations().get(0); | |
| // Create your cell area. | |
| const cellArea = AsposeCells.CellArea.createCellArea("D5", "E7"); | |
| // Adding the cell area to Validation | |
| validation.addArea(cellArea, false, false); | |
| // Save the output workbook. | |
| workbook.save(path.join(outputDir, "ValidationsSample_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const workbook = new AsposeCells.Workbook(dataDir + "sampleValidation.xlsx"); | |
| const sheet = workbook.getWorksheets().get("Sheet1"); | |
| const cells = sheet.getCells(); | |
| const checkDropDown = (cell, cellRef) => { | |
| const validation = cell.getValidation(); | |
| if (validation.getInCellDropDown()) { | |
| console.log(`${cellRef} is a dropdown`); | |
| } else { | |
| console.log(`${cellRef} is NOT a dropdown`); | |
| } | |
| }; | |
| checkDropDown(cells.get("A2"), "A2"); | |
| checkDropDown(cells.get("B2"), "B2"); | |
| checkDropDown(cells.get("C2"), "C2"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiate the workbook from sample Excel file | |
| const workbook = new AsposeCells.Workbook(dataDir + "sample.xlsx"); | |
| // Access the first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access Cell C1 | |
| // Cell C1 has the Decimal Validation applied on it. | |
| // It can take only the values Between 10 and 20 | |
| const cell = worksheet.getCells().get("C1"); | |
| // Enter 3 inside this cell | |
| // Since it is not between 10 and 20, it should fail the validation | |
| cell.putValue(3); | |
| // Check if number 3 satisfies the Data Validation rule applied on this cell | |
| console.log("Is 3 a Valid Value for this Cell: " + cell.getValidationValue()); | |
| // Enter 15 inside this cell | |
| // Since it is between 10 and 20, it should succeed the validation | |
| cell.putValue(15); | |
| // Check if number 15 satisfies the Data Validation rule applied on this cell | |
| console.log("Is 15 a Valid Value for this Cell: " + cell.getValidationValue()); | |
| // Enter 30 inside this cell | |
| // Since it is not between 10 and 20, it should fail the validation again | |
| cell.putValue(30); | |
| // Check if number 30 satisfies the Data Validation rule applied on this cell | |
| console.log("Is 30 a Valid Value for this Cell: " + cell.getValidationValue()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Create a workbook. | |
| let workbook = new AsposeCells.Workbook(); | |
| // Obtain the cells of the first worksheet. | |
| let cells = workbook.getWorksheets().get(0).getCells(); | |
| // Put a string value into the A1 cell. | |
| cells.get("A1").putValue("Please enter Date b/w 1/1/1970 and 12/31/1999"); | |
| // Set row height and column width for the cells. | |
| cells.setRowHeight(0, 31); | |
| cells.setColumnWidth(0, 35); | |
| // Get the validations collection. | |
| let validations = workbook.getWorksheets().get(0).getValidations(); | |
| // Create Cell Area | |
| let ca = new AsposeCells.CellArea(); | |
| ca.startRow = 0; | |
| ca.endRow = 0; | |
| ca.startColumn = 0; | |
| ca.endColumn = 0; | |
| // Add a new validation. | |
| let validation = validations.get(validations.add(ca)); | |
| // Set the data validation type. | |
| validation.setType(AsposeCells.ValidationType.Date); | |
| // Set the operator for the data validation | |
| validation.setOperator(AsposeCells.OperatorType.Between); | |
| // Set the value or expression associated with the data validation. | |
| validation.setFormula1("1/1/1970"); | |
| // The value or expression associated with the second part of the data validation. | |
| validation.setFormula2("12/31/1999"); | |
| // Enable the error. | |
| validation.setShowError(true); | |
| // Set the validation alert style. | |
| validation.setAlertStyle(AsposeCells.ValidationAlertType.Stop); | |
| // Set the title of the data-validation error dialog box | |
| validation.setErrorTitle("Date Error"); | |
| // Set the data validation error message. | |
| validation.setErrorMessage("Enter a Valid Date"); | |
| // Set and enable the data validation input message. | |
| validation.setInputMessage("Date Validation Type"); | |
| validation.setIgnoreBlank(true); | |
| validation.setShowInput(true); | |
| // Set a collection of CellArea which contains the data validation settings. | |
| let cellArea = new AsposeCells.CellArea(); | |
| cellArea.startRow = 0; | |
| cellArea.endRow = 0; | |
| cellArea.startColumn = 1; | |
| cellArea.endColumn = 1; | |
| // Add the validation area. | |
| validation.addArea(cellArea); | |
| // Save the Excel file. | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| // Load source Excel file | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "SampleBook1.ods")); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| const cell = worksheet.getCells().get("A9"); | |
| if (cell.getValidation() !== null) | |
| { | |
| console.log(cell.getValidation().getType()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Create a workbook object. | |
| let workbook = new AsposeCells.Workbook(); | |
| // Get the first worksheet. | |
| let worksheet1 = workbook.getWorksheets().get(0); | |
| // Add a new worksheet and access it. | |
| let i = workbook.getWorksheets().add(); | |
| let worksheet2 = workbook.getWorksheets().get(i); | |
| // Create a range in the second worksheet. | |
| let range = worksheet2.getCells().createRange("E1", "E4"); | |
| // Name the range. | |
| range.setName("MyRange"); | |
| // Fill different cells with data in the range. | |
| range.get(0, 0).putValue("Blue"); | |
| range.get(1, 0).putValue("Red"); | |
| range.get(2, 0).putValue("Green"); | |
| range.get(3, 0).putValue("Yellow"); | |
| // Get the validations collection. | |
| let validations = worksheet1.getValidations(); | |
| // Create Cell Area | |
| let ca = new AsposeCells.CellArea(); | |
| ca.startRow = 0; | |
| ca.endRow = 0; | |
| ca.startColumn = 0; | |
| ca.endColumn = 0; | |
| // Create a new validation to the validations list. | |
| let validation = validations.get(validations.add(ca)); | |
| // Set the validation type. | |
| validation.setType(AsposeCells.ValidationType.List); | |
| // Set the operator. | |
| validation.setOperator(AsposeCells.OperatorType.None); | |
| // Set the in cell drop down. | |
| validation.setInCellDropDown(true); | |
| // Set the formula1. | |
| validation.setFormula1("=MyRange"); | |
| // Enable it to show error. | |
| validation.setShowError(true); | |
| // Set the alert type severity level. | |
| validation.setAlertStyle(AsposeCells.ValidationAlertType.Stop); | |
| // Set the error title. | |
| validation.setErrorTitle("Error"); | |
| // Set the error message. | |
| validation.setErrorMessage("Please select a color from the list"); | |
| // Specify the validation area. | |
| let area = new AsposeCells.CellArea(); | |
| area.startRow = 0; | |
| area.endRow = 4; | |
| area.startColumn = 0; | |
| area.endColumn = 0; | |
| // Add the validation area. | |
| validation.addArea(area); | |
| // Save the Excel file. | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiate the workbook from sample Excel file | |
| const workbook = new AsposeCells.Workbook(dataDir + "sample.xlsx"); | |
| // Access its first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Cell C1 has the Decimal Validation applied on it. It can take only the values Between 10 and 20 | |
| const cell = worksheet.getCells().get("C1"); | |
| // Access the validation applied on this cell | |
| const validation = cell.getValidation(); | |
| // Read various properties of the validation | |
| console.log("Reading Properties of Validation"); | |
| console.log("--------------------------------"); | |
| console.log("Type: " + validation.getType()); | |
| console.log("Operator: " + validation.getOperator()); | |
| console.log("Formula1: " + validation.getFormula1()); | |
| console.log("Formula2: " + validation.getFormula2()); | |
| console.log("Ignore blank: " + validation.getIgnoreBlank()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Create a new workbook. | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtain the cells of the first worksheet. | |
| const cells = workbook.getWorksheets().get(0).getCells(); | |
| // Put a string value into A1 cell. | |
| cells.get("A1").putValue("Please enter a string not more than 5 chars"); | |
| // Set row height and column width for the cell. | |
| cells.setRowHeight(0, 31); | |
| cells.setColumnWidth(0, 35); | |
| // Get the validations collection. | |
| const validations = workbook.getWorksheets().get(0).getValidations(); | |
| // Create Cell Area | |
| const ca = new AsposeCells.CellArea(); | |
| ca.startRow = 0; | |
| ca.endRow = 0; | |
| ca.startColumn = 0; | |
| ca.endColumn = 0; | |
| // Add a new validation. | |
| const validation = validations.get(validations.add(ca)); | |
| // Set the data validation type. | |
| validation.setType(AsposeCells.ValidationType.TextLength); | |
| // Set the operator for the data validation. | |
| validation.setOperator(AsposeCells.OperatorType.LessOrEqual); | |
| // Set the value or expression associated with the data validation. | |
| validation.setFormula1("5"); | |
| // Enable the error. | |
| validation.setShowError(true); | |
| // Set the validation alert style. | |
| validation.setAlertStyle(AsposeCells.ValidationAlertType.Warning); | |
| // Set the title of the data-validation error dialog box. | |
| validation.setErrorTitle("Text Length Error"); | |
| // Set the data validation error message. | |
| validation.setErrorMessage(" Enter a Valid String"); | |
| // Set and enable the data validation input message. | |
| validation.setInputMessage("TextLength Validation Type"); | |
| validation.setIgnoreBlank(true); | |
| validation.setShowInput(true); | |
| // Set a collection of CellArea which contains the data validation settings. | |
| const cellArea = new AsposeCells.CellArea(); | |
| cellArea.startRow = 0; | |
| cellArea.endRow = 0; | |
| cellArea.startColumn = 1; | |
| cellArea.endColumn = 1; | |
| // Add the validation area. | |
| validation.addArea(cellArea); | |
| // Save the Excel file. | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Create a workbook. | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtain the cells of the first worksheet. | |
| const cells = workbook.getWorksheets().get(0).getCells(); | |
| // Put a string value into A1 cell. | |
| cells.get("A1").putValue("Please enter Time b/w 09:00 and 11:30 'o Clock"); | |
| // Set the row height and column width for the cells. | |
| cells.setRowHeight(0, 31); | |
| cells.setColumnWidth(0, 35); | |
| // Get the validations collection. | |
| const validations = workbook.getWorksheets().get(0).getValidations(); | |
| // Create Cell Area | |
| const ca = new AsposeCells.CellArea(); | |
| ca.startRow = 0; | |
| ca.endRow = 0; | |
| ca.startColumn = 0; | |
| ca.endColumn = 0; | |
| // Add a new validation. | |
| const validation = validations.get(validations.add(ca)); | |
| // Set the data validation type. | |
| validation.setType(AsposeCells.ValidationType.Time); | |
| // Set the operator for the data validation. | |
| validation.setOperator(AsposeCells.OperatorType.Between); | |
| // Set the value or expression associated with the data validation. | |
| validation.setFormula1("09:00"); | |
| // The value or expression associated with the second part of the data validation. | |
| validation.setFormula2("11:30"); | |
| // Enable the error. | |
| validation.setShowError(true); | |
| // Set the validation alert style. | |
| validation.setAlertStyle(AsposeCells.ValidationAlertType.Information); | |
| // Set the title of the data-validation error dialog box. | |
| validation.setErrorTitle("Time Error"); | |
| // Set the data validation error message. | |
| validation.setErrorMessage("Enter a Valid Time"); | |
| // Set and enable the data validation input message. | |
| validation.setInputMessage("Time Validation Type"); | |
| validation.setIgnoreBlank(true); | |
| validation.setShowInput(true); | |
| // Set a collection of CellArea which contains the data validation settings. | |
| const cellArea = new AsposeCells.CellArea(); | |
| cellArea.startRow = 0; | |
| cellArea.endRow = 0; | |
| cellArea.startColumn = 1; | |
| cellArea.endColumn = 1; | |
| // Add the validation area. | |
| validation.addArea(cellArea); | |
| // Save the Excel file. | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiate the workbook from sample Excel file | |
| const workbook = new AsposeCells.Workbook(dataDir + "sample.xlsx"); | |
| // Access the first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access Cell C1 | |
| // Cell C1 has the Decimal Validation applied on it. | |
| // It can take only the values Between 10 and 20 | |
| const cell = worksheet.getCells().get("C1"); | |
| // Enter 3 inside this cell | |
| // Since it is not between 10 and 20, it should fail the validation | |
| cell.putValue(3); | |
| // Check if number 3 satisfies the Data Validation rule applied on this cell | |
| console.log("Is 3 a Valid Value for this Cell: " + cell.getValidationValue()); | |
| // Enter 15 inside this cell | |
| // Since it is between 10 and 20, it should succeed the validation | |
| cell.putValue(15); | |
| // Check if number 15 satisfies the Data Validation rule applied on this cell | |
| console.log("Is 15 a Valid Value for this Cell: " + cell.getValidationValue()); | |
| // Enter 30 inside this cell | |
| // Since it is not between 10 and 20, it should fail the validation again | |
| cell.putValue(30); | |
| // Check if number 30 satisfies the Data Validation rule applied on this cell | |
| console.log("Is 30 a Valid Value for this Cell: " + cell.getValidationValue()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Create a workbook object. | |
| const workbook = new AsposeCells.Workbook(); | |
| // Create a worksheet and get the first worksheet. | |
| const ExcelWorkSheet = workbook.getWorksheets().get(0); | |
| // Accessing the Validations collection of the worksheet | |
| const validations = workbook.getWorksheets().get(0).getValidations(); | |
| // Create Cell Area | |
| const ca = new AsposeCells.CellArea(); | |
| ca.startRow = 0; | |
| ca.endRow = 0; | |
| ca.startColumn = 0; | |
| ca.endColumn = 0; | |
| // Creating a Validation object | |
| const validation = validations.get(validations.add(ca)); | |
| // Setting the validation type to whole number | |
| validation.setType(AsposeCells.ValidationType.WholeNumber); | |
| // Setting the operator for validation to Between | |
| validation.setOperator(AsposeCells.OperatorType.Between); | |
| // Setting the minimum value for the validation | |
| validation.setFormula1("10"); | |
| // Setting the maximum value for the validation | |
| validation.setFormula2("1000"); | |
| // Applying the validation to a range of cells from A1 to B2 using the | |
| // CellArea structure | |
| const area = new AsposeCells.CellArea(); | |
| area.startRow = 0; | |
| area.endRow = 1; | |
| area.startColumn = 0; | |
| area.endColumn = 1; | |
| // Adding the cell area to Validation | |
| validation.addArea(area); | |
| // Save the workbook. | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the newly added worksheet | |
| const ws = workbook.getWorksheets().get(0); | |
| const cells = ws.getCells(); | |
| // Setting the DateTime value to the cells | |
| const a1 = cells.get("A1"); | |
| a1.putValue(new Date()); | |
| // Check if the cell contains a numeric value | |
| if (a1.getType() === AsposeCells.CellValueType.IsNumeric) { | |
| console.log("A1 is Numeric Value: " + a1.isNumericValue); | |
| } | |
| let a1Style = a1.getStyle(); | |
| // Set custom Datetime style | |
| a1Style.setCustom("mm-dd-yy hh:mm:ss"); | |
| a1.setStyle(a1Style); | |
| // Check if the cell contains a DateTime value | |
| if (a1.getType() === AsposeCells.CellValueType.IsDateTime) { | |
| console.log("Cell A1 contains a DateTime value."); | |
| // Get the DateTime value | |
| const dateTimeValue = a1.getDateTimeValue(); | |
| // Now, you can use dateTimeValue as needed | |
| console.log("A1 DateTime Value: " + dateTimeValue); | |
| // Output date formatted string | |
| console.log("A1 DateTime String Value: " + a1.getStringValue()); | |
| } else { | |
| console.log("Cell A1 does not contain a DateTime value."); | |
| } | |
| // Setting the DateTime value to the cells | |
| const a2 = cells.get("A2"); | |
| a2.putValue(new Date()); | |
| // Check if the cell contains a numeric value | |
| if (a2.getType() === AsposeCells.CellValueType.IsNumeric) { | |
| console.log("A2 is Numeric Value: " + a2.isNumericValue); | |
| } | |
| let a2Style = a2.getStyle(); | |
| // Set the display format of numbers and dates. | |
| a2Style.setNumber(22); | |
| a2.setStyle(a2Style); | |
| // Check if the cell contains a DateTime value | |
| if (a2.getType() === AsposeCells.CellValueType.IsDateTime) { | |
| console.log("Cell A2 contains a DateTime value."); | |
| // Get the DateTime value | |
| const dateTimeValue = a2.getDateTimeValue(); | |
| // Now, you can use dateTimeValue as needed | |
| console.log("A2 DateTime Value: " + dateTimeValue); | |
| // Output date formatted string | |
| console.log("A2 DateTime String Value: " + a2.getStringValue()); | |
| } else { | |
| console.log("Cell A2 does not contain a DateTime value."); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the newly added worksheet | |
| let ws = workbook.getWorksheets().get(0); | |
| let cells = ws.getCells(); | |
| // Setting the DateTime value to the cells | |
| let a1 = cells.get("A1"); | |
| a1.putValue(new Date()); | |
| // Check if the cell contains a numeric value | |
| if (a1.getType() === AsposeCells.CellValueType.IsNumeric) { | |
| console.log("A1 is Numeric Value: " + a1.isNumericValue()); | |
| } | |
| let a1Style = a1.getStyle(); | |
| // Set custom Datetime style | |
| a1Style.setCustom("mm-dd-yy hh:mm:ss"); | |
| a1.setStyle(a1Style); | |
| // Check if the cell contains a DateTime value | |
| if (a1.getType() === AsposeCells.CellValueType.IsDateTime) { | |
| console.log("Cell A1 contains a DateTime value."); | |
| } else { | |
| console.log("Cell A1 does not contain a DateTime value."); | |
| } | |
| // Setting the DateTime value to the cells | |
| let a2 = cells.get("A2"); | |
| a2.putValue(new Date()); | |
| // Check if the cell contains a numeric value | |
| if (a2.getType() === AsposeCells.CellValueType.IsNumeric) { | |
| console.log("A2 is Numeric Value: " + a2.isNumericValue()); | |
| } | |
| let a2Style = a2.getStyle(); | |
| // Set the display format of numbers and dates. | |
| a2Style.setNumber(22); | |
| a2.setStyle(a2Style); | |
| // Check if the cell contains a DateTime value | |
| if (a2.getType() === AsposeCells.CellValueType.IsDateTime) { | |
| console.log("Cell A2 contains a DateTime value."); | |
| } else { | |
| console.log("Cell A2 does not contain a DateTime value."); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating an Workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| workbook.getSettings().setDate1904(false); | |
| // Obtaining the reference of the newly added worksheet | |
| let ws = workbook.getWorksheets().get(0); | |
| let cells = ws.getCells(); | |
| let dateData = new Date(2023, 10, 23); // JavaScript months are 0-based | |
| // Setting the DateTime value to the cells | |
| let a1 = cells.get("A1"); | |
| a1.putValue(dateData); | |
| // Check if the cell contains a numeric value | |
| if (a1.getType() === AsposeCells.CellValueType.IsNumeric) { | |
| console.log("A1 is Numeric Value: " + a1.getDoubleValue()); | |
| } | |
| workbook.getSettings().setDate1904(true); | |
| console.log("use The 1904 date system===================="); | |
| // Setting the DateTime value to the cells | |
| let a2 = cells.get("A2"); | |
| a2.setValue(dateData); | |
| // Check if the cell contains a numeric value | |
| if (a2.getType() === AsposeCells.CellValueType.IsNumeric) { | |
| console.log("A2 is Numeric Value: " + a2.getDoubleValue()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook | |
| const workbook = new AsposeCells.Workbook(); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access cell A1 | |
| const cell = worksheet.getCells().get("A1"); | |
| // Put value inside the cell | |
| cell.putValue(0.012345); | |
| // Format the cell that it should display 0.01 instead of 0.012345 | |
| const style = cell.getStyle(); | |
| style.setNumber(2); | |
| cell.setStyle(style); | |
| // Get string value as Cell Style | |
| let value = cell.getStringValue(AsposeCells.CellValueFormatStrategy.CellStyle); | |
| console.log(value); | |
| // Get string value without any formatting | |
| value = cell.getStringValue(AsposeCells.CellValueFormatStrategy.None); | |
| console.log(value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| const workbook = new AsposeCells.Workbook(); | |
| const worksheet = workbook.getWorksheets().get(0); | |
| const cell = worksheet.getCells().get("A1"); | |
| cell.setHtmlString("<Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;TEXT-DECORATION: underline;FONT-FAMILY: Arial;FONT-SIZE: 11pt;COLOR: #ff0000;\">This is simple HTML formatted text.</Font>"); | |
| workbook.save(dataDir + "output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access cell A1 | |
| const cell = worksheet.getCells().get("A1"); | |
| // Set the HTML string | |
| cell.setHtmlString("<font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'>Text 1 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 2 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 3 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 4 </font>"); | |
| // Auto fit the Columns | |
| worksheet.autoFitColumns(); | |
| // Save the workbook | |
| workbook.save(path.join(dataDir, "BulletsInCells_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook. | |
| const wb = new AsposeCells.Workbook(); | |
| // Access first worksheet. | |
| const ws = wb.getWorksheets().get(0); | |
| // Access cell A1 and put some text inside it. | |
| const cell = ws.getCells().get("A1"); | |
| cell.putValue("This is some text."); | |
| // Get the Normal and Html5 strings. | |
| const strNormal = cell.getHtmlString(false); | |
| const strHtml5 = cell.getHtmlString(true); | |
| // Print the Normal and Html5 strings on console. | |
| console.log("Normal:\r\n" + strNormal); | |
| console.log(); | |
| console.log("Html5:\r\n" + strHtml5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the newly added worksheet | |
| let ws = workbook.getWorksheets().get(0); | |
| let cells = ws.getCells(); | |
| // Setting the value to the cells | |
| let cell = cells.get("A1"); | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Price"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| let c3 = cells.get("C3"); | |
| // set html string for C3 cell. | |
| c3.setHtmlString("<b>test bold</b>"); | |
| let c4 = cells.get("C4"); | |
| // set html string for C4 cell. | |
| c4.setHtmlString("<i>test italic</i>"); | |
| // get the html string of specific cell. | |
| console.log(c3.getHtmlString()); | |
| console.log(c4.getHtmlString()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiate a new workbook | |
| let workbook = new AsposeCells.Workbook(); | |
| // Get the first worksheet | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Insert a string value to a cell | |
| worksheet.getCells().get("C2").putValue("Image Hyperlink"); | |
| // Set the 4th row height | |
| worksheet.getCells().setRowHeight(3, 100); | |
| // Set the C column width | |
| worksheet.getCells().setColumnWidth(2, 21); | |
| // Add a picture to the C4 cell | |
| let index = worksheet.getPictures().add(3, 2, 4, 3, path.join(dataDir, "aspose-logo.jpg")); | |
| // Get the picture object | |
| let pic = worksheet.getPictures().get(index); | |
| // Set the placement type | |
| pic.setPlacement(AsposeCells.Drawing.PlacementType.FreeFloating); | |
| // Add an image hyperlink | |
| let hlink = pic.addHyperlink("http://www.aspose.com/"); | |
| // Specify the screen tip | |
| hlink.setScreenTip("Click to go to Aspose site"); | |
| let outputFilePath = path.join(dataDir, "ImageHyperlink.out.xls"); | |
| // Save the Excel file | |
| workbook.save(outputFilePath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Workbook object | |
| workbook.getWorksheets().add(); | |
| // Obtaining the reference of the first (default) worksheet | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Adding an internal hyperlink to the "B3" cell of the other worksheet "Sheet2" in | |
| // The same Excel file | |
| worksheet.getHyperlinks().add("B3", 1, 1, "Sheet2!B9"); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in | |
| // The same Excel file | |
| worksheet.getHyperlinks().add("A5", 1, 1, path.join(dataDir, "book1.xls")); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the first worksheet | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Adding a hyperlink to a URL at "A1" cell | |
| worksheet.getHyperlinks().add("A1", 1, 1, "http://www.aspose.com"); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "output.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const workbook = new AsposeCells.Workbook(sourceDir + "LinkTypes.xlsx"); | |
| // Get the first (default) worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Create a range A1:B7 | |
| const range = worksheet.getCells().createRange("A1", "A7"); | |
| // Get Hyperlinks in range | |
| const hyperlinks = range.getHyperlinks(); | |
| hyperlinks.forEach(link => { | |
| console.log(link.getTextToDisplay() + ": " + link.getLinkType()); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const workbook = new AsposeCells.Workbook(dataDir + "Sample.xlsx"); | |
| const worksheet = workbook.getWorksheets().get(0); | |
| for (let i = 0; i < worksheet.getHyperlinks().getCount(); i++) { | |
| const hl = worksheet.getHyperlinks().get(i); | |
| hl.setAddress("http://www.aspose.com"); | |
| } | |
| workbook.save(dataDir + "output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "output"); | |
| // Instantiate a Workbook object | |
| // Open an Excel file | |
| const workbook = new AsposeCells.Workbook(`${sourceDir}/HyperlinksSample.xlsx`); | |
| // Get the first (default) worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Create a range A2:B3 | |
| const range = worksheet.getCells().createRange("A2", "B3"); | |
| // Get Hyperlinks in range | |
| const hyperlinks = range.getHyperlinks(); | |
| hyperlinks.forEach(link => { | |
| console.log(`${link.getArea()} : ${link.getAddress()}`); | |
| // To delete the link, use the Hyperlink.Delete() method. | |
| link.delete(); | |
| }); | |
| workbook.save(`${outputDir}/HyperlinksSample_out.xlsx`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Load the Excel file | |
| let workbook = new AsposeCells.Workbook(path.join(dataDir, "sample.xlsx")); | |
| // Access the first worksheet | |
| let sheet = workbook.getWorksheets().get(0); | |
| // Unlock all cells first | |
| let unlockStyle = workbook.createStyle(); | |
| unlockStyle.setIsLocked(false); | |
| let styleFlag = new AsposeCells.StyleFlag(); | |
| styleFlag.setLocked(true); | |
| sheet.getCells().applyStyle(unlockStyle, styleFlag); | |
| // Lock specific cells (e.g., A1 and B2) | |
| let lockStyle = workbook.createStyle(); | |
| lockStyle.setIsLocked(true); | |
| sheet.getCells().get("A1").setStyle(lockStyle); | |
| sheet.getCells().get("B2").setStyle(lockStyle); | |
| // Protect the worksheet to enforce the locking | |
| sheet.protect(AsposeCells.ProtectionType.All); | |
| // Save the modified workbook | |
| workbook.save(path.join(dataDir, "output_locked.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const workbook = new AsposeCells.Workbook(dataDir +"sample.xlsx"); | |
| const sheet = workbook.getWorksheets().get(0); | |
| const cells = sheet.getCells(); | |
| const row = cells.checkRow(1); | |
| if (row != null) { | |
| //get Maximum column index of Row which contains data or style. | |
| console.log("Max column index in row: " + row.getLastCell().getColumn()); | |
| //get Maximum column index of Row which contains data. | |
| console.log("Max data column index in row: " + row.getLastDataCell().getColumn()); | |
| } | |
| // create the range of column B | |
| const columnRange = cells.createRange(1, 1, true); | |
| var max_row_index = cells.getMaxRow() + 1; | |
| var maxRow = 0; | |
| var maxDataRow = 0; | |
| for (let row_index = 0; row_index < max_row_index; row_index++) | |
| { | |
| var curr_cell = cells.get(row_index, 1); | |
| if (curr_cell) | |
| { | |
| if (curr_cell.getStringValue()) | |
| { | |
| maxDataRow = curr_cell.getRow(); | |
| } | |
| if (curr_cell.getStringValue() || curr_cell.getHasCustomStyle()) | |
| { | |
| maxRow = curr_cell.getRow(); | |
| } | |
| } | |
| } | |
| //Maximum row index of Column which contains data or style. | |
| console.log("Max row index in Column: " + maxRow); | |
| //Maximum row index of Column which contains data. | |
| console.log("Max data row index in Column: " + maxDataRow); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| let workbook = new AsposeCells.Workbook(sourceDir + "GetTextWidthSample.xlsx"); | |
| console.log("Text width: " + AsposeCells.CellsHelper.getTextWidth(workbook.getWorksheets().get(0).getCells().get("A1").getStringValue(), workbook.getDefaultStyle().getFont(), 1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook object | |
| let workbook = new AsposeCells.Workbook(); | |
| // Access first worksheet | |
| let worksheet = workbook.getWorksheets().get(0); | |
| // Access cell B2 and add some value inside it | |
| let cell = worksheet.getCells().get("B2"); | |
| cell.putValue("Welcome to Aspose!"); | |
| // Enlarge its font to size 16 | |
| let style = cell.getStyle(); | |
| style.getFont().setSize(16); | |
| cell.setStyle(style); | |
| // Calculate the width and height of the cell value in unit of pixels | |
| let widthOfValue = cell.getWidthOfValue(); | |
| let heightOfValue = cell.getHeightOfValue(); | |
| // Print both values | |
| console.log("Width of Cell Value: " + widthOfValue); | |
| console.log("Height of Cell Value: " + heightOfValue); | |
| // Set the row height and column width to adjust/fit the cell value inside cell | |
| worksheet.getCells().setColumnWidthPixel(1, widthOfValue); | |
| worksheet.getCells().setRowHeightPixel(1, heightOfValue); | |
| // Save the output excel file | |
| workbook.save(path.join(dataDir, "output_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| const dataDir = path.join(__dirname, "data"); | |
| let testWorkbook; | |
| const threadLoop = () => { | |
| const random = Math.random; | |
| while (true) { | |
| try { | |
| const row = Math.floor(random() * 10000); | |
| const col = Math.floor(random() * 100); | |
| const s = testWorkbook.getWorksheets().get(0).getCells().get(row, col).getStringValue(); | |
| if (s !== "R" + row + "C" + col) { | |
| console.log("This message will show up when cells read values are incorrect."); | |
| } | |
| } catch (e) {} | |
| } | |
| }; | |
| const testMultiThreadingRead = () => { | |
| testWorkbook = new AsposeCells.Workbook(); | |
| testWorkbook.getWorksheets().clear(); | |
| testWorkbook.getWorksheets().add("Sheet1"); | |
| for (let row = 0; row < 10000; row++) | |
| for (let col = 0; col < 100; col++) | |
| testWorkbook.getWorksheets().get(0).getCells().get(row, col).setValue("R" + row + "C" + col); | |
| // Uncommenting this line will enable multi-threaded reading | |
| //testWorkbook.getWorksheets().get(0).getCells().setMultiThreadReading(true); | |
| const myThread1 = setInterval(threadLoop, 0); | |
| const myThread2 = setInterval(threadLoop, 0); | |
| setTimeout(() => { | |
| clearInterval(myThread1); | |
| clearInterval(myThread2); | |
| }, 5 * 1000); | |
| }; | |
| testMultiThreadingRead(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // Create an instance of Workbook class | |
| const book = new AsposeCells.Workbook(); | |
| // Setting this property to true will make Aspose.Cells to throw exception | |
| // when invalid custom number format is assigned to Style.Custom property | |
| book.getSettings().setCheckCustomNumberFormat(true); | |
| // Access first worksheet | |
| const sheet = book.getWorksheets().get(0); | |
| // Access cell A1 and put some number to it | |
| const cell = sheet.getCells().get("A1"); | |
| cell.putValue(2347); | |
| // Access cell's style and set its Style.Custom property | |
| const style = cell.getStyle(); | |
| // This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true | |
| style.setCustom("ggg @ fff"); //Invalid custom number format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Adding the current system date to "A1" cell | |
| worksheet.getCells().get("A1").putValue(new Date()); | |
| // Getting the Style of the A1 Cell | |
| let style = worksheet.getCells().get("A1").getStyle(); | |
| // Setting the display format to number 15 to show date as "d-mmm-yy" | |
| style.setNumber(15); | |
| // Applying the style to the A1 cell | |
| worksheet.getCells().get("A1").setStyle(style); | |
| // Adding a numeric value to "A2" cell | |
| worksheet.getCells().get("A2").putValue(20); | |
| // Getting the Style of the A2 Cell | |
| style = worksheet.getCells().get("A2").getStyle(); | |
| // Setting the display format to number 9 to show value as percentage | |
| style.setNumber(9); | |
| // Applying the style to the A2 cell | |
| worksheet.getCells().get("A2").setStyle(style); | |
| // Adding a numeric value to "A3" cell | |
| worksheet.getCells().get("A3").putValue(2546); | |
| // Getting the Style of the A3 Cell | |
| style = worksheet.getCells().get("A3").getStyle(); | |
| // Setting the display format to number 6 to show value as currency | |
| style.setNumber(6); | |
| // Applying the style to the A3 cell | |
| worksheet.getCells().get("A3").setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)){ | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Adding the current system date to "A1" cell | |
| worksheet.getCells().get("A1").putValue(new Date()); | |
| // Getting the style of A1 cell | |
| let style = worksheet.getCells().get("A1").getStyle(); | |
| // Setting the custom display format to show date as "d-mmm-yy" | |
| style.setCustom("d-mmm-yy"); | |
| // Applying the style to A1 cell | |
| worksheet.getCells().get("A1").setStyle(style); | |
| // Adding a numeric value to "A2" cell | |
| worksheet.getCells().get("A2").putValue(20); | |
| // Getting the style of A2 cell | |
| style = worksheet.getCells().get("A2").getStyle(); | |
| // Setting the custom display format to show value as percentage | |
| style.setCustom("0.0%"); | |
| // Applying the style to A2 cell | |
| worksheet.getCells().get("A2").setStyle(style); | |
| // Adding a numeric value to "A3" cell | |
| worksheet.getCells().get("A3").putValue(2546); | |
| // Getting the style of A3 cell | |
| style = worksheet.getCells().get("A3").getStyle(); | |
| // Setting the custom display format to show value as currency | |
| style.setCustom("£#,##0;[Red]$-#,##0"); | |
| // Applying the style to A3 cell | |
| worksheet.getCells().get("A3").setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "SourceFile.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| workbook.save(path.join(dataDir, "CustomDateFormat_out.pdf")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Specify custom separators | |
| workbook.getSettings().setNumberDecimalSeparator('.'); | |
| workbook.getSettings().setNumberGroupSeparator(' '); | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Set cell value | |
| const cell = worksheet.getCells().get("A1"); | |
| cell.putValue(123456.789); | |
| // Set custom cell style | |
| const style = cell.getStyle(); | |
| style.setCustom("#,##0.000;[Red]#,##0.000"); | |
| cell.setStyle(style); | |
| worksheet.autoFitColumns(); | |
| // Save workbook as pdf | |
| workbook.save(path.join(dataDir, "CustomSeparator_out.pdf")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a workbook. | |
| const wb = new AsposeCells.Workbook(); | |
| // Access first worksheet. | |
| const ws = wb.getWorksheets().get(0); | |
| // Access cell A1 and put value 123. | |
| const cell = ws.getCells().get("A1"); | |
| cell.putValue(123); | |
| // Access cell style. | |
| const st = cell.getStyle(); | |
| // Specifying DBNum custom pattern formatting. | |
| st.setCustom("[DBNum2][$-804]General"); | |
| // Set the cell style. | |
| cell.setStyle(st); | |
| // Set the first column width. | |
| ws.getCells().setColumnWidth(0, 30); | |
| // Save the workbook in output pdf format. | |
| wb.save(path.join(dataDir, "outputDBNumCustomFormatting.pdf"), AsposeCells.SaveFormat.Pdf); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create a workbook | |
| let workbook = new AsposeCells.Workbook(); | |
| // Populate Data into Cells | |
| let cells = workbook.getWorksheets().get(0).getCells(); | |
| cells.get("A1").putValue("data1"); | |
| cells.get("B1").putValue("data2"); | |
| cells.get("A2").putValue("data3"); | |
| cells.get("B2").putValue("data4"); | |
| // Save workbook | |
| workbook.save(path.join(dataDir, "output_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook | |
| let wb = new AsposeCells.Workbook(); | |
| // Access first worksheet | |
| let ws = wb.getWorksheets().get(0); | |
| // Access cell A1 | |
| let cell = ws.getCells().get("A1"); | |
| // Put some text in cell, it does not have Single Quote at the beginning | |
| cell.putValue("Text"); | |
| // Access style of cell A1 | |
| let st = cell.getStyle(); | |
| // Print the value of Style.QuotePrefix of cell A1 | |
| console.log("Quote Prefix of Cell A1: " + st.getQuotePrefix()); | |
| // Put some text in cell, it has Single Quote at the beginning | |
| cell.putValue("'Text"); | |
| // Access style of cell A1 | |
| st = cell.getStyle(); | |
| // Print the value of Style.QuotePrefix of cell A1 | |
| console.log("Quote Prefix of Cell A1: " + st.getQuotePrefix()); | |
| // Print information about StyleFlag.QuotePrefix property | |
| console.log(); | |
| console.log("When StyleFlag.QuotePrefix is False, it means, do not update the value of Cell.Style.QuotePrefix."); | |
| console.log("Similarly, when StyleFlag.QuotePrefix is True, it means, update the value of Cell.Style.QuotePrefix."); | |
| console.log(); | |
| // Create an empty style | |
| st = wb.createStyle(); | |
| // Create style flag - set StyleFlag.QuotePrefix as false | |
| // It means, we do not want to update the Style.QuotePrefix property of cell A1's style. | |
| let flag = new AsposeCells.StyleFlag(); | |
| flag.setQuotePrefix(false); | |
| // Create a range consisting of single cell A1 | |
| let rng = ws.getCells().createRange("A1"); | |
| // Apply the style to the range | |
| rng.applyStyle(st, flag); | |
| // Access the style of cell A1 | |
| st = cell.getStyle(); | |
| // Print the value of Style.QuotePrefix of cell A1 | |
| // It will print True, because we have not updated the Style.QuotePrefix property of cell A1's style. | |
| console.log("Quote Prefix of Cell A1: " + st.getQuotePrefix()); | |
| // Create an empty style | |
| st = wb.createStyle(); | |
| // Create style flag - set StyleFlag.QuotePrefix as true | |
| // It means, we want to update the Style.QuotePrefix property of cell A1's style. | |
| flag = new AsposeCells.StyleFlag(); | |
| flag.setQuotePrefix(true); | |
| // Apply the style to the range | |
| rng.applyStyle(st, flag); | |
| // Access the style of cell A1 | |
| st = cell.getStyle(); | |
| // Print the value of Style.QuotePrefix of cell A1 | |
| // It will print False, because we have updated the Style.QuotePrefix property of cell A1's style. | |
| console.log("Quote Prefix of Cell A1: " + st.getQuotePrefix()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Opening an existing workbook | |
| const workbook = new AsposeCells.Workbook("book1.xls"); | |
| // Accessing first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| var cells = worksheet.getCells(); | |
| var maxRow = cells.getMaxRow(); | |
| var maxColumn = cells.getMaxColumn(); | |
| for (let i = 0; i <= maxRow; i++) { | |
| for (let j = 0; j <= maxColumn; j++) | |
| { | |
| const cell1 = cells.get(i, j); | |
| // Variables to store values of different data types | |
| let stringValue; | |
| let doubleValue; | |
| let boolValue; | |
| let dateTimeValue; | |
| // Passing the type of the data contained in the cell for evaluation | |
| switch (cell1.getType()) { | |
| // Evaluating the data type of the cell data for string value | |
| case AsposeCells.CellValueType.IsString: | |
| stringValue = cell1.getStringValue(); | |
| console.log("String Value: " + stringValue); | |
| break; | |
| // Evaluating the data type of the cell data for double value | |
| case AsposeCells.CellValueType.IsNumeric: | |
| doubleValue = cell1.getDoubleValue(); | |
| console.log("Double Value: " + doubleValue); | |
| break; | |
| // Evaluating the data type of the cell data for boolean value | |
| case AsposeCells.CellValueType.IsBool: | |
| boolValue = cell1.getBoolValue(); | |
| console.log("Bool Value: " + boolValue); | |
| break; | |
| // Evaluating the data type of the cell data for date/time value | |
| case AsposeCells.CellValueType.IsDateTime: | |
| dateTimeValue = cell1.getDateTimeValue(); | |
| console.log("DateTime Value: " + dateTimeValue); | |
| break; | |
| // Evaluating the unknown data type of the cell data | |
| case AsposeCells.CellValueType.IsUnknown: | |
| stringValue = cell1.getStringValue(); | |
| console.log("Unknown Value: " + stringValue); | |
| break; | |
| // Terminating the type checking of type of the cell data is null | |
| case AsposeCells.CellValueType.IsNull: | |
| break; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Opening the Excel file | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "sampleFindingCellsContainingFormula.xlsx")); | |
| // Accessing the first worksheet in the Excel file | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Instantiate FindOptions Object | |
| const findOptions = new AsposeCells.FindOptions(); | |
| findOptions.setLookInType(AsposeCells.LookInType.Formulas); | |
| // Finding the cell containing the specified formula | |
| const cell = worksheet.getCells().find("=SUM(A5:A10)", null, findOptions); | |
| // Printing the name of the cell found after searching worksheet | |
| console.log("Name of the cell containing formula: " + cell.getName()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiate the workbook object | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xls")); | |
| // Get Cells collection | |
| const cells = workbook.getWorksheets().get(0).getCells(); | |
| const opts = new AsposeCells.FindOptions(); | |
| opts.setLookInType(AsposeCells.LookInType.Values); | |
| opts.setLookAtType(AsposeCells.LookAtType.EntireContent); | |
| // Find the cell with the input integer or double | |
| let cell1 = cells.find(205, null, opts); | |
| if (cell1 !== null) { | |
| console.log("Name of the cell containing the value: " + cell1.getName()); | |
| } else { | |
| console.log("Record not found "); | |
| } | |
| // Find the cell with the input string | |
| let cell2 = cells.find("Items A", null, opts); | |
| if (cell2 !== null) { | |
| console.log("Name of the cell containing the value: " + cell2.getName()); | |
| } else { | |
| console.log("Record not found "); | |
| } | |
| // Find the cell containing the input string | |
| opts.setLookAtType(AsposeCells.LookAtType.Contains); | |
| let cell3 = cells.find("Data", null, opts); | |
| if (cell3 !== null) { | |
| console.log("Name of the cell containing the value: " + cell3.getName()); | |
| } else { | |
| console.log("Record not found "); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| // Instantiate the workbook object | |
| const workbook = new AsposeCells.Workbook(sourceDir + "sampleFindingDataOrFormulasUsingFindOptions.xlsx"); | |
| workbook.calculateFormula(); | |
| // Get Cells collection | |
| const cells = workbook.getWorksheets().get(0).getCells(); | |
| // Instantiate FindOptions Object | |
| const findOptions = new AsposeCells.FindOptions(); | |
| // Create a Cells Area | |
| const ca = new AsposeCells.CellArea(); | |
| ca.startRow = 8; | |
| ca.startColumn = 2; | |
| ca.endRow = 17; | |
| ca.endColumn = 13; | |
| // Set cells area for find options | |
| findOptions.setRange(ca); | |
| // Set searching properties | |
| findOptions.setSearchBackward(false); | |
| findOptions.setSearchOrderByRows(true); | |
| // Set the lookintype, you may specify, values, formulas, comments etc. | |
| findOptions.setLookInType(AsposeCells.LookInType.Values); | |
| // Set the lookattype, you may specify Match entire content, endswith, starwith etc. | |
| findOptions.setLookAtType(AsposeCells.LookAtType.EntireContent); | |
| // Find the cell with value | |
| const cell = cells.find(341, null, findOptions); | |
| if (cell !== null) { | |
| console.log("Name of the cell containing the value: " + cell.getName()); | |
| } else { | |
| console.log("Record not found "); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook | |
| const wb = new AsposeCells.Workbook(); | |
| // Create worksheet | |
| const sheet = wb.getWorksheets().get(0); | |
| // Access cell A1 and A2 | |
| const a1 = sheet.getCells().get("A1"); | |
| const a2 = sheet.getCells().get("A2"); | |
| // Add sample in A1 and sample with quote prefix in A2 | |
| a1.putValue("sample"); | |
| a2.putValue("'sample"); | |
| // Print their string values, A1 and A2 both are same | |
| console.log("String value of A1: " + a1.getStringValue()); | |
| console.log("String value of A2: " + a2.getStringValue()); | |
| // Access styles of A1 and A2 | |
| const s1 = a1.getStyle(); | |
| const s2 = a2.getStyle(); | |
| console.log(); | |
| // Check if A1 and A2 has a quote prefix | |
| console.log("A1 has a quote prefix: " + s1.getQuotePrefix()); | |
| console.log("A2 has a quote prefix: " + s2.getQuotePrefix()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "TestBook.xlsx"); | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access the style of cell A1 | |
| const style = worksheet.getCells().get("A1").getStyle(); | |
| // Specify the style for searching | |
| const options = new AsposeCells.FindOptions(); | |
| options.setStyle(style); | |
| let nextCell = null; | |
| do { | |
| // Find the cell that has a style of cell A1 | |
| nextCell = worksheet.getCells().find(null, nextCell, options); | |
| if (nextCell === null) break; | |
| // Change the text of the cell | |
| nextCell.putValue("Found"); | |
| } while (true); | |
| const outputPath = path.join(dataDir, "output.out.xlsx"); | |
| workbook.save(outputPath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Add 10 in cell A1 and A2 | |
| worksheet.getCells().get("A1").putValue(10); | |
| worksheet.getCells().get("A2").putValue(10); | |
| // Add Sum formula in cell D4 but customize it as --- | |
| const cell = worksheet.getCells().get("D4"); | |
| let style = cell.getStyle(); | |
| style.setCustom("---"); | |
| cell.setStyle(style); | |
| // The result of formula will be 20 but 20 will not be visible because the cell is formatted as --- | |
| cell.setFormula("=Sum(A1:A2)"); | |
| // Calculate the workbook | |
| workbook.calculateFormula(); | |
| // Create find options, we will search 20 using original values otherwise 20 will never be found because it is formatted as --- | |
| const options = new AsposeCells.FindOptions(); | |
| options.setLookInType(AsposeCells.LookInType.OriginalValues); | |
| options.setLookAtType(AsposeCells.LookAtType.EntireContent); | |
| let foundCell = null; | |
| const obj = 20; | |
| // Find 20 which is Sum(A1:A2) and formatted as --- | |
| foundCell = worksheet.getCells().find(obj, foundCell, options); | |
| // Print the found cell | |
| console.log(foundCell); | |
| // Save the workbook | |
| workbook.save(path.join(dataDir, "output_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| // Create a workbook object and load template file | |
| var workbook = new AsposeCells.Workbook("CellsNet46500.xlsx"); | |
| // Instantiate data sorter object | |
| var sorter = workbook.getDataSorter(); | |
| // Add key for second column for red color | |
| sorter.addKey(1, AsposeCells.SortOnType.CellColor, AsposeCells.SortOrder.Descending, AsposeCells.Color.Red); | |
| // Sort the data based on the key | |
| sorter.sort(workbook.getWorksheets().get(0).getCells(), AsposeCells.CellArea.createCellArea("A2", "C6")); | |
| // Save the output file | |
| workbook.save("outputSortData_CustomSortList.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| //Load the source Excel file | |
| var wb = new AsposeCells.Workbook("sampleSortData_CustomSortList.xlsx"); | |
| //Access first worksheet | |
| var ws = wb.getWorksheets().get(0); | |
| //Specify cell area - sort from A1 to A40 | |
| var ca = AsposeCells.CellArea.createCellArea("A1", "A40"); | |
| //Create Custom Sort list | |
| var customSortList = ["USA,US", "Brazil,BR", "China,CN", "Russia,RU", "Canada,CA" ]; | |
| //Add Key for Column A, Sort it in Ascending Order with Custom Sort List | |
| wb.getDataSorter().addKey(0, AsposeCells.SortOrder.Ascending, customSortList); | |
| wb.getDataSorter().sort(ws.getCells(), ca); | |
| //Save the output Excel file | |
| wb.save("outputSortData_CustomSortList.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| //Create workbook. | |
| var workbook = new AsposeCells.Workbook("sampleSortAsNumber.xlsx"); | |
| //Access first worksheet. | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Create your cell area. | |
| var ca = AsposeCells.CellArea.createCellArea("A1", "A20"); | |
| //Create your sorter. | |
| var sorter = workbook.getDataSorter(); | |
| //Find the index, since we want to sort by column A, so we should know the index for sorter. | |
| var idx = AsposeCells.CellsHelper.columnNameToIndex("A"); | |
| //Add key in sorter, it will sort in Ascending order. | |
| sorter.addKey(idx, AsposeCells.SortOrder.Ascending); | |
| sorter.setSortAsNumber(true); | |
| //Perform sort. | |
| sorter.sort(worksheet.getCells(), ca); | |
| //Save the output workbook. | |
| workbook.save("outputSortAsNumber.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create a workbook. | |
| const workbook = new AsposeCells.Workbook(); | |
| // Create a new style object. | |
| const style = workbook.createStyle(); | |
| // Set the number format. | |
| style.setNumber(14); | |
| // Set the font color to red color. | |
| style.getFont().setColor(AsposeCells.Color.Red); | |
| // Name the style. | |
| style.setName("Date1"); | |
| // Get the first worksheet cells. | |
| const cells = workbook.getWorksheets().get(0).getCells(); | |
| // Specify the style (described above) to A1 cell. | |
| cells.get("A1").setStyle(style); | |
| // Create a range (B1:D1). | |
| const range = cells.createRange("B1", "D1"); | |
| // Initialize styleflag object. | |
| const flag = new AsposeCells.StyleFlag(); | |
| // Set all formatting attributes on. | |
| flag.setAll(true); | |
| // Apply the style (described above) to the range. | |
| range.applyStyle(style, flag); | |
| // Modify the style (described above) and change the font color from red to black. | |
| style.getFont().setColor(AsposeCells.Color.Black); | |
| // Done! Since the named style (described above) has been set to a cell and range, | |
| // The change would be reflected(new modification is implemented) to cell(A1) and | |
| // Range (B1:D1). | |
| style.update(); | |
| // Save the excel file. | |
| workbook.save(path.join(dataDir, "book_styles.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create a Style object using CellsFactory class | |
| const cf = new AsposeCells.CellsFactory(); | |
| const st = cf.createStyle(); | |
| // Set the Style fill color to Yellow | |
| st.setPattern(AsposeCells.BackgroundType.Solid); | |
| st.setForegroundColor(AsposeCells.Color.Yellow); | |
| // Create a workbook and set its default style using the created Style object | |
| const wb = new AsposeCells.Workbook(); | |
| wb.setDefaultStyle(st); | |
| // Save the workbook | |
| wb.save(path.join(dataDir, "output_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "book1.xlsx"); | |
| // Create a workbook. | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // We get the Percent style and create a style object. | |
| const style = workbook.getNamedStyle("Percent"); | |
| // Change the number format to "0.00%". | |
| style.setNumber(11); | |
| // Set the font color. | |
| style.getFont().setColor(AsposeCells.Color.Red); | |
| // Update the style. so, the style of range "A1:C8" will be changed too. | |
| style.update(); | |
| // Save the excel file. | |
| workbook.save(path.join(dataDir, "book2.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access cells | |
| const cell1 = worksheet.getCells().get("A1"); | |
| const cell2 = worksheet.getCells().get("B1"); | |
| // Set the styles of both cells to Times New Roman | |
| const styleObject = workbook.createStyle(); | |
| styleObject.getFont().setColor(AsposeCells.Color.Red); | |
| styleObject.getFont().setName("Times New Roman"); | |
| cell1.setStyle(styleObject); | |
| cell2.setStyle(styleObject); | |
| // Put the values inside the cell | |
| cell1.putValue("Hello World!"); | |
| cell2.putValue("Hello World!!"); | |
| // Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
| workbook.save(path.join(dataDir, "SampleOutput_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the newly added worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Row index of the cell | |
| let row = 0; | |
| // Column index of the cell | |
| let column = 0; | |
| let a1 = worksheet.getCells().get(row, column); | |
| a1.putValue("a1 rotate text"); | |
| let a1Style = a1.getStyle(); | |
| // Set the rotation angle in degrees | |
| a1Style.setRotationAngle(45); | |
| a1.setStyle(a1Style); | |
| // set Column index of the cell | |
| column = 1; | |
| let b1 = worksheet.getCells().get(row, column); | |
| b1.putValue("b1 rotate text"); | |
| let b1Style = b1.getStyle(); | |
| // Set the rotation angle in degrees | |
| b1Style.setRotationAngle(255); | |
| b1.setStyle(b1Style); | |
| // set Column index of the cell | |
| column = 2; | |
| let c1 = worksheet.getCells().get(row, column); | |
| c1.putValue("c1 rotate text"); | |
| let c1Style = c1.getStyle(); | |
| // Set the rotation angle in degrees | |
| c1Style.setRotationAngle(-90); | |
| c1.setStyle(c1Style); | |
| // set Column index of the cell | |
| column = 3; | |
| let d1 = worksheet.getCells().get(row, column); | |
| d1.putValue("d1 rotate text"); | |
| let d1Style = d1.getStyle(); | |
| // Set the rotation angle in degrees | |
| d1Style.setRotationAngle(-90); | |
| d1.setStyle(d1Style); | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const output1Path = path.join(dataDir, "Output.xlsx"); | |
| const output2Path = path.join(dataDir, "Output.out.ods"); | |
| const workbook = new AsposeCells.Workbook(); | |
| const style = workbook.createBuiltinStyle(AsposeCells.BuiltinStyleType.Title); | |
| const cell = workbook.getWorksheets().get(0).getCells().get("A1"); | |
| cell.putValue("Aspose"); | |
| cell.setStyle(style); | |
| const worksheet = workbook.getWorksheets().get(0); | |
| worksheet.autoFitColumn(0); | |
| worksheet.autoFitRow(0); | |
| workbook.save(output1Path); | |
| console.log(`File saved ${output1Path}`); | |
| workbook.save(output2Path); | |
| console.log(`File saved ${output2Path}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the first (default) worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Visit Aspose!"); | |
| // Create a style object | |
| const style = cell.getStyle(); | |
| // Setting the line style of the top border | |
| style.getBorders().get(AsposeCells.BorderType.TopBorder).setLineStyle(AsposeCells.CellBorderType.Thick); | |
| // Setting the color of the top border | |
| style.getBorders().get(AsposeCells.BorderType.TopBorder).setColor(AsposeCells.Color.Black); | |
| // Setting the line style of the bottom border | |
| style.getBorders().get(AsposeCells.BorderType.BottomBorder).setLineStyle(AsposeCells.CellBorderType.Thick); | |
| // Setting the color of the bottom border | |
| style.getBorders().get(AsposeCells.BorderType.BottomBorder).setColor(AsposeCells.Color.Black); | |
| // Setting the line style of the left border | |
| style.getBorders().get(AsposeCells.BorderType.LeftBorder).setLineStyle(AsposeCells.CellBorderType.Thick); | |
| // Setting the color of the left border | |
| style.getBorders().get(AsposeCells.BorderType.LeftBorder).setColor(AsposeCells.Color.Black); | |
| // Setting the line style of the right border | |
| style.getBorders().get(AsposeCells.BorderType.RightBorder).setLineStyle(AsposeCells.CellBorderType.Thick); | |
| // Setting the color of the right border | |
| style.getBorders().get(AsposeCells.BorderType.RightBorder).setColor(AsposeCells.Color.Black); | |
| // Apply the border styles to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)){ | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the first (default) worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello World From Aspose"); | |
| // Creating a range of cells starting from "A1" cell to 3rd column in a row | |
| const range = worksheet.getCells().createRange(0, 0, 1, 3); | |
| // Adding a thick top border with blue line | |
| range.setOutlineBorder(AsposeCells.BorderType.TopBorder, AsposeCells.CellBorderType.Thick, AsposeCells.Color.Blue); | |
| // Adding a thick bottom border with blue line | |
| range.setOutlineBorder(AsposeCells.BorderType.BottomBorder, AsposeCells.CellBorderType.Thick, AsposeCells.Color.Blue); | |
| // Adding a thick left border with blue line | |
| range.setOutlineBorder(AsposeCells.BorderType.LeftBorder, AsposeCells.CellBorderType.Thick, AsposeCells.Color.Blue); | |
| // Adding a thick right border with blue line | |
| range.setOutlineBorder(AsposeCells.BorderType.RightBorder, AsposeCells.CellBorderType.Thick, AsposeCells.Color.Blue); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const sourceDir = path.join(__dirname, "data"); | |
| const outputDir = path.join(__dirname, "output"); | |
| // Load sample Excel file containing cells with formatting. | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleChangeCellsAlignmentAndKeepExistingFormatting.xlsx")); | |
| // Access first worksheet. | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Create cells range. | |
| const range = worksheet.getCells().createRange("B2:D7"); | |
| // Create style object. | |
| const style = workbook.createStyle(); | |
| // Set the horizontal and vertical alignment to center. | |
| style.setHorizontalAlignment(AsposeCells.TextAlignmentType.Center); | |
| style.setVerticalAlignment(AsposeCells.TextAlignmentType.Center); | |
| // Create style flag object. | |
| const flag = new AsposeCells.StyleFlag(); | |
| flag.setAlignments(true); // Set style flag alignments true. It is most crucial statement. | |
| // Apply style to range of cells. | |
| range.applyStyle(style, flag); | |
| // Save the workbook in XLSX format. | |
| workbook.save(path.join(outputDir, "outputChangeCellsAlignmentAndKeepExistingFormatting.xlsx"), AsposeCells.SaveFormat.Xlsx); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Visit Aspose!"); | |
| // Setting the horizontal alignment of the text in the "A1" cell | |
| const style = cell.getStyle(); | |
| style.setHorizontalAlignment(AsposeCells.TextAlignmentType.Center); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Visit Aspose!"); | |
| // Setting the horizontal alignment of the text in the "A1" cell | |
| const style = cell.getStyle(); | |
| // Setting the indentation level of the text (inside the cell) to 2 | |
| style.setIndentLevel(2); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Create a Workbook. | |
| const wbk = new AsposeCells.Workbook(); | |
| // Create a Worksheet and get the first sheet. | |
| const worksheet = wbk.getWorksheets().get(0); | |
| // Create a Cells object to fetch all the cells. | |
| const cells = worksheet.getCells(); | |
| // Merge some Cells (C6:E7) into a single C6 Cell. | |
| cells.merge(5, 2, 2, 3); | |
| // Input data into C6 Cell. | |
| cells.get(5, 2).putValue("This is my value"); | |
| // Create a Style object to fetch the Style of C6 Cell. | |
| const style = cells.get(5, 2).getStyle(); | |
| // Create a Font object | |
| const font = style.getFont(); | |
| // Set the name. | |
| font.setName("Times New Roman"); | |
| // Set the font size. | |
| font.setSize(18); | |
| // Set the font color | |
| font.setColor(AsposeCells.Color.Blue); | |
| // Bold the text | |
| font.setIsBold(true); | |
| // Make it italic | |
| font.setIsItalic(true); | |
| // Set the background color of C6 Cell to Red | |
| style.setForegroundColor(AsposeCells.Color.Red); | |
| style.setPattern(AsposeCells.BackgroundType.Solid); | |
| // Apply the Style to C6 Cell. | |
| cells.get(5, 2).setStyle(style); | |
| // Save the Workbook. | |
| wbk.save(path.join(dataDir, "mergingcells.out.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Visit Aspose!"); | |
| // Setting the horizontal alignment of the text in the "A1" cell | |
| const style = cell.getStyle(); | |
| // Setting the rotation of the text (inside the cell) to 25 | |
| style.setRotationAngle(25); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Visit Aspose!"); | |
| // Setting the horizontal alignment of the text in the "A1" cell | |
| const style = cell.getStyle(); | |
| // Shrinking the text to fit according to the dimensions of the cell | |
| style.setShrinkToFit(true); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Instantiating a Workbook object | |
| // Obtaining the reference of first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("I am using the latest version of Aspose.Cells to test this functionality."); | |
| // Gets style in the "A1" cell | |
| const style = cell.getStyle(); | |
| // Shrinking the text to fit according to the dimensions of the cell | |
| style.setTextDirection(AsposeCells.TextDirectionType.LeftToRight); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save("book1.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create Workbook Object | |
| const wb = new AsposeCells.Workbook(); | |
| // Open first Worksheet in the workbook | |
| const ws = wb.getWorksheets().get(0); | |
| // Get Worksheet Cells Collection | |
| const cell = ws.getCells(); | |
| // Increase the width of First Column Width | |
| cell.setColumnWidth(0, 35); | |
| // Increase the height of first row | |
| cell.setRowHeight(0, 65); | |
| // Add Text to the First Cell with Explicit Line Breaks | |
| cell.checkCell(0, 0).putValue("I am using\nthe latest version of \nAspose.Cells to \ntest this functionality"); | |
| // Make Cell's Text wrap | |
| const style = cell.checkCell(0, 0).getStyle(); | |
| style.setIsTextWrapped(true); | |
| cell.checkCell(0, 0).setStyle(style); | |
| // Save Excel File | |
| wb.save(path.join(dataDir, "WrappingText.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Clearing all the worksheets | |
| workbook.getWorksheets().clear(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Visit Aspose!"); | |
| // Setting the horizontal alignment of the text in the "A1" cell | |
| const style = cell.getStyle(); | |
| // Setting the vertical alignment of the text in a cell | |
| style.setVerticalAlignment(AsposeCells.TextAlignmentType.Center); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create Workbook Object | |
| const wb = new AsposeCells.Workbook(); | |
| // Open first Worksheet in the workbook | |
| const ws = wb.getWorksheets().get(0); | |
| // Get Worksheet Cells Collection | |
| const cell = ws.getCells(); | |
| // Increase the width of First Column Width | |
| cell.setColumnWidth(0, 35); | |
| // Increase the height of first row | |
| cell.setRowHeight(0, 36); | |
| // Add Text to the First Cell | |
| cell.checkCell(0, 0).putValue("I am using the latest version of Aspose.Cells to test this functionality"); | |
| // Make Cell's Text wrap | |
| const style = cell.checkCell(0, 0).getStyle(); | |
| style.setIsTextWrapped(true); | |
| cell.checkCell(0, 0).setStyle(style); | |
| // Save Excel File | |
| wb.save(path.join(dataDir, "WrappingText.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create Workbook Object | |
| const wb = new AsposeCells.Workbook(); | |
| // Open first Worksheet in the workbook | |
| const ws = wb.getWorksheets().get(0); | |
| // Get Worksheet Cells Collection | |
| const cell = ws.getCells(); | |
| // Increase the width of First Column Width | |
| cell.setColumnWidth(0, 35); | |
| // Increase the height of first row | |
| cell.setRowHeight(0, 36); | |
| // Add Text to the First Cell | |
| cell.checkCell(0, 0).putValue("I am using the latest version of Aspose.Cells to test this functionality"); | |
| // Make Cell's Text wrap | |
| const style = cell.checkCell(0, 0).getStyle(); | |
| style.setIsTextWrapped(true); | |
| cell.checkCell(0, 0).setStyle(style); | |
| // Save Excel File | |
| wb.save(path.join(dataDir, "WrappingText.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Get the first worksheet | |
| const ws = workbook.getWorksheets().get(0); | |
| const cells = ws.getCells(); | |
| // Setting the value to the cells | |
| let cell = cells.get("A1"); | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Price"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| cell = cells.get("B2"); | |
| cell.putValue(5); | |
| cell = cells.get("B3"); | |
| cell.putValue(3); | |
| cell = cells.get("B4"); | |
| cell.putValue(6); | |
| cell = cells.get("B5"); | |
| cell.putValue(4); | |
| cell = cells.get("C2"); | |
| cell.putValue(5); | |
| cell = cells.get("C3"); | |
| cell.putValue(20); | |
| cell = cells.get("C4"); | |
| cell.putValue(30); | |
| cell = cells.get("C5"); | |
| cell.putValue(60); | |
| // Access the worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| const a2 = worksheet.getCells().get("A2"); | |
| // Get style of A2 | |
| const style = a2.getStyle(); | |
| // Change the format | |
| style.getFont().setColor(AsposeCells.Color.Red); | |
| style.getFont().setIsBold(true); | |
| const flag = new AsposeCells.StyleFlag(); | |
| flag.setFontColor(true); | |
| a2.setStyle(style, flag); | |
| const b3 = worksheet.getCells().get("B3"); | |
| // Get style of B3 | |
| const style2 = b3.getStyle(); | |
| // Change the format | |
| style2.getFont().setColor(AsposeCells.Color.Blue); | |
| style2.getFont().setIsItalic(true); | |
| b3.setStyle(style2); | |
| // Save the modified workbook | |
| workbook.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Checks if a color is in the palette for the spreadsheet. | |
| console.log(workbook.isColorInPalette(AsposeCells.Color.Orchid)); | |
| // Adding Orchid color to the palette at 55th index | |
| workbook.changePalette(AsposeCells.Color.Orchid, 55); | |
| console.log(workbook.isColorInPalette(AsposeCells.Color.Orchid)); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Defining new Style object | |
| const styleObject = workbook.createStyle(); | |
| // Setting the Orchid (custom) color to the font | |
| styleObject.getFont().setColor(workbook.getColors()[55]); | |
| // Applying the style to the cell | |
| cell.setStyle(styleObject); | |
| // Saving the Excel file | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Create workbook | |
| const workbook = new AsposeCells.Workbook(); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Add some data in cells | |
| worksheet.getCells().get("A1").putValue("2-Color Scale"); | |
| worksheet.getCells().get("D1").putValue("3-Color Scale"); | |
| for (let i = 2; i <= 15; i++) { | |
| worksheet.getCells().get("A" + i).putValue(i); | |
| worksheet.getCells().get("D" + i).putValue(i); | |
| } | |
| // Adding 2-Color Scale Conditional Formatting | |
| let ca = AsposeCells.CellArea.createCellArea("A2", "A15"); | |
| let idx = worksheet.getConditionalFormattings().add(); | |
| let fcc = worksheet.getConditionalFormattings().get(idx); | |
| fcc.addCondition(AsposeCells.FormatConditionType.ColorScale); | |
| fcc.addArea(ca); | |
| let fc = worksheet.getConditionalFormattings().get(idx).get(0); | |
| fc.getColorScale().setIs3ColorScale(false); | |
| fc.getColorScale().setMaxColor(AsposeCells.Color.LightBlue); | |
| fc.getColorScale().setMinColor(AsposeCells.Color.LightGreen); | |
| // Adding 3-Color Scale Conditional Formatting | |
| ca = AsposeCells.CellArea.createCellArea("D2", "D15"); | |
| idx = worksheet.getConditionalFormattings().add(); | |
| fcc = worksheet.getConditionalFormattings().get(idx); | |
| fcc.addCondition(AsposeCells.FormatConditionType.ColorScale); | |
| fcc.addArea(ca); | |
| fc = worksheet.getConditionalFormattings().get(idx).get(0); | |
| fc.getColorScale().setIs3ColorScale(true); | |
| fc.getColorScale().setMaxColor(AsposeCells.Color.LightBlue); | |
| fc.getColorScale().setMidColor(AsposeCells.Color.Yellow); | |
| fc.getColorScale().setMinColor(AsposeCells.Color.LightGreen); | |
| // Save the workbook | |
| workbook.save(path.join(dataDir, "output_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "Book1.xlsx"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Adds an empty conditional formatting | |
| const index = sheet.getConditionalFormattings().getCount(); | |
| const fcs = sheet.getConditionalFormattings().get(index); | |
| // Sets the conditional format range. | |
| let ca = AsposeCells.CellArea.createCellArea(0, 0, 0, 0); | |
| fcs.addArea(ca); | |
| ca = AsposeCells.CellArea.createCellArea(1, 1, 1, 1); | |
| fcs.addArea(ca); | |
| // Adds condition. | |
| const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "=A2", "100"); | |
| // Adds condition. | |
| const conditionIndex2 = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
| // Sets the background color. | |
| const fc = fcs.get(conditionIndex); | |
| fc.getStyle().setBackgroundColor(AsposeCells.Color.Red); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "output.xls")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create an instance of Workbook or load existing | |
| const book = new AsposeCells.Workbook(); | |
| // Access the Worksheet on which desired rule has to be applied | |
| const sheet = book.getWorksheets().get(0); | |
| // Add FormatConditions to the instance of Worksheet | |
| let idx = sheet.getConditionalFormattings().add(); | |
| // Access the newly added FormatConditions via its index | |
| const conditionCollection = sheet.getConditionalFormattings().get(idx); | |
| // Define a CellsArea on which conditional formatting will be applicable | |
| // The code creates a CellArea ranging from A1 to I20 | |
| const area = AsposeCells.CellArea.createCellArea("A1", "I20"); | |
| // Add area to the instance of FormatConditions | |
| conditionCollection.addArea(area); | |
| // Add a condition to the instance of FormatConditions | |
| // For this case, the condition type is expression, which is based on some formula | |
| idx = conditionCollection.addCondition(AsposeCells.FormatConditionType.Expression); | |
| // Access the newly added FormatCondition via its index | |
| const formatCondition = conditionCollection.get(idx); | |
| // Set the formula for the FormatCondition | |
| formatCondition.setFormula1("=MOD(ROW(),2)=0"); | |
| // Set the background color and pattern for the FormatCondition's Style | |
| formatCondition.getStyle().setBackgroundColor(AsposeCells.Color.Blue); | |
| formatCondition.getStyle().setPattern(AsposeCells.BackgroundType.Solid); | |
| // Save the result on disk | |
| book.save(path.join(dataDir, "output_out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const outputFilePath = path.join(dataDir, "output.out.xls"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Adds an empty conditional formatting | |
| const index = sheet.getConditionalFormattings().getCount(); | |
| // Get the collection of conditional formatting | |
| const fcs = sheet.getConditionalFormattings(); | |
| // Sets the conditional format range. | |
| const ca = AsposeCells.CellArea.createCellArea(0, 0, 0, 0); | |
| fcs.addArea(ca); | |
| // Adds condition. | |
| const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
| // Sets the background color. | |
| const fc = fcs.get(conditionIndex); | |
| fc.getStyle().setBackgroundColor(AsposeCells.Color.Red); | |
| // Saving the Excel file | |
| workbook.save(outputFilePath, AsposeCells.SaveFormat.Auto); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Adds an empty conditional formatting | |
| const index = sheet.getConditionalFormattings().getCount(); | |
| sheet.getConditionalFormattings().add(); | |
| // Gets the conditional format collection | |
| const fcs = sheet.getConditionalFormattings().get(index); | |
| // Sets the conditional format range. | |
| const ca = AsposeCells.CellArea.createCellArea(2, 1, 2, 1); | |
| fcs.addArea(ca); | |
| // Adds condition. | |
| const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.Expression); | |
| // Sets the background color. | |
| const fc = fcs.get(conditionIndex); | |
| fc.setFormula1("=IF(SUM(B1:B2)>100,TRUE,FALSE)"); | |
| fc.getStyle().setBackgroundColor(AsposeCells.Color.Red); | |
| sheet.getCells().get("B3").setFormula("=SUM(B1:B2)"); | |
| sheet.getCells().get("C4").putValue("If Sum of B1:B2 is greater than 100, B3 will have RED background"); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "output.out.xls"), AsposeCells.SaveFormat.Auto); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Open a template Excel file | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xlsx")); | |
| // Get the first worksheet in the workbook | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Get the A1 cell | |
| const cell = sheet.getCells().get("A1"); | |
| // Get the conditional formatting result object | |
| const cfr = cell.getConditionalFormattingResult(); | |
| // Get the icon set | |
| const icon = cfr.getConditionalFormattingIcon(); | |
| // Create the image file based on the icon's image data | |
| require("fs").writeFileSync(path.join(dataDir, "imgIcon.out.jpg"), icon.getImageData()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const fs = require("fs"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // Source directory | |
| const sourceDir = RunExamples.Get_SourceDirectory(); | |
| // Output directory | |
| const outputDir = RunExamples.Get_OutputDirectory(); | |
| // Create workbook object from source excel file | |
| const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleGenerateDatabarImage.xlsx")); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell which contains conditional formatting databar | |
| const cell = worksheet.getCells().get("C1"); | |
| // Create and get the conditional formatting of the worksheet | |
| const idx = worksheet.getConditionalFormattings().add(); | |
| const fcc = worksheet.getConditionalFormattings().get(idx); | |
| fcc.addCondition(AsposeCells.FormatConditionType.DataBar); | |
| fcc.addArea(AsposeCells.CellArea.createCellArea("C1", "C4")); | |
| // Access the conditional formatting databar | |
| const dbar = fcc.get(0).getDataBar(); | |
| // Create image or print options | |
| const opts = new AsposeCells.ImageOrPrintOptions(); | |
| opts.setImageType(AsposeCells.ImageType.Png); | |
| // Get the image bytes of the databar | |
| const imgBytes = dbar.toImage(cell, opts); | |
| // Write image bytes on the disk | |
| fs.writeFileSync(path.join(outputDir, "outputGenerateDatabarImage.png"), imgBytes); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Open a template Excel file | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xlsx")); | |
| // Get the first worksheet in the workbook | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Get the A1 cell | |
| const cell = sheet.getCells().get("A1"); | |
| // Get the conditional formatting result object | |
| const cfr = cell.getConditionalFormattingResult(); | |
| // Get the icon set | |
| const icon = cfr.getConditionalFormattingIcon(); | |
| // Create the image file based on the icon's image data | |
| require("fs").writeFileSync(path.join(dataDir, "imgIcon.out.jpg"), icon.getImageData()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Adds an empty conditional formatting | |
| const index = sheet.getConditionalFormattings().add(); | |
| const fcs = sheet.getConditionalFormattings().get(index); | |
| // Sets the conditional format range. | |
| const ca = AsposeCells.CellArea.createCellArea(0, 0, 5, 3); | |
| fcs.addArea(ca); | |
| // Adds condition. | |
| const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
| // Sets the background color. | |
| const fc = fcs.get(conditionIndex); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.LeftBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.RightBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.TopBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.BottomBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.LeftBorder).setColor(new AsposeCells.Color(0, 255, 255)); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.RightBorder).setColor(new AsposeCells.Color(0, 255, 255)); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.TopBorder).setColor(new AsposeCells.Color(0, 255, 255)); | |
| fc.getStyle().getBorders().get(AsposeCells.BorderType.BottomBorder).setColor(new AsposeCells.Color(255, 255, 0)); | |
| workbook.save(path.join(dataDir, "output.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Open a template Excel file | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xlsx")); | |
| // Get the first worksheet in the workbook | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Get the A1 cell | |
| const cell = sheet.getCells().get("A1"); | |
| // Get the conditional formatting result object | |
| const cfr = cell.getConditionalFormattingResult(); | |
| // Get the icon set | |
| const icon = cfr.getConditionalFormattingIcon(); | |
| // Create the image file based on the icon's image data | |
| require("fs").writeFileSync(path.join(dataDir, "imgIcon.out.jpg"), icon.getImageData()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| const sheet = workbook.getWorksheets().get(0); | |
| // Adds an empty conditional formatting | |
| const index = sheet.getConditionalFormattings().add(); | |
| const fcs = sheet.getConditionalFormattings().get(index); | |
| // Sets the conditional format range. | |
| const ca = AsposeCells.CellArea.createCellArea(0, 0, 5, 3); | |
| fcs.addArea(ca); | |
| // Adds condition. | |
| const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
| const fc = fcs.get(conditionIndex); | |
| fc.getStyle().setPattern(AsposeCells.BackgroundType.ReverseDiagonalStripe); | |
| fc.getStyle().setForegroundColor(new AsposeCells.Color(255, 255, 0)); | |
| fc.getStyle().setBackgroundColor(new AsposeCells.Color(0, 255, 255)); | |
| workbook.save(path.join(dataDir, "output.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Checks if a color is in the palette for the spreadsheet. | |
| console.log(workbook.isColorInPalette(AsposeCells.Color.Orchid)); | |
| // Adding Orchid color to the palette at 55th index | |
| workbook.changePalette(AsposeCells.Color.Orchid, 55); | |
| console.log(workbook.isColorInPalette(AsposeCells.Color.Orchid)); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Defining new Style object | |
| const styleObject = workbook.createStyle(); | |
| // Setting the Orchid (custom) color to the font | |
| styleObject.getFont().setColor(workbook.getColors()[55]); | |
| // Applying the style to the cell | |
| cell.setStyle(styleObject); | |
| // Saving the Excel file | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Loads the workbook which contains hidden external links | |
| const workbook = new AsposeCells.Workbook(); | |
| // Get the first worksheet (default) in the workbook | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Input a value into B3 cell | |
| worksheet.getCells().get(2, 1).putValue("test"); | |
| // Get the Style of the cell | |
| const style = worksheet.getCells().get("B3").getStyle(); | |
| // Set Gradient pattern on | |
| style.setIsGradient(true); | |
| // Specify two color gradient fill effects | |
| style.setTwoColorGradient(new AsposeCells.Color(255, 255, 255), new AsposeCells.Color(79, 129, 189), AsposeCells.GradientStyleType.Horizontal, 1); | |
| // Set the color of the text in the cell | |
| style.getFont().setColor(AsposeCells.Color.Red); | |
| // Specify horizontal and vertical alignment settings | |
| style.setHorizontalAlignment(AsposeCells.TextAlignmentType.Center); | |
| style.setVerticalAlignment(AsposeCells.TextAlignmentType.Center); | |
| // Apply the style to the cell | |
| worksheet.getCells().get("B3").setStyle(style); | |
| // Set the third row height in pixels | |
| worksheet.getCells().setRowHeightPixel(2, 53); | |
| // Merge the range of cells (B3:C3) | |
| worksheet.getCells().merge(2, 1, 1, 2); | |
| // Save the Excel file | |
| workbook.save(path.join(dataDir, "output.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)){ | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Workbook object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Define a Style and get the A1 cell style | |
| let style = worksheet.getCells().get("A1").getStyle(); | |
| // Setting the foreground color to yellow | |
| style.setForegroundColor(AsposeCells.Color.Yellow); | |
| // Setting the background pattern to vertical stripe | |
| style.setPattern(AsposeCells.BackgroundType.VerticalStripe); | |
| // Apply the style to A1 cell | |
| worksheet.getCells().get("A1").setStyle(style); | |
| // Get the A2 cell style | |
| style = worksheet.getCells().get("A2").getStyle(); | |
| // Setting the foreground color to blue | |
| style.setForegroundColor(AsposeCells.Color.Blue); | |
| // Setting the background color to yellow | |
| style.setBackgroundColor(AsposeCells.Color.Yellow); | |
| // Setting the background pattern to vertical stripe | |
| style.setPattern(AsposeCells.BackgroundType.VerticalStripe); | |
| // Apply the style to A2 cell | |
| worksheet.getCells().get("A2").setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require('fs'); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello"); | |
| // Setting the font Subscript | |
| const style = cell.getStyle(); | |
| style.getFont().setIsSubscript(true); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "Subscript.out.xls"), AsposeCells.SaveFormat.Auto); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello"); | |
| // Setting the font Superscript | |
| const style = cell.getStyle(); | |
| style.getFont().setIsSuperscript(true); | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "Superscript.out.xls"), AsposeCells.SaveFormat.Auto); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Load source workbook | |
| const workbook = new AsposeCells.Workbook(path.join(dataDir, "sampleGetFonts.xlsx")); | |
| // Get all the fonts inside the workbook | |
| const fonts = workbook.getFonts(); | |
| // Print all the fonts | |
| for (let i = 0; i < fonts.length; i++) { | |
| console.log(fonts[i].toString()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting the font weight to bold | |
| style.getFont().setIsBold(true); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting the font color to blue | |
| style.getFont().setColor(AsposeCells.Color.Blue); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| const fs = require("fs"); | |
| if (!fs.existsSync(dataDir)) { | |
| fs.mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting the font name to "Times New Roman" | |
| style.getFont().setName("Times New Roman"); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "sample.xlsx"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().getCount(); | |
| workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting the font size to 14 | |
| style.getFont().setSize(14); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting the strike out effect on the font | |
| style.getFont().setIsStrikeout(true); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const path = require("path"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const outputPath = path.join(dataDir, "out.xlsx"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)){ | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting the font to be underlined | |
| style.getFont().setUnderline(AsposeCells.FontUnderlineType.Single); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(outputPath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting subscript effect | |
| style.getFont().setIsSubscript(true); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Instantiating a Workbook object | |
| const workbook = new AsposeCells.Workbook(); | |
| // Adding a new worksheet to the Excel object | |
| const i = workbook.getWorksheets().add(); | |
| // Obtaining the reference of the newly added worksheet by passing its sheet index | |
| const worksheet = workbook.getWorksheets().get(i); | |
| // Accessing the "A1" cell from the worksheet | |
| const cell = worksheet.getCells().get("A1"); | |
| // Adding some value to the "A1" cell | |
| cell.putValue("Hello Aspose!"); | |
| // Obtaining the style of the cell | |
| const style = cell.getStyle(); | |
| // Setting superscript effect | |
| style.getFont().setIsSuperscript(true); | |
| // Applying the style to the cell | |
| cell.setStyle(style); | |
| // Saving the Excel file | |
| workbook.save(path.join(dataDir, "out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var cell = worksheet.getCells().get("A1"); | |
| // Put some numeric value in the cell | |
| cell.putValue(1234.56); | |
| // Get the style of the cell | |
| var style = cell.getStyle(); | |
| // Set the number format to accounting. | |
| // The format code "_(\$* #,##0.00_);_(\$* (#,##0.00);_(\$* \"-\"??_);_(@_)" is an example for US currency. | |
| // You might need to adjust the format code according to your specific requirements and locale. | |
| style.setCustom("_(\\$* #,##0.00_);_(\\$* (#,##0.00);_(\\$* \"-\"??_);_(@_)"); | |
| // Apply the style to the cell | |
| cell.setStyle(style); | |
| // Save the workbook | |
| workbook.save("FormattedWorkbook.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var a1 = worksheet.getCells().get("A1"); | |
| // Set a numeric value to the cell | |
| a1.putValue(1234.56); | |
| // Create a style object to apply the currency format | |
| var a1Style = a1.getStyle(); | |
| // "7" is the currency format in Excel | |
| a1Style.setNumber(7); | |
| // Apply the style to the cell | |
| a1.setStyle(a1Style); | |
| // Access the cell where you want to apply the currency format | |
| var a2 = worksheet.getCells().get("A2"); | |
| // Set a numeric value to the cell | |
| a2.putValue(3456.78); | |
| // Create a style object to apply the currency format | |
| var a2Style = a2.getStyle(); | |
| // Custom format for dollar currency | |
| a2Style.setCustom("$#,##0.00"); | |
| // Apply the style to the cell | |
| a2.setStyle(a2Style); | |
| // Save the workbook | |
| workbook.save("CurrencyFormatted.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var a1 = worksheet.getCells().get("A1"); | |
| // Set a numeric value that represents a date (e.g., 44210 represents 09/06/2021 in Excel) | |
| a1.putValue(44210); | |
| // Create a style object to apply the date format | |
| var a1Style = a1.getStyle(); | |
| // "14" represents a standard date format in Excel (MM/DD/YYYY) | |
| a1Style.setNumber(14); | |
| // Apply the style to the cell | |
| a1.setStyle(a1Style); | |
| // Access the cell where you want to apply the currency format | |
| var a2 = worksheet.getCells().get("A2"); | |
| // Set a numeric value to the cell | |
| a2.putValue(44210); | |
| // Create a style object to apply the date format | |
| var a2Style = a2.getStyle(); | |
| // Custom format for YYYY-MM-DD | |
| a2Style.setCustom("YYYY-MM-DD"); | |
| // Apply the style to the cell | |
| a2.setStyle(a2Style); | |
| // Save the workbook | |
| workbook.save("DateFormatted.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var cell = worksheet.getCells().get("A1"); | |
| // Set the cell value | |
| cell.putValue(0.5); | |
| // Get the style of the cell | |
| var style = cell.getStyle(); | |
| // Set the number format to fraction (e.g., "# ?/?") | |
| style.setCustom("# ?/?"); | |
| // Apply the style to the cell | |
| cell.setStyle(style); | |
| // Save the workbook | |
| workbook.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var cell = worksheet.getCells().get("A1"); | |
| // Set the cell value | |
| cell.putValue(0.25); | |
| // Get the cell's style | |
| var style = cell.getStyle(); | |
| // Set the number format to percentage | |
| style.setNumber(9);// Number 9 corresponds to the percentage format | |
| // Apply the style to the cell | |
| cell.setStyle(style); | |
| // Save the workbook to a file | |
| workbook.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var cell = worksheet.getCells().get("A1"); | |
| // Set the value of the cell | |
| cell.putValue(12345.6789); // The second parameter ensures the value is set as a number | |
| // Get the cell's style | |
| var style = cell.getStyle(); | |
| // Set the custom format of the cell to scientific notation | |
| style.setCustom("0.00E+00"); | |
| // Apply the style to the cell | |
| cell.setStyle(style); | |
| // Save the workbook to a file | |
| workbook.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var cell = worksheet.getCells().get("A1"); | |
| // Set the value of the cell | |
| cell.putValue(1234567890); // Example value | |
| // Get the style of the cell | |
| var style = cell.getStyle(); | |
| // Set the custom number format | |
| // For example, format as a phone number | |
| style.setCustom("(###) ###-####"); | |
| // Apply the style to the cell | |
| cell.setStyle(style); | |
| // Save the workbook | |
| workbook.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Create a new workbook | |
| var workbook = new AsposeCells.Workbook(); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the cell you want to format | |
| var cell = worksheet.getCells().get("A1"); | |
| // Put a numeric value representing time in the cell | |
| // For example, 0.5 represents 12 hours (half a day) | |
| cell.putValue(0.5); | |
| // Get the style of the cell | |
| var style = cell.getStyle(); | |
| // Set the custom number format for time (HH:MM) | |
| style.setCustom("HH:MM"); | |
| // Apply the style to the cell | |
| cell.setStyle(style); | |
| workbook.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| // Create directory if it is not already present. | |
| if (!require("fs").existsSync(dataDir)) { | |
| require("fs").mkdirSync(dataDir); | |
| } | |
| // Instantiate a Workbook. | |
| const workbook = new AsposeCells.Workbook(); | |
| // Get cells collection in the first (default) worksheet. | |
| const cells = workbook.getWorksheets().get(0).getCells(); | |
| // Get the D3 cell. | |
| const c = cells.get("D3"); | |
| // Get the style of the cell. | |
| const s = c.getStyle(); | |
| // Set foreground color for the cell from the default theme Accent2 color. | |
| s.setForegroundThemeColor(new AsposeCells.ThemeColor(AsposeCells.ThemeColorType.Accent2, 0.5)); | |
| // Set the pattern type. | |
| s.setPattern(AsposeCells.BackgroundType.Solid); | |
| // Get the font for the style. | |
| const f = s.getFont(); | |
| // Set the theme color. | |
| f.setThemeColor(new AsposeCells.ThemeColor(AsposeCells.ThemeColorType.Accent4, 0.1)); | |
| // Apply style. | |
| c.setStyle(s); | |
| // Put a value. | |
| c.putValue("Testing1"); | |
| // Save the excel file. | |
| workbook.save(path.join(dataDir, "output.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "book1.xlsx"); | |
| // Define Color array (of 12 colors) for Theme. | |
| const carr = [ | |
| new AsposeCells.Color("AntiqueWhite"), // Background1 | |
| new AsposeCells.Color("Brown"), // Text1 | |
| new AsposeCells.Color("AliceBlue"), // Background2 | |
| new AsposeCells.Color("Yellow"), // Text2 | |
| new AsposeCells.Color("YellowGreen"), // Accent1 | |
| new AsposeCells.Color("Red"), // Accent2 | |
| new AsposeCells.Color("Pink"), // Accent3 | |
| new AsposeCells.Color("Purple"), // Accent4 | |
| new AsposeCells.Color("PaleGreen"), // Accent5 | |
| new AsposeCells.Color("Orange"), // Accent6 | |
| new AsposeCells.Color("Green"), // Hyperlink | |
| new AsposeCells.Color("Gray") // Followed Hyperlink | |
| ]; | |
| // Instantiate a Workbook. | |
| // Open the template file. | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Set the custom theme with specified colors. | |
| workbook.customTheme("CustomeTheme1", carr); | |
| // Save as the excel file. | |
| workbook.save(path.join(dataDir, "output.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "source.xlsx"); | |
| // Create workbook object | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Extract theme name applied to this workbook | |
| console.log(workbook.getTheme()); | |
| // Access first worksheet | |
| const worksheet = workbook.getWorksheets().get(0); | |
| // Access cell A1 | |
| const cell = worksheet.getCells().get("A1"); | |
| // Get the style object | |
| const style = cell.getStyle(); | |
| if (style.getForegroundThemeColor() != null) { | |
| // Extract theme color applied to this cell if theme has foreground theme color defined | |
| console.log(style.getForegroundThemeColor().getColorType()); | |
| } else { | |
| console.log("Theme has not foreground color defined."); | |
| } | |
| // Extract theme color applied to the bottom border of the cell if theme has border color defined | |
| const bot = style.getBorders().getBorder(AsposeCells.BorderType.BottomBorder); | |
| if (bot.getThemeColor() != null) { | |
| console.log(bot.getThemeColor().getColorType()); | |
| } else { | |
| console.log("Theme has not Border color defined."); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "book1.xlsx"); | |
| // Instantiate Workbook object. | |
| // Open an existing excel file. | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| // Get the Background1 theme color. | |
| let c = workbook.getThemeColor(AsposeCells.ThemeColorType.Background1); | |
| // Print the color. | |
| console.log("theme color Background1: ", c); | |
| // Get the Accent2 theme color. | |
| c = workbook.getThemeColor(AsposeCells.ThemeColorType.Accent2); | |
| // Print the color. | |
| console.log("theme color Accent2: ", c); | |
| // Change the Background1 theme color. | |
| workbook.setThemeColor(AsposeCells.ThemeColorType.Background1, AsposeCells.Color.Red); | |
| // Get the updated Background1 theme color. | |
| c = workbook.getThemeColor(AsposeCells.ThemeColorType.Background1); | |
| // Print the updated color for confirmation. | |
| console.log("theme color Background1 changed to: ", c); | |
| // Change the Accent2 theme color. | |
| workbook.setThemeColor(AsposeCells.ThemeColorType.Accent2, AsposeCells.Color.Blue); | |
| // Get the updated Accent2 theme color. | |
| c = workbook.getThemeColor(AsposeCells.ThemeColorType.Accent2); | |
| // Print the updated color for confirmation. | |
| console.log("theme color Accent2 changed to: ", c); | |
| // Save the updated file. | |
| workbook.save(path.join(dataDir, "output.out.xlsx")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "Book1.xlsx"); | |
| // Instantiate a new LoadOptions. | |
| const options = new AsposeCells.LoadOptions(); | |
| // Sets the customer's region | |
| options.setRegion(AsposeCells.CountryCode.Japan); | |
| // Instantiate a new Workbook. | |
| const workbook = new AsposeCells.Workbook(filePath, options); | |
| const defaultStyle = workbook.getDefaultStyle(); | |
| // Gets customer's local font. | |
| const localFontName = defaultStyle.getFont().getName(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const AsposeCells = require("aspose.cells.node"); | |
| // The path to the documents directory. | |
| const dataDir = path.join(__dirname, "data"); | |
| const filePath = path.join(dataDir, "Book1.xlsx"); | |
| // Loads the workbook | |
| const workbook = new AsposeCells.Workbook(filePath); | |
| let defaultStyle = workbook.getDefaultStyle(); | |
| let schemeType = defaultStyle.getFont().getSchemeType(); | |
| if (schemeType === AsposeCells.FontSchemeType.Major || schemeType === AsposeCells.FontSchemeType.Minor) { | |
| console.log("It's theme font"); | |
| } | |
| // Change theme font to normal font | |
| defaultStyle.getFont().setSchemeType(AsposeCells.FontSchemeType.None); | |
| workbook.setDefaultStyle(defaultStyle); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| var workbook = new AsposeCells.Workbook(AsposeCells.FileFormatType.Xlsx); | |
| var cells = workbook.getWorksheets().get(0).getCells(); | |
| var cell = cells.get("A1"); | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Price"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| cell = cells.get("B2"); | |
| cell.putValue(5); | |
| cell = cells.get("B3"); | |
| cell.putValue(3); | |
| cell = cells.get("B4"); | |
| cell.putValue(6); | |
| cell = cells.get("B5"); | |
| cell.putValue(4); | |
| cell = cells.get("C2"); | |
| cell.putValue(5); | |
| cell = cells.get("C3"); | |
| cell.putValue(20); | |
| cell = cells.get("C4"); | |
| cell.putValue(30); | |
| cell = cells.get("C5"); | |
| cell.putValue(60); | |
| var curr = cells.find("Blackberry", null); | |
| //var curr = cells.get("A4"); | |
| console.log("Current Cell Name: " + curr.getName()); | |
| //get row and column index of current cell | |
| var rowCol = AsposeCells.CellsHelper.cellNameToIndex(curr.getName()); | |
| var currRow = rowCol[0]; | |
| var currCol = rowCol[1]; | |
| console.log("Row Index: " + currRow + " Column Index: " + currCol); | |
| //get column name by column index | |
| var columnName = AsposeCells.CellsHelper.columnIndexToName(currCol); | |
| //get row name by row index | |
| var rowName = AsposeCells.CellsHelper.rowIndexToName(currRow); | |
| console.log("Column Name: " + columnName + " Row Name: " + rowName); | |
| //get column index by column name | |
| var columnIndex = AsposeCells.CellsHelper.columnNameToIndex(columnName); | |
| //get row index by row name | |
| var rowIndex = AsposeCells.CellsHelper.rowNameToIndex(rowName); | |
| console.log("Column Index: " + columnIndex + " Row Index: " + rowIndex); | |
| console.log(columnIndex == currCol); | |
| console.log(rowIndex == currRow); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| var workbook = new AsposeCells.Workbook(AsposeCells.FileFormatType.Xlsx); | |
| var cells = workbook.getWorksheets().get(0).getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1"); | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Price"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| cell = cells.get("B2"); | |
| cell.putValue(5); | |
| cell = cells.get("B3"); | |
| cell.putValue(3); | |
| cell = cells.get("B4"); | |
| cell.putValue(6); | |
| cell = cells.get("B5"); | |
| cell.putValue(4); | |
| cell = cells.get("C2"); | |
| cell.putValue(5); | |
| cell = cells.get("C3"); | |
| cell.putValue(20); | |
| cell = cells.get("C4"); | |
| cell.putValue(30); | |
| cell = cells.get("C5"); | |
| cell.putValue(60); | |
| cell = cells.get("E10"); | |
| var temp = workbook.createStyle(); | |
| temp.getFont().setColor(new AsposeCells.Color(255, 0, 0)); | |
| cell.setStyle(temp); | |
| // Get max display range of worksheet | |
| var range = cells.getMaxDisplayRange(); | |
| //get maximum row index of cell which contains data or style. | |
| console.log(cells.getMaxRow()); | |
| //get maximum row index of cell which contains data. | |
| console.log(cells.getMaxDataRow()); | |
| //get maximum column index of cell which contains data or style. | |
| console.log(cells.getMaxColumn()); | |
| //get maximum column index of cell which contains data. | |
| console.log(cells.getMaxDataColumn()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| const fs = require('fs'); | |
| //Instantiating an Workbook object | |
| var workbook = new AsposeCells.Workbook(AsposeCells.FileFormatType.Xlsx); | |
| var cells = workbook.getWorksheets().get(0).getCells(); | |
| var a2 = cells.get("A2"); | |
| a2.putValue("Apple"); | |
| //Getting D8 cell | |
| var d8 = cells.get("D8"); | |
| // async mode | |
| // fs.readFile("aspose.png", (err, data) => { | |
| // if (err) { | |
| // console.error('reading file error:', err); | |
| // return; | |
| // } | |
| // var byteArray = new Uint8Array(data); | |
| // console.log(byteArray); | |
| // d8.setEmbeddedImage(byteArray); | |
| // workbook.save("out.xlsx"); | |
| // }); | |
| // sync mode | |
| var imgBuf = new Uint8Array(fs.readFileSync("aspose.png")); | |
| d8.setEmbeddedImage(imgBuf); | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //This example shows how to optimize memory usage while working with large data in Aspose.Cells for Node.js via C++ | |
| const { Workbook, FileFormatType, MemorySetting } = require("aspose.cells.node"); | |
| var workbook = new Workbook(FileFormatType.Xlsx); | |
| // apply the setting to existing "Sheet1" | |
| workbook.getWorksheets().get(0).getCells().setMemorySetting(MemorySetting.MemoryPreference); | |
| // apply the setting globally | |
| workbook.getSettings().setMemorySetting(MemorySetting.MemoryPreference); | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| var InputPath = dataDir + "Book1.xlsx"; | |
| //Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook(InputPath); | |
| //Accessing the first worksheet in the Excel file | |
| var worksheet = workbook.getWorksheets().get(0) | |
| //Populating new data to the worksheet cells | |
| worksheet.getCells().get("A9").putValue("Golf"); | |
| worksheet.getCells().get("B9").putValue("Qtr4"); | |
| worksheet.getCells().get("C9").putValue(7000); | |
| //Changing named range "DataSource" | |
| var range = worksheet.getCells().createRange(0, 0, 9, 3); | |
| range.setName("DataSource"); | |
| //Saving the modified Excel file | |
| workbook.save(dataDir + "output.xls"); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook() | |
| //Obtaining the reference of the newly added worksheet | |
| var sheet = workbook.getWorksheets().get(0); | |
| var cells = sheet.getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1"); | |
| cell.putValue("Sport"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Quarter"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Sales"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Golf"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Golf"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A6"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A7"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A8"); | |
| cell.putValue("Golf"); | |
| cell = cells.get("B2"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("B3"); | |
| cell.putValue("Qtr4"); | |
| cell = cells.get("B4"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("B5"); | |
| cell.putValue("Qtr4"); | |
| cell = cells.get("B6"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("B7"); | |
| cell.putValue("Qtr4"); | |
| cell = cells.get("B8"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("C2"); | |
| cell.putValue(1500); | |
| cell = cells.get("C3"); | |
| cell.putValue(2000); | |
| cell = cells.get("C4"); | |
| cell.putValue(600); | |
| cell = cells.get("C5"); | |
| cell.putValue(1500); | |
| cell = cells.get("C6"); | |
| cell.putValue(4070) | |
| cell = cells.get("C7"); | |
| cell.putValue(5000) | |
| cell = cells.get("C8"); | |
| cell.putValue(6430); | |
| var pivotTables = sheet.getPivotTables(); | |
| //Adding a PivotTable to the worksheet | |
| var index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = pivotTables.get(index); | |
| //Unshowing grand totals for rows. | |
| pivotTable.setRowGrand(false); | |
| //Draging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| //Draging the second field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 1) | |
| //Draging the third field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2) | |
| //Saving the Excel file | |
| workbook.save("pivotTable_test_out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Load source excel file containing a pivot table having calculated items | |
| var wb = new AsposeCells.Workbook(dataDir + "sample.xlsx"); | |
| //Access first worksheet | |
| var sheet = wb.getWorksheets().get(0); | |
| //Change the value of cell D2 | |
| sheet.getCells().get("D2").putValue(20); | |
| //Refresh and calculate all the pivot tables inside this sheet | |
| sheet.refreshPivotTables(); | |
| //Save the workbook in output pdf | |
| wb.save(dataDir + "RefreshAndCalculateItems_out.pdf", AsposeCells.SaveFormat.Pdf); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Load template file | |
| var wb = new AsposeCells.Workbook(sourceDir + "samplePivotTable.xlsx"); | |
| //Get first pivot table in the worksheet | |
| var pt = wb.getWorksheets().get(1).getPivotTables().get(0); | |
| //Set pivot field | |
| pt.showReportFilterPage(pt.getPageFields().get(0)); | |
| //Set position index for showing report filter pages | |
| pt.showReportFilterPageByIndex(pt.getPageFields().get(0).getPosition()); | |
| //Set the page field name | |
| pt.showReportFilterPageByName(pt.getPageFields().get(0).getName()); | |
| //Save the output file | |
| wb.save(outputDir + "outputSamplePivotTable.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating an Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| //Obtaining the reference of the newly added worksheet | |
| var ws = workbook.getWorksheets().get(0); | |
| var cells = ws.getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1"); | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Price"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| cell = cells.get("B2"); | |
| cell.putValue(5); | |
| cell = cells.get("B3"); | |
| cell.putValue(3); | |
| cell = cells.get("B4"); | |
| cell.putValue(6); | |
| cell = cells.get("B5"); | |
| cell.putValue(4); | |
| cell = cells.get("C2"); | |
| cell.putValue(5); | |
| cell = cells.get("C3"); | |
| cell.putValue(20); | |
| cell = cells.get("C4"); | |
| cell.putValue(30); | |
| cell = cells.get("C5"); | |
| cell.putValue(60); | |
| //Adding a PivotTable to the worksheet | |
| var i = ws.getPivotTables().add("=A1:C5", "D10", "PivotTable1"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = ws.getPivotTables().get(i); | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| //Adding a calculated field to PivotTable and drag it to data area. | |
| pivotTable.addCalculatedField("total", "=Count*Price", true); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating an Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| //Obtaining the reference of the newly added worksheet | |
| var ws = workbook.getWorksheets().get(0); | |
| var cells = ws.getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1"); | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| cell = cells.get("A6"); | |
| cell.putValue("Guava"); | |
| cell = cells.get("A7"); | |
| cell.putValue("Carambola"); | |
| cell = cells.get("A8"); | |
| cell.putValue("Banana"); | |
| cell = cells.get("B2"); | |
| cell.putValue(5); | |
| cell = cells.get("B3"); | |
| cell.putValue(3); | |
| cell = cells.get("B4"); | |
| cell.putValue(6); | |
| cell = cells.get("B5"); | |
| cell.putValue(4); | |
| cell = cells.get("B6"); | |
| cell.putValue(5); | |
| cell = cells.get("B7"); | |
| cell.putValue(2); | |
| cell = cells.get("B8"); | |
| cell.putValue(20); | |
| //Adding a PivotTable to the worksheet | |
| var i = ws.getPivotTables().add("=A1:B8", "D10", "PivotTable1"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = ws.getPivotTables().get(i); | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "Count"); | |
| pivotTable.getDataFields().get(0).setFunction(AsposeCells.ConsolidationFunction.Sum); | |
| var field = pivotTable.getRowFields().get(0); | |
| field.setIsAutoSort(true); | |
| field.setIsAscendSort(false); | |
| field.setAutoSortField(0); | |
| //Add top10 filter | |
| var index = pivotTable.getPivotFilters().add(0, AsposeCells.PivotFilterType.Count); | |
| var filter = pivotTable.getPivotFilters().get(index); | |
| filter.getAutoFilter().filterTop10(0, True, False, 5); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir(".") | |
| //Create workbook object from source excel file | |
| var workbook = new AsposeCells.Workbook(dataDir + "pivotTable_sample.xlsx"); | |
| //Access first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Access first pivot table | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| //1 - Show the pivot table in compact form | |
| pivotTable.showInCompactForm(); | |
| //Refresh the pivot table | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Save the output | |
| workbook.save(dataDir + "CompactForm_out.xlsx"); | |
| //2 - Show the pivot table in outline form | |
| pivotTable.showInOutlineForm(); | |
| //Refresh the pivot table | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Save the output | |
| workbook.save(dataDir + "OutlineForm_out.xlsx"); | |
| //3 - Show the pivot table in tabular form | |
| pivotTable.showInTabularForm(); | |
| //Refresh the pivot table | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Save the output | |
| workbook.save(dataDir + "TabularForm_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating an Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| //Obtaining the reference of the newly added worksheet | |
| var ws = workbook.getWorksheets().get(0); | |
| var cells = ws.getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1");; | |
| cell.putValue("Fruit"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Count"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Apple"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Mango"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Blackberry"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Cherry"); | |
| cell = cells.get("A6"); | |
| cell.putValue("Guava"); | |
| cell = cells.get("A7"); | |
| cell.putValue("Carambola"); | |
| cell = cells.get("A8"); | |
| cell.putValue("Banana"); | |
| cell = cells.get("B2"); | |
| cell.putValue(5) | |
| cell = cells.get("B3"); | |
| cell.putValue(3) | |
| cell = cells.get("B4"); | |
| cell.putValue(6) | |
| cell = cells.get("B5"); | |
| cell.putValue(4) | |
| cell = cells.get("B6"); | |
| cell.putValue(5) | |
| cell = cells.get("B7"); | |
| cell.putValue(2) | |
| cell = cells.get("B8"); | |
| cell.putValue(20) | |
| //Adding a PivotTable to the worksheet | |
| var i = ws.getPivotTables().add("=A1:B8", "D10", "PivotTable1"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = ws.getPivotTables().get(i); | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "Count"); | |
| pivotTable.getDataFields().get(0).setFunction(AsposeCells.ConsolidationFunction.Sum); | |
| var field = pivotTable.getRowFields().get(0); | |
| field.setIsAutoSort(true); | |
| field.setIsAscendSort(false); | |
| field.setAutoSortField(0); | |
| //Add top10 filter | |
| var index = pivotTable.getPivotFilters().add(field.getBaseIndex(), AsposeCells.PivotFilterType.Count); | |
| var filter = pivotTable.getPivotFilters().get(index); | |
| filter.getAutoFilter().filterTop10(0, True, False, 5); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| workbook.save("out_add.xlsx"); | |
| //Clear PivotFilter from the specific PivotField | |
| pivotTable.getPivotFilters().clearFilter(field.getBaseIndex()); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| workbook.save("out_delete.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir(".") | |
| //Load a template file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
| //Get the first worksheet | |
| var sheet = workbook.getWorksheets().get(0); | |
| //Get the pivot tables in the sheet | |
| var pivotTables = sheet.getPivotTables(); | |
| //Get the first PivotTable | |
| var pivotTable = pivotTables.get(0); | |
| //Clear all the data fields | |
| pivotTable.getDataFields().clear(); | |
| //Add new data field | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "Betrag Netto FW"); | |
| //Set the refresh data flag on | |
| pivotTable.setRefreshDataFlag(true); | |
| //Refresh and calculate the pivot table data | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| pivotTable.setRefreshDataFlag(false); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir(".") | |
| //Create workbook from source excel file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book.xlsx"); | |
| //Access the first worksheet of the workbook | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Access the first pivot table of the worksheet | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| //Apply Average consolidation function to first data field | |
| pivotTable.getDataFields().get(0).setFunction(AsposeCells.ConsolidationFunction.Average); | |
| //Apply DistinctCount consolidation function to second data field | |
| pivotTable.getDataFields().get(1).setFunction(AsposeCells.ConsolidationFunction.DistinctCount); | |
| //Calculate the data to make changes affect | |
| pivotTable.calculateData(); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| //Obtaining the reference of the newly added worksheet | |
| var sheetIndex = workbook.getWorksheets().add(); | |
| var sheet = workbook.getWorksheets().get(sheetIndex); | |
| var cells = sheet.getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1"); | |
| cell.setValue("Sport"); | |
| cell = cells.get("B1"); | |
| cell.setValue("Quarter"); | |
| cell = cells.get("C1"); | |
| cell.setValue("Sales"); | |
| cell = cells.get("A2"); | |
| cell.setValue("Golf"); | |
| cell = cells.get("A3"); | |
| cell.setValue("Golf"); | |
| cell = cells.get("A4"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A5"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A6"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A7"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A8"); | |
| cell.setValue("Golf"); | |
| cell = cells.get("B2"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("B3"); | |
| cell.setValue("Qtr4"); | |
| cell = cells.get("B4"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("B5"); | |
| cell.setValue("Qtr4"); | |
| cell = cells.get("B6"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("B7"); | |
| cell.setValue("Qtr4"); | |
| cell = cells.get("B8"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("C2"); | |
| cell.setValue(1500); | |
| cell = cells.get("C3"); | |
| cell.setValue(2000); | |
| cell = cells.get("C4"); | |
| cell.setValue(600); | |
| cell = cells.get("C5"); | |
| cell.setValue(1500); | |
| cell = cells.get("C6"); | |
| cell.setValue(4070); | |
| cell = cells.get("C7"); | |
| cell.setValue(5000); | |
| cell = cells.get("C8"); | |
| cell.setValue(6430); | |
| var pivotTables = sheet.getPivotTables(); | |
| //Adding a PivotTable to the worksheet | |
| var index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = pivotTables.get(index); | |
| //Unshowing grand totals for rows. | |
| pivotTable.setRowGrand(false); | |
| //Dragging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| //Dragging the second field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 1); | |
| //Dragging the third field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2); | |
| //Saving the Excel file | |
| workbook.save("CreatePivotTable_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| //Obtaining the reference of the newly added worksheet | |
| var sheetIndex = workbook.getWorksheets().add(); | |
| var worksheet = workbook.getWorksheets().get(sheetIndex); | |
| var cells = worksheet.getCells(); | |
| //Setting the value to the cells | |
| var cell = cells.get("A1");; | |
| cell.setValue("Sport");; | |
| cell = cells.get("B1"); | |
| cell.setValue("Quarter"); | |
| cell = cells.get("C1"); | |
| cell.setValue("Sales"); | |
| cell = cells.get("A2"); | |
| cell.setValue("Golf"); | |
| cell = cells.get("A3"); | |
| cell.setValue("Golf"); | |
| cell = cells.get("A4"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A5"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A6"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A7"); | |
| cell.setValue("Tennis"); | |
| cell = cells.get("A8"); | |
| cell.setValue("Golf"); | |
| cell = cells.get("B2"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("B3"); | |
| cell.setValue("Qtr4"); | |
| cell = cells.get("B4"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("B5"); | |
| cell.setValue("Qtr4"); | |
| cell = cells.get("B6"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("B7"); | |
| cell.setValue("Qtr4"); | |
| cell = cells.get("B8"); | |
| cell.setValue("Qtr3"); | |
| cell = cells.get("C2"); | |
| cell.setValue(1500); | |
| cell = cells.get("C3"); | |
| cell.setValue(2000); | |
| cell = cells.get("C4"); | |
| cell.setValue(600); | |
| cell = cells.get("C5"); | |
| cell.setValue(1500); | |
| cell = cells.get("C6"); | |
| cell.setValue(4070); | |
| cell = cells.get("C7"); | |
| cell.setValue(5000); | |
| cell = cells.get("C8"); | |
| cell.setValue(6430); | |
| var pivotTables = worksheet.getPivotTables(); | |
| //Adding a PivotTable to the worksheet | |
| var index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = pivotTables.get(index); | |
| //Unshowing grand totals for rows | |
| pivotTable.setRowGrand(false); | |
| //Dragging the first field to the row area | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| //Dragging the second field to the column area | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 1); | |
| //Dragging the third field to the data area | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2); | |
| //Saving the Excel file | |
| workbook.save("CreatePivotTable_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Instantiating an Workbook object | |
| //Opening the excel file | |
| var workbook = new AsposeCells.Workbook(dataDir + "pivotTable_test.xlsx"); | |
| //Adding a new sheet | |
| var sheet3 = workbook.getWorksheets().get(workbook.getWorksheets().add(AsposeCells.SheetType.Chart)); | |
| //Naming the sheet | |
| sheet3.setName("PivotChart"); | |
| //Adding a column chart | |
| index = sheet3.getCharts().add(AsposeCells.ChartType.Column, 0, 5, 28, 16); | |
| //Setting the pivot chart data source | |
| sheet3.getCharts().get(index).setPivotSource("PivotTable!PivotTable1"); | |
| sheet3.getCharts().get(index).setHidePivotFieldButtons(false); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "pivotChart_test_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir(".");; | |
| //Instantiating an Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| //Obtaining the reference of the first worksheet | |
| var sheet = workbook.getWorksheets().get(0); | |
| //Name the sheet | |
| sheet.setName("Data");; | |
| var cells = sheet.getCells(); | |
| //Setting the values to the cells | |
| var cell = cells.get("A1"); | |
| cell.putValue("Employee"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Quarter"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Product"); | |
| cell = cells.get("D1"); | |
| cell.putValue("Continent"); | |
| cell = cells.get("E1"); | |
| cell.putValue("Country"); | |
| cell = cells.get("F1"); | |
| cell.putValue("Sale"); | |
| cell = cells.get("A2"); | |
| cell.putValue("David"); | |
| cell = cells.get("A3"); | |
| cell.putValue("David"); | |
| cell = cells.get("A4"); | |
| cell.putValue("David"); | |
| cell = cells.get("A5"); | |
| cell.putValue("David"); | |
| cell = cells.get("A6"); | |
| cell.putValue("James"); | |
| cell = cells.get("A7"); | |
| cell.putValue("James"); | |
| cell = cells.get("A8"); | |
| cell.putValue("James"); | |
| cell = cells.get("A9"); | |
| cell.putValue("James"); | |
| cell = cells.get("A10"); | |
| cell.putValue("James"); | |
| cell = cells.get("A11"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A12"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A13"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A14"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A15"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A16"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A17"); | |
| cell.putValue("Miya"); | |
| cell = cells.get("A18"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A19"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A20"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A21"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A22"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A23"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A24"); | |
| cell.putValue("Elvis"); | |
| cell = cells.get("A25"); | |
| cell.putValue("Jean"); | |
| cell = cells.get("A26"); | |
| cell.putValue("Jean"); | |
| cell = cells.get("A27"); | |
| cell.putValue("Jean"); | |
| cell = cells.get("A28"); | |
| cell.putValue("Ada"); | |
| cell = cells.get("A29"); | |
| cell.putValue("Ada"); | |
| cell = cells.get("A30"); | |
| cell.putValue("Ada"); | |
| cell = cells.get("B2"); | |
| cell.putValue("1"); | |
| cell = cells.get("B3"); | |
| cell.putValue("2"); | |
| cell = cells.get("B4"); | |
| cell.putValue("3"); | |
| cell = cells.get("B5"); | |
| cell.putValue("4"); | |
| cell = cells.get("B6"); | |
| cell.putValue("1"); | |
| cell = cells.get("B7"); | |
| cell.putValue("2"); | |
| cell = cells.get("B8"); | |
| cell.putValue("3"); | |
| cell = cells.get("B9"); | |
| cell.putValue("4"); | |
| cell = cells.get("B10"); | |
| cell.putValue("4"); | |
| cell = cells.get("B11"); | |
| cell.putValue("1"); | |
| cell = cells.get("B12"); | |
| cell.putValue("1"); | |
| cell = cells.get("B13"); | |
| cell.putValue("2"); | |
| cell = cells.get("B14"); | |
| cell.putValue("2"); | |
| cell = cells.get("B15"); | |
| cell.putValue("3"); | |
| cell = cells.get("B16"); | |
| cell.putValue("4"); | |
| cell = cells.get("B17"); | |
| cell.putValue("4"); | |
| cell = cells.get("B18"); | |
| cell.putValue("1"); | |
| cell = cells.get("B19"); | |
| cell.putValue("1"); | |
| cell = cells.get("B20"); | |
| cell.putValue("2"); | |
| cell = cells.get("B21"); | |
| cell.putValue("3"); | |
| cell = cells.get("B22"); | |
| cell.putValue("3"); | |
| cell = cells.get("B23"); | |
| cell.putValue("4"); | |
| cell = cells.get("B24"); | |
| cell.putValue("4"); | |
| cell = cells.get("B25"); | |
| cell.putValue("1"); | |
| cell = cells.get("B26"); | |
| cell.putValue("2"); | |
| cell = cells.get("B27"); | |
| cell.putValue("3"); | |
| cell = cells.get("B28"); | |
| cell.putValue("1"); | |
| cell = cells.get("B29"); | |
| cell.putValue("2"); | |
| cell = cells.get("B30"); | |
| cell.putValue("3"); | |
| cell = cells.get("C2"); | |
| cell.putValue("Maxilaku"); | |
| cell = cells.get("C3"); | |
| cell.putValue("Maxilaku"); | |
| cell = cells.get("C4"); | |
| cell.putValue("Chai"); | |
| cell = cells.get("C5"); | |
| cell.putValue("Maxilaku"); | |
| cell = cells.get("C6"); | |
| cell.putValue("Chang"); | |
| cell = cells.get("C7"); | |
| cell.putValue("Chang"); | |
| cell = cells.get("C8"); | |
| cell.putValue("Chang"); | |
| cell = cells.get("C9"); | |
| cell.putValue("Chang"); | |
| cell = cells.get("C10"); | |
| cell.putValue("Chang"); | |
| cell = cells.get("C11"); | |
| cell.putValue("Geitost"); | |
| cell = cells.get("C12"); | |
| cell.putValue("Chai"); | |
| cell = cells.get("C13"); | |
| cell.putValue("Geitost"); | |
| cell = cells.get("C14"); | |
| cell.putValue("Geitost"); | |
| cell = cells.get("C15"); | |
| cell.putValue("Maxilaku"); | |
| cell = cells.get("C16"); | |
| cell.putValue("Geitost"); | |
| cell = cells.get("C17"); | |
| cell.putValue("Geitost"); | |
| cell = cells.get("C18"); | |
| cell.putValue("Ikuru"); | |
| cell = cells.get("C19"); | |
| cell.putValue("Ikuru"); | |
| cell = cells.get("C20"); | |
| cell.putValue("Ikuru"); | |
| cell = cells.get("C21"); | |
| cell.putValue("Ikuru"); | |
| cell = cells.get("C22"); | |
| cell.putValue("Ipoh Coffee"); | |
| cell = cells.get("C23"); | |
| cell.putValue("Ipoh Coffee"); | |
| cell = cells.get("C24"); | |
| cell.putValue("Ipoh Coffee"); | |
| cell = cells.get("C25"); | |
| cell.putValue("Chocolade"); | |
| cell = cells.get("C26"); | |
| cell.putValue("Chocolade"); | |
| cell = cells.get("C27"); | |
| cell.putValue("Chocolade"); | |
| cell = cells.get("C28"); | |
| cell.putValue("Chocolade"); | |
| cell = cells.get("C29"); | |
| cell.putValue("Chocolade"); | |
| cell = cells.get("C30"); | |
| cell.putValue("Chocolade"); | |
| cell = cells.get("D2"); | |
| cell.putValue("Asia"); | |
| cell = cells.get("D3"); | |
| cell.putValue("Asia"); | |
| cell = cells.get("D4"); | |
| cell.putValue("Asia"); | |
| cell = cells.get("D5"); | |
| cell.putValue("Asia"); | |
| cell = cells.get("D6"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D7"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D8"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D9"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D10"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D11"); | |
| cell.putValue("America"); | |
| cell = cells.get("D12"); | |
| cell.putValue("America"); | |
| cell = cells.get("D13"); | |
| cell.putValue("America"); | |
| cell = cells.get("D14"); | |
| cell.putValue("America"); | |
| cell = cells.get("D15"); | |
| cell.putValue("America"); | |
| cell = cells.get("D16"); | |
| cell.putValue("America"); | |
| cell = cells.get("D17"); | |
| cell.putValue("America"); | |
| cell = cells.get("D18"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D19"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D20"); | |
| cell.putValue("Europe"); | |
| cell = cells.get("D21"); | |
| cell.putValue("Oceania"); | |
| cell = cells.get("D22"); | |
| cell.putValue("Oceania"); | |
| cell = cells.get("D23"); | |
| cell.putValue("Oceania"); | |
| cell = cells.get("D24"); | |
| cell.putValue("Oceania"); | |
| cell = cells.get("D25"); | |
| cell.putValue("Africa"); | |
| cell = cells.get("D26"); | |
| cell.putValue("Africa"); | |
| cell = cells.get("D27"); | |
| cell.putValue("Africa"); | |
| cell = cells.get("D28"); | |
| cell.putValue("Africa"); | |
| cell = cells.get("D29"); | |
| cell.putValue("Africa"); | |
| cell = cells.get("D30"); | |
| cell.putValue("Africa"); | |
| cell = cells.get("E2"); | |
| cell.putValue("China"); | |
| cell = cells.get("E3"); | |
| cell.putValue("India"); | |
| cell = cells.get("E4"); | |
| cell.putValue("Korea"); | |
| cell = cells.get("E5"); | |
| cell.putValue("India"); | |
| cell = cells.get("E6"); | |
| cell.putValue("France"); | |
| cell = cells.get("E7"); | |
| cell.putValue("France"); | |
| cell = cells.get("E8"); | |
| cell.putValue("Germany"); | |
| cell = cells.get("E9"); | |
| cell.putValue("Italy"); | |
| cell = cells.get("E10"); | |
| cell.putValue("France"); | |
| cell = cells.get("E11"); | |
| cell.putValue("U.S."); | |
| cell = cells.get("E12"); | |
| cell.putValue("U.S."); | |
| cell = cells.get("E13"); | |
| cell.putValue("Brazil"); | |
| cell = cells.get("E14"); | |
| cell.putValue("U.S."); | |
| cell = cells.get("E15"); | |
| cell.putValue("U.S."); | |
| cell = cells.get("E16"); | |
| cell.putValue("Canada"); | |
| cell = cells.get("E17"); | |
| cell.putValue("U.S."); | |
| cell = cells.get("E18"); | |
| cell.putValue("Italy"); | |
| cell = cells.get("E19"); | |
| cell.putValue("France"); | |
| cell = cells.get("E20"); | |
| cell.putValue("Italy"); | |
| cell = cells.get("E21"); | |
| cell.putValue("New Zealand"); | |
| cell = cells.get("E22"); | |
| cell.putValue("Australia"); | |
| cell = cells.get("E23"); | |
| cell.putValue("Australia"); | |
| cell = cells.get("E24"); | |
| cell.putValue("New Zealand"); | |
| cell = cells.get("E25"); | |
| cell.putValue("S.Africa"); | |
| cell = cells.get("E26"); | |
| cell.putValue("S.Africa"); | |
| cell = cells.get("E27"); | |
| cell.putValue("S.Africa"); | |
| cell = cells.get("E28"); | |
| cell.putValue("Egypt"); | |
| cell = cells.get("E29"); | |
| cell.putValue("Egypt"); | |
| cell = cells.get("E30"); | |
| cell.putValue("Egypt"); | |
| cell = cells.get("F2"); | |
| cell.putValue(2000) | |
| cell = cells.get("F3"); | |
| cell.putValue(500) | |
| cell = cells.get("F4"); | |
| cell.putValue(1200) | |
| cell = cells.get("F5"); | |
| cell.putValue(1500) | |
| cell = cells.get("F6"); | |
| cell.putValue(500) | |
| cell = cells.get("F7"); | |
| cell.putValue(1500) | |
| cell = cells.get("F8"); | |
| cell.putValue(800) | |
| cell = cells.get("F9"); | |
| cell.putValue(900) | |
| cell = cells.get("F10"); | |
| cell.putValue(500) | |
| cell = cells.get("F11"); | |
| cell.putValue(1600) | |
| cell = cells.get("F12"); | |
| cell.putValue(600) | |
| cell = cells.get("F13"); | |
| cell.putValue(2000) | |
| cell = cells.get("F14"); | |
| cell.putValue(500) | |
| cell = cells.get("F15"); | |
| cell.putValue(900) | |
| cell = cells.get("F16"); | |
| cell.putValue(700) | |
| cell = cells.get("F17"); | |
| cell.putValue(1400) | |
| cell = cells.get("F18"); | |
| cell.putValue(1350) | |
| cell = cells.get("F19"); | |
| cell.putValue(300) | |
| cell = cells.get("F20"); | |
| cell.putValue(500) | |
| cell = cells.get("F21"); | |
| cell.putValue(1000) | |
| cell = cells.get("F22"); | |
| cell.putValue(1500) | |
| cell = cells.get("F23"); | |
| cell.putValue(1500) | |
| cell = cells.get("F24"); | |
| cell.putValue(1600) | |
| cell = cells.get("F25"); | |
| cell.putValue(1000) | |
| cell = cells.get("F26"); | |
| cell.putValue(1200) | |
| cell = cells.get("F27"); | |
| cell.putValue(1300) | |
| cell = cells.get("F28"); | |
| cell.putValue(1500) | |
| cell = cells.get("F29"); | |
| cell.putValue(1400) | |
| cell = cells.get("F30"); | |
| cell.putValue(1000) | |
| //Adding a new sheet | |
| var sheet2 = workbook.getWorksheets().get(workbook.getWorksheets().add()); | |
| //Naming the sheet | |
| sheet2.setName("PivotTable"); | |
| //Getting the pivottables collection in the sheet | |
| var pivotTables = sheet2.getPivotTables(); | |
| //Adding a PivotTable to the worksheet | |
| var index = pivotTables.add("=Data!A1:F30", "B3", "PivotTable1"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = pivotTables.get(index); | |
| //Showing the grand totals | |
| pivotTable.setRowGrand(true); | |
| pivotTable.setColumnGrand(true); | |
| //Setting the PivotTable report is automatically formatted | |
| pivotTable.setIsAutoFormat(true); | |
| //Setting the PivotTable autoformat type. | |
| pivotTable.setAutoFormatType(AsposeCells.PivotTableAutoFormatType.Report6); | |
| //Draging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| //Draging the third field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 2); | |
| //Draging the second field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 1); | |
| //Draging the fourth field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 3); | |
| //Draging the fifth field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 5); | |
| //Setting the number format of the first data field | |
| pivotTable.getDataFields().get(0).setNumberFormat("$#,##0.00"); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "pivotTable_test.out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Open the template file containing the pivot table | |
| var wb = new AsposeCells.Workbook("pivot_table_test.xlsx"); | |
| //Access the pivot table in the first sheet | |
| var pt = wb.getWorksheets().get(0).getPivotTables().get(0); | |
| //Disable ribbon for this pivot table | |
| pt.setEnableWizard(false); | |
| //Save output file | |
| wb.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Load sample Excel file | |
| var wb = new AsposeCells.Workbook("sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx"); | |
| //Access first worksheet | |
| var ws = wb.getWorksheets().get(0); | |
| //Access third pivot table | |
| var ptParent = ws.getPivotTables().get(2); | |
| //Access the children of the parent pivot table | |
| var ptChildren = ptParent.getChildren(); | |
| //Refresh all the children pivot table | |
| for (let pivot of ptChildren) { | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create workbook object from source file containing pivot table | |
| var workbook = new AsposeCells.Workbook("pivot_format.xlsx"); | |
| //Access the worksheet by its name | |
| var worksheet = workbook.getWorksheets().get("Sheet1"); | |
| //Access the pivot table | |
| var pivotTable = worksheet.getPivotTables().get(1); | |
| //Create a style object with background color light blue | |
| var style = workbook.createStyle(); | |
| style.setPattern(AsposeCells.BackgroundType.Solid); | |
| style.setBackgroundColor(AsposeCells.Color.LightBlue); | |
| //Format entire pivot table with light blue color | |
| pivotTable.formatAll(style); | |
| //Create another style object with yellow color | |
| var style = workbook.createStyle(); | |
| style.setPattern(AsposeCells.BackgroundType.Solid); | |
| style.setBackgroundColor(AsposeCells.Color.Yellow); | |
| //Access the pivot table | |
| var pivotTable2 = worksheet.getPivotTables().get(0); | |
| //Format the cell of pivot table | |
| pivotTable2.format(16, 5, style); | |
| //Save the workbook object | |
| workbook.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir(".") | |
| //Load a template file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
| //Get the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| var pivot = worksheet.getPivotTables().get(0); | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleDark1); | |
| var style = workbook.createStyle(); | |
| style.getFont().setName("Arial Black"); | |
| style.setPattern(AsposeCells.BackgroundType.Solid); | |
| style.setForegroundColor(AsposeCells.Color.Yellow); | |
| pivot.formatAll(style); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Create workbook object from source excel file | |
| var workbook = new AsposeCells.Workbook(dataDir + "source.xlsx"); | |
| //Access first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Access first pivot table inside the worksheet | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| //Access cell by display name of 2nd data field of the pivot table | |
| var cell = pivotTable.getCellByDisplayName(pivotTable.getDataFields().get(1).getDisplayName()); | |
| //Access cell style and set its fill color and font color | |
| var style = cell.getStyle(); | |
| style.setForegroundColor(AsposeCells.Color.LightBlue); | |
| style.getFont().setColor(AsposeCells.Color.Black); | |
| //Set the style of the cell | |
| pivotTable.format(cell.getRow(), cell.getColumn(), style); | |
| //Save workbook | |
| workbook.save(dataDir + "output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Create workbook object from source excel file | |
| var workbook = new AsposeCells.Workbook(sourceDir + "sourcePivotTable.xlsx"); | |
| //Access first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Access first pivot table inside the worksheet | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| //Access pivot table refresh by who | |
| console.log("Pivot table refresh by who = " + pivotTable.getRefreshedByWho()); | |
| //Access pivot table refresh date | |
| console.log("Pivot table refresh date = " + pivotTable.getRefreshDate()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Load sample workbook | |
| var wb = new AsposeCells.Workbook("sampleGroupPivotFieldsInPivotTable.xlsx"); | |
| //Access the second worksheet | |
| var ws = wb.getWorksheets().get(1); | |
| //Access the pivot table | |
| var pt = ws.getPivotTables().get(0); | |
| //Specify the start and end date time | |
| var dtStart = new Date(2008, 1, 1); | |
| var dtEnd = new Date(2008, 9, 5); | |
| //Specify the group type list, we want to group by months and quarters | |
| var groupTypeList = [AsposeCells.PivotGroupByType.Months, AsposeCells.PivotGroupByType.Quarters]; | |
| //Apply the grouping on first pivot field | |
| var field = pt.getRowFields().get(0); | |
| field.groupBy(dtStart, dtEnd, groupTypeList, 1, true); | |
| //Refresh and calculate pivot table | |
| pt.setRefreshDataFlag(true); | |
| pt.refreshData(); | |
| pt.calculateData(); | |
| pt.setRefreshDataFlag(false); | |
| //Save the output Excel file | |
| wb.save("outputGroupPivotFieldsInPivotTable.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setAutoFormatType(AsposeCells.PivotTableAutoFormatType.Report8); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| //Construct data range for chart object | |
| var dataRange = "="+sheet.getName()+"!"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().startRow + 1, pivot.getTableRange1().startColumn)+":"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().endRow, pivot.getTableRange1().endColumn); | |
| var charts = sheet.getCharts(); | |
| //Add Cylinder chart | |
| var index = charts.add(AsposeCells.ChartType.Cylinder, dataRange, false, 10, 5, 25, 15); | |
| charts.get(index).refreshPivotData(); | |
| book.save("out.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleMedium9); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| //Construct data range for chart object | |
| var dataRange = "="+sheet.getName()+"!"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().startRow + 1, pivot.getTableRange1().startColumn)+":"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().endRow, pivot.getTableRange1().endColumn); | |
| var charts = sheet.getCharts(); | |
| //Add Cylinder chart | |
| var index = charts.add(AsposeCells.ChartType.Cylinder, dataRange, false, 10, 5, 25, 15); | |
| charts.get(index).refreshPivotData(); | |
| book.save("out.xlsb"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleMedium9); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| //Construct data range for chart object | |
| var dataRange = "="+sheet.getName()+"!"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().startRow + 1, pivot.getTableRange1().startColumn)+":"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().endRow, pivot.getTableRange1().endColumn); | |
| var charts = sheet.getCharts(); | |
| //Add Cylinder chart | |
| var index = charts.add(AsposeCells.ChartType.Cylinder, dataRange, false, 10, 5, 25, 15); | |
| charts.get(index).refreshPivotData(); | |
| book.save("out.xlsm"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleMedium9); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| //Construct data range for chart object | |
| var dataRange = "="+sheet.getName()+"!"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().startRow + 1, pivot.getTableRange1().startColumn)+":"+AsposeCells.CellsHelper.cellIndexToName(pivot.getTableRange1().endRow, pivot.getTableRange1().endColumn); | |
| var charts = sheet.getCharts(); | |
| //Add Cylinder chart | |
| var index = charts.add(AsposeCells.ChartType.Cylinder, dataRange, false, 10, 5, 25, 15); | |
| charts.get(index).refreshPivotData(); | |
| book.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setAutoFormatType(AsposeCells.PivotTableAutoFormatType.Report8); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| book.save("out.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleMedium9); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| book.save("out.xlsb"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleMedium9); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| book.save("out.xlsm"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //Create a new workbook | |
| var book = new AsposeCells.Workbook(); | |
| //Get the first worksheet | |
| var sheet = book.getWorksheets().get(0); | |
| //add some data | |
| var cells = sheet.getCells(); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(0, 0).setValue("fruit"); | |
| cells.get(1, 0).setValue("grape"); | |
| cells.get(2, 0).setValue("blueberry"); | |
| cells.get(3, 0).setValue("kiwi"); | |
| cells.get(4, 0).setValue("cherry"); | |
| cells.get(5, 0).setValue("grape"); | |
| cells.get(6, 0).setValue("blueberry"); | |
| cells.get(7, 0).setValue("kiwi"); | |
| cells.get(8, 0).setValue("cherry"); | |
| cells.get(0, 1).setValue("year"); | |
| cells.get(1, 1).setValue(2020); | |
| cells.get(2, 1).setValue(2020); | |
| cells.get(3, 1).setValue(2020); | |
| cells.get(4, 1).setValue(2020); | |
| cells.get(5, 1).setValue(2021); | |
| cells.get(6, 1).setValue(2021); | |
| cells.get(7, 1).setValue(2021); | |
| cells.get(8, 1).setValue(2021); | |
| cells.get(0, 2).setValue("amount"); | |
| cells.get(1, 2).setValue(50); | |
| cells.get(2, 2).setValue(60); | |
| cells.get(3, 2).setValue(70); | |
| cells.get(4, 2).setValue(80); | |
| cells.get(5, 2).setValue(90); | |
| cells.get(6, 2).setValue(100); | |
| cells.get(7, 2).setValue(110); | |
| cells.get(8, 2).setValue(120); | |
| var pivots = sheet.getPivotTables(); | |
| //Add a PivotTable | |
| var pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable"); | |
| var pivot = pivots.get(pivotIndex); | |
| //Add PivotField for row area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Row, "fruit"); | |
| //Add PivotField for column area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Column, "year"); | |
| //Add PivotField for data area | |
| pivot.addFieldToArea(AsposeCells.PivotFieldType.Data, "amount"); | |
| //Set the style of PivotTable | |
| pivot.setPivotTableStyleType(AsposeCells.PivotTableStyleType.PivotTableStyleMedium9); | |
| //Refresh and calculate data of PivotTable | |
| pivot.refreshData(); | |
| pivot.calculateData(); | |
| book.save("out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Create load options | |
| var options = new AsposeCells.LoadOptions(); | |
| //Set ParsingPivotCachedRecords true, default value is false | |
| options.setParsingPivotCachedRecords(true); | |
| //Load the sample Excel file containing pivot table cached records | |
| var wb = new AsposeCells.Workbook("sampleParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx", options); | |
| //Access first worksheet | |
| var ws = wb.getWorksheets().get(0); | |
| //Access first pivot table | |
| var pt = ws.getPivotTables().get(0); | |
| //Set refresh data flag true | |
| pt.setRefreshDataFlag(true); | |
| //Refresh and calculate pivot table | |
| pt.refreshData(); | |
| pt.calculateData(); | |
| //Set refresh data flag false | |
| pt.setRefreshDataFlag(false); | |
| //Save the output Excel file | |
| wb.save("outputParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //Source directory | |
| var sourceDir = RunExamples.Get_SourceDirectory(); | |
| var outputDir = RunExamples.Get_OutputDirectory(); | |
| var wb = new AsposeCells.Workbook(sourceDir + "SamplePivotSort.xlsx"); | |
| // Obtaining the reference of the newly added worksheet | |
| var sheet = wb.getWorksheets().get(0); | |
| var pivotTables = sheet.getPivotTables(); | |
| // source PivotTable | |
| // Adding a PivotTable to the worksheet | |
| var index = pivotTables.add("=Sheet1!A1:C10", "E3", "PivotTable2"); | |
| //Accessing the instance of the newly added PivotTable | |
| var pivotTable = pivotTables.get(index); | |
| // Unshowing grand totals for rows. | |
| pivotTable.setRowGrand(false); | |
| pivotTable.setColumnGrand(false); | |
| // Dragging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 1); | |
| var rowField = pivotTable.getRowFields().get(0); | |
| rowField.setIsAutoSort(true); | |
| rowField.setIsAscendSort(true); | |
| // Dragging the second field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 0); | |
| var colField = pivotTable.getColumnFields().get(0); | |
| colField.setNumberFormat("dd/mm/yyyy"); | |
| colField.setIsAutoSort(true); | |
| colField.setIsAscendSort(true); | |
| // Dragging the third field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2) | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| // end of source PivotTable | |
| // sort the PivotTable on "SeaFood" row field values | |
| // Adding a PivotTable to the worksheet | |
| index = pivotTables.add("=Sheet1!A1:C10", "E10", "PivotTable2"); | |
| // Accessing the instance of the newly added PivotTable | |
| pivotTable = pivotTables.get(index); | |
| // Unshowing grand totals for rows. | |
| pivotTable.setRowGrand(false); | |
| pivotTable.setColumnGrand(false); | |
| // Dragging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 1); | |
| rowField = pivotTable.getRowFields().get(0); | |
| rowField.setIsAutoSort(true); | |
| rowField.setIsAscendSort(true); | |
| // Dragging the second field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 0); | |
| colField = pivotTable.getColumnFields().get(0); | |
| colField.setNumberFormat("dd/mm/yyyy"); | |
| colField.setIsAutoSort(true); | |
| colField.setIsAscendSort(true); | |
| colField.setAutoSortField(0); | |
| //Dragging the third field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2) | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| // end of sort the PivotTable on "SeaFood" row field values | |
| // sort the PivotTable on "28/07/2000" column field values | |
| // Adding a PivotTable to the worksheet | |
| index = pivotTables.add("=Sheet1!A1:C10", "E18", "PivotTable2"); | |
| // Accessing the instance of the newly added PivotTable | |
| pivotTable = pivotTables.get(index); | |
| // Unshowing grand totals for rows. | |
| pivotTable.setRowGrand(false); | |
| pivotTable.setColumnGrand(false); | |
| // Dragging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 1); | |
| rowField = pivotTable.getRowFields().get(0); | |
| rowField.setIsAutoSort(true); | |
| rowField.setIsAscendSort(true); | |
| rowField.setAutoSortField(0); | |
| // Dragging the second field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 0); | |
| colField = pivotTable.getColumnFields().get(0); | |
| colField.setNumberFormat("dd/mm/yyyy"); | |
| colField.setIsAutoSort(true); | |
| colField.setIsAscendSort(true); | |
| //Dragging the third field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2) | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| // end of sort the PivotTable on "28/07/2000" column field values | |
| //Saving the Excel file | |
| wb.save(outputDir + "out_java.xlsx"); | |
| var options = new AsposeCells.PdfSaveOptions(); | |
| options.setOnePagePerSheet(true); | |
| wb.save(outputDir + "out_java.pdf", options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| // directories | |
| var sourceDir = RunExamples.Get_SourceDirectory() | |
| var outputDir = RunExamples.Get_OutputDirectory() | |
| // Load a template file | |
| var workbook = new AsposeCells.Workbook(sourceDir + "PivotTableSample.xlsx"); | |
| // Get the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| var pivotIndex = 0; | |
| // Accessing the PivotTable | |
| var pivotTable = worksheet.getPivotTables().get(pivotIndex); | |
| // Accessing the data fields. | |
| var pivotFields = pivotTable.getDataFields(); | |
| // Accessing the first data field in the data fields. | |
| var pivotField = pivotFields.get(0); | |
| // Setting data display format | |
| pivotField.getShowValuesSetting().setCalculationType(AsposeCells.PivotFieldDataDisplayFormat.RankLargestToSmallest); | |
| pivotTable.calculateData(); | |
| // Saving the Excel file | |
| workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| // Source directory | |
| var sourceDir = RunExamples.Get_SourceDirectory(); | |
| // Load sample file | |
| var workbook = new AsposeCells.Workbook(sourceDir + "SamplePivotTableExternalConnection.xlsx"); | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Get the pivot table | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| // Print External Connection Details | |
| console.log("External Connection Data Source"); | |
| console.log("Name: " + pivotTable.getExternalConnectionDataSource().getName()); | |
| console.log("Type: " + pivotTable.getExternalConnectionDataSource().getType()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| // The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| // Create workbook object from source Excel file | |
| var workbook = new AsposeCells.Workbook(dataDir + "source.xlsx"); | |
| // Access the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access the first pivot table object | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| // Remove pivot table using pivot table object | |
| worksheet.getPivotTables().remove(pivotTable); | |
| // OR you can remove pivot table using pivot table position by uncommenting below line | |
| //worksheet.getPivotTables().removeAt(0); | |
| // Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| var outputDir = RunExamples.Get_OutputDirectory(); | |
| // Instantiating a Workbook object | |
| var workbook = new AsposeCells.Workbook(); | |
| // Obtaining the reference of the newly added worksheet | |
| var sheet = workbook.getWorksheets(0).get(0); | |
| var cells = sheet.getCells(); | |
| // Setting the value to the cells | |
| var cell = cells.get("A1");; | |
| cell.putValue("Sport"); | |
| cell = cells.get("B1"); | |
| cell.putValue("Quarter"); | |
| cell = cells.get("C1"); | |
| cell.putValue("Sales"); | |
| cell = cells.get("A2"); | |
| cell.putValue("Golf"); | |
| cell = cells.get("A3"); | |
| cell.putValue("Golf"); | |
| cell = cells.get("A4"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A5"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A6"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A7"); | |
| cell.putValue("Tennis"); | |
| cell = cells.get("A8"); | |
| cell.putValue("Golf"); | |
| cell = cells.get("B2"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("B3"); | |
| cell.putValue("Qtr4"); | |
| cell = cells.get("B4"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("B5"); | |
| cell.putValue("Qtr4"); | |
| cell = cells.get("B6"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("B7"); | |
| cell.putValue("Qtr4"); | |
| cell = cells.get("B8"); | |
| cell.putValue("Qtr3"); | |
| cell = cells.get("C2"); | |
| cell.putValue(1500) | |
| cell = cells.get("C3"); | |
| cell.putValue(2000) | |
| cell = cells.get("C4"); | |
| cell.putValue(600) | |
| cell = cells.get("C5"); | |
| cell.putValue(1500) | |
| cell = cells.get("C6"); | |
| cell.putValue(4070) | |
| cell = cells.get("C7"); | |
| cell.putValue(5000) | |
| cell = cells.get("C8"); | |
| cell.putValue(6430) | |
| var pivotTables = sheet.getPivotTables(); | |
| // Adding a PivotTable to the worksheet | |
| var index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
| // Accessing the instance of the newly added PivotTable | |
| var pivotTable = pivotTables.get(index); | |
| // Unshowing grand totals for rows. | |
| pivotTable.setRowGrand(false); | |
| // Draging the first field to the row area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
| // Draging the second field to the column area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Column, 1); | |
| // Draging the third field to the data area. | |
| pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, 2); | |
| pivotTable.calculateData(); | |
| // Saving the ODS file | |
| workbook.save(outputDir + "PivotTableSaveInODS_out.ods"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //directories | |
| var sourceDir = RunExamples.Get_SourceDirectory(); | |
| var outputDir = RunExamples.Get_OutputDirectory(); | |
| var workbook = new AsposeCells.Workbook(sourceDir + "PivotTableHideAndSortSample.xlsx"); | |
| var worksheet = workbook.getWorksheets().get(0); | |
| var pivotTable = worksheet.getPivotTables().get(0); | |
| var dataBodyRange = pivotTable.getDataBodyRange(); | |
| var currentRow = 3; | |
| var rowsUsed = dataBodyRange.endRow; | |
| //Sorting score in descending | |
| var field = pivotTable.getRowFields().get(0); | |
| field.setIsAutoSort(true); | |
| field.setIsAscendSort(false); | |
| field.setAutoSortField(0); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Hiding rows with score less than 60 | |
| while (currentRow < rowsUsed) | |
| { | |
| var cell = worksheet.getCells().get(currentRow, 1); | |
| var score = cell.getFloatValue(); | |
| if (score < 60) | |
| { | |
| worksheet.getCells().hideRow(currentRow); | |
| } | |
| currentRow = currentRow + 1; | |
| } | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Saving the Excel file | |
| workbook.save(outputDir + "PivotTableHideAndSort_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Load a template file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
| var pivotindex = 0; | |
| //Get the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| //Accessing the PivotTable | |
| var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
| //Setting the PivotTable report is automatically formatted | |
| pivotTable.setIsAutoFormat(true); | |
| //Setting the PivotTable atuoformat type. | |
| pivotTable.setAutoFormatType(AsposeCells.PivotTableAutoFormatType.Report5); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Load a template file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
| //Get the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| var pivotindex = 0; | |
| //Accessing the PivotTable | |
| var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
| //Accessing the data fields. | |
| var pivotFields = pivotTable.getDataFields(); | |
| //Accessing the first data field in the data fields. | |
| var pivotField = pivotFields.get(0); | |
| //Setting data display format | |
| pivotField.showValuesAs(AsposeCells.PivotFieldDataDisplayFormat.PercentageOf, 1, AsposeCells.PivotItemPositionType.Next, 0); | |
| //Setting number format | |
| pivotField.setNumber(10); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Load a template file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
| //Get the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| var pivotindex = 0; | |
| //Accessing the PivotTable | |
| var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
| //Setting the PivotTable report shows grand totals for rows. | |
| pivotTable.setRowGrand(true); | |
| //Setting the PivotTable report shows grand totals for columns. | |
| pivotTable.setColumnGrand(true); | |
| //Setting the PivotTable report displays a custom string in cells that contain null values. | |
| pivotTable.setDisplayNullString(true); | |
| pivotTable.setNullString("null"); | |
| //Setting the PivotTable report's layout | |
| pivotTable.setPageFieldOrder(AsposeCells.PrintOrderType.DownThenOver); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Load a template file | |
| var workbook = new AsposeCells.Workbook(dataDir + "Book1.xls"); | |
| //Get the first worksheet | |
| var worksheet = workbook.getWorksheets().get(0); | |
| var pivotindex = 0; | |
| //Accessing the PivotTable | |
| var pivotTable = worksheet.getPivotTables().get(pivotindex); | |
| //Setting the PivotTable report shows grand totals for rows. | |
| pivotTable.setRowGrand(true); | |
| //Accessing the row fields. | |
| var pivotFields = pivotTable.getRowFields(); | |
| //Accessing the first row field in the row fields. | |
| var pivotField = pivotFields.get(0); | |
| //Setting Subtotals. | |
| pivotField.setSubtotals(AsposeCells.PivotFieldSubtotalType.Sum, true); | |
| pivotField.setSubtotals(AsposeCells.PivotFieldSubtotalType.Count, true); | |
| //Setting autosort options. | |
| //Setting the field auto sort. | |
| pivotField.setIsAutoSort(true); | |
| //Setting the field auto sort ascend. | |
| pivotField.setIsAscendSort(true); | |
| //Setting the field auto sort using the field itself. | |
| pivotField.setAutoSortField(-5); | |
| //Setting autoShow options. | |
| //Setting the field auto show. | |
| pivotField.setIsAutoShow(true); | |
| //Setting the field auto show ascend. | |
| pivotField.setIsAscendShow(false); | |
| //Setting the auto show using field(data field). | |
| pivotField.setAutoShowField(0); | |
| //Saving the Excel file | |
| workbook.save(dataDir + "output.xls"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| var wb = new AsposeCells.Workbook(dataDir + "input.xlsx"); | |
| var pt = wb.getWorksheets().get(0).getPivotTables().get(0); | |
| //Indicating if or not display the empty cell value | |
| pt.setDisplayNullString(true); | |
| //Indicating the null string | |
| pt.setNullString("null"); | |
| pt.calculateData(); | |
| pt.setRefreshDataOnOpeningFile(false); | |
| wb.save(dataDir + "output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
| const AsposeCells = require("aspose.cells.node"); | |
| var wb = new AsposeCells.Workbook("source.xlsx"); | |
| var wsPivot = wb.getWorksheets().add("pvtNew Hardware"); | |
| var wsData = wb.getWorksheets().get("New Hardware - Yearly"); | |
| // Get the pivottables collection for the pivot sheet | |
| var pivotTables = wsPivot.getPivotTables(); | |
| // Add PivotTable to the worksheet | |
| var index = pivotTables.add("='New Hardware - Yearly'!A1:D621", "A3", "HWCounts_PivotTable"); | |
| // Get the PivotTable object | |
| var pvtTable = pivotTables.get(index); | |
| // Add vendor row field | |
| pvtTable.addFieldToArea(AsposeCells.PivotFieldType.Row, "Vendor"); | |
| // Add item row field | |
| pvtTable.addFieldToArea(AsposeCells.PivotFieldType.Row, "Item"); | |
| // Add data field | |
| pvtTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "2014"); | |
| // Turn off the subtotals for the vendor row field | |
| var pivotField = pvtTable.getRowFields().get("Vendor"); | |
| pivotField.setSubtotals(AsposeCells.PivotFieldSubtotalType.None, true); | |
| // Turn off grand total | |
| pvtTable.setColumnGrand(false); | |
| /* | |
| * Please call the PivotTable.refreshData() and PivotTable.calculateData() | |
| * before using PivotItem.setPosition, | |
| * PivotItem.setPositionInSameParentNode and PivotItem.move methods. | |
| */ | |
| pvtTable.refreshData(); | |
| pvtTable.calculateData(); | |
| pvtTable.getRowFields().get("Item").getPivotItems().get("4H12").setPositionInSameParentNode(0); | |
| pvtTable.getRowFields().get("Item").getPivotItems().get("DIF400").setPositionInSameParentNode(3); | |
| /* | |
| * As a result of using PivotItem.setPositionInSameParentNode, | |
| * it will change the original sort sequence. | |
| * So when you use PivotItem.setPositionInSameParentNode in another parent node. | |
| * You need call the method named "calculateData" again. | |
| */ | |
| pvtTable.calculateData(); | |
| pvtTable.getRowFields().get("Item").getPivotItems().get("CA32").setPositionInSameParentNode(1); | |
| pvtTable.getRowFields().get("Item").getPivotItems().get("AAA3").setPositionInSameParentNode(2); | |
| // Save file | |
| wb.save("output_out.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| //For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
| //The path to the documents directory. | |
| var dataDir = RunExamples.GetDataDir("."); | |
| //Load source excel file containing sample pivot table | |
| var wb = new AsposeCells.Workbook(dataDir + "sample-pivot-table.xlsx"); | |
| //Access first worksheet that contains pivot table data | |
| var dataSheet = wb.getWorksheets().get(0); | |
| //Access cell A3 and sets its data | |
| var cells = dataSheet.getCells(); | |
| var cell = cells.get("A3"); | |
| cell.putValue("FooBar"); | |
| //Access cell B3, sets its data. We set B3 a very long string which has more than 255 characters | |
| var longStr = "Very long text 1. very long text 2. very long text 3. very long text 4. very long text 5. very long text 6. very long text 7. very long text 8. very long text 9. very long text 10. very long text 11. very long text 12. very long text 13. very long text 14. very long text 15. very long text 16. very long text 17. very long text 18. very long text 19. very long text 20. End of text." | |
| cell = cells.get("B3"); | |
| cell.putValue(longStr) | |
| //Print the length of cell B3 string | |
| console.log("Length of original data string: " + cell.getStringValue().length); | |
| //Access cell C3 and sets its data | |
| cell = cells.get("C3"); | |
| cell.putValue("closed"); | |
| //Access cell D3 and sets its data | |
| cell = cells.get("D3"); | |
| cell.putValue("2016/07/21"); | |
| //Access the second worksheet that contains pivot table | |
| var pivotSheet = wb.getWorksheets().get(1); | |
| //Access the pivot table | |
| var pivotTable = pivotSheet.getPivotTables().get(0); | |
| //IsExcel2003Compatible property tells if PivotTable is compatible for Excel2003 while refreshing PivotTable. | |
| //If it is true, a string must be less than or equal to 255 characters, so if the string is greater than 255 characters, | |
| //it will be truncated. If false, a string will not have the aforementioned restriction. The default value is true. | |
| pivotTable.setIsExcel2003Compatible(true); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Check the value of cell B5 of pivot sheet. | |
| //It will be 255 because we have set IsExcel2003Compatible property to true. All the data after 255 characters has been truncated | |
| var b5 = pivotSheet.getCells().get("B5"); | |
| console.log("Length of cell B5 after setting IsExcel2003Compatible property to True: " + b5.getStringValue().length); | |
| //Now set IsExcel2003Compatible property to false and again refresh | |
| pivotTable.setIsExcel2003Compatible(false); | |
| pivotTable.refreshData(); | |
| pivotTable.calculateData(); | |
| //Now it will print 383 the original length of cell data. The data has not been truncated now. | |
| b5 = pivotSheet.getCells().get("B5"); | |
| print("Length of cell B5 after setting IsExcel2003Compatible property to False: " + b5.getStringValue().length); | |
| //Set the row height and column width of cell B5 and also wrap its text | |
| pivotSheet.getCells().setRowHeight(b5.getRow(), 100); | |
| pivotSheet.getCells().setColumnWidth(b5.getColumn(), 65); | |
| var st = b5.getStyle(); | |
| st.setIsTextWrapped(true); | |
| b5.setStyle(st); | |
| //Save workbook in xlsx format | |
| wb.save(dataDir + "SpecifyCompatibility_out_.xlsx", AsposeCells.SaveFormat.Xlsx); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Load sample Excel file containing a table. | |
| var workbook = new AsposeCells.Workbook("sampleCreateSlicerToExcelTable.xlsx"); | |
| // Access first worksheet. | |
| var worksheet = workbook.getWorksheets().get(0); | |
| // Access first table inside the worksheet. | |
| var table = worksheet.getListObjects().get(0); | |
| // Add slicer | |
| var idx = worksheet.getSlicers().add(table, 0, "H5"); | |
| // Save the workbook in output XLSX format. | |
| workbook.save("outputCreateSlicerToExcelTable.xlsx", AsposeCells.SaveFormat.Xlsx); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Load sample Excel file containing pivot table. | |
| var wb = new AsposeCells.Workbook("sampleCreateSlicerToPivotTable.xlsx"); | |
| // Access first worksheet. | |
| var ws = wb.getWorksheets().get(0); | |
| // Access first pivot table inside the worksheet. | |
| var pt = ws.getPivotTables().get(0); | |
| // Add slicer relating to pivot table with first base field at cell B22. | |
| var idx = ws.getSlicers().add(pt, "B22", pt.getBaseFields().get(0)); | |
| // Access the newly added slicer from slicer collection. | |
| var slicer = ws.getSlicers().get(idx); | |
| // Save the workbook in output XLSX format. | |
| wb.save("outputCreateSlicerToPivotTable.xlsx", AsposeCells.SaveFormat.Xlsx); | |
| // Save the workbook in output XLSB format. | |
| wb.save("outputCreateSlicerToPivotTable.xlsb", AsposeCells.SaveFormat.Xlsb); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Load sample Excel file containing a table. | |
| var workbook = new AsposeCells.Workbook("SampleSlicerChart.xlsx"); | |
| // Save the workbook to pdf format. | |
| workbook.save("SampleSlicerChart.pdf", AsposeCells.SaveFormat.Pdf); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Load sample Excel file containing pivot table. | |
| var wb = new AsposeCells.Workbook("input.xlsx"); | |
| // Access second worksheet. | |
| var sheet = wb.getWorksheets().get(1); | |
| // Access first pivot table inside the worksheet. | |
| var pivot = sheet.getPivotTables().get(0); | |
| // Add timeline relating to pivot table | |
| var index = sheet.getTimelines().add(pivot, 15, 1, "Ship Date"); | |
| // Access the newly added timeline from timeline collection. | |
| var timeline = sheet.getTimelines().get(index); | |
| wb.save("output.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| // Load sample Excel file containing pivot table. | |
| var wb = new AsposeCells.Workbook("input.xlsx"); | |
| // Access second worksheet. | |
| var sheet = wb.getWorksheets().get(1); | |
| // Add timeline relating to pivot table | |
| var timeline = sheet.getTimelines().get(0); | |
| var options = new AsposeCells.ImageOrPrintOptions(); | |
| options.setImageType(AsposeCells.ImageType.Png); | |
| // Get timeline shape object by timeline's name | |
| var timeLineShape = sheet.getShapes().get(timeline.getName()); | |
| timeLineShape.toImage("out.png", options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AsposeCells = require("aspose.cells.node"); | |
| var workbook = new AsposeCells.Workbook("sample.xlsx"); | |
| var cells = workbook.getWorksheets().get(0).getCells(); | |
| var cell = cells.get("A1"); | |
| console.log("Before updating the font settings...."); | |
| var fnts = cell.getCharacters(); | |
| var count = fnts.length; | |
| for (var i = 0; i < count; i++) | |
| { | |
| console.log(fnts[i].getFont().getName()); | |
| } | |
| // Modify the first FontSetting Font Name | |
| fnts[0].getFont().setName("Arial"); | |
| // And update it using SetCharacters() method | |
| cell.setCharacters(fnts); | |
| console.log("After updating the font settings...."); | |
| fnts = cell.getCharacters(); | |
| for (var i = 0; i < count; i++) { | |
| console.log(fnts[i].getFont().getName()); | |
| } | |
| workbook.save("output.xlsx"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment