Last active
July 8, 2024 18:13
-
-
Save aspose-com-kb/6f8e8d118eeb97ddab103c2d3ca9f3d8 to your computer and use it in GitHub Desktop.
Add Sparklines in Excel with Node.js. For further details: https://kb.aspose.com/cells/nodejs/add-sparklines-in-excel-with-node.js/
This file contains 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
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Set the license | |
new aspose.cells.License().setLicense("License.lic"); | |
// Instantiate a Workbook object | |
let wb = new aspose.cells.Workbook(); | |
let sheet = wb.getWorksheets().get(0); | |
// Set values in cells | |
sheet.getCells().get("A1").putValue(10); | |
sheet.getCells().get("B1").putValue(2); | |
sheet.getCells().get("C1").putValue(1); | |
sheet.getCells().get("D1").putValue(3); | |
// Define the CellArea and add a group | |
let ca = new aspose.cells.CellArea(); | |
ca.StartRow = 0; | |
ca.StartColumn = 4; | |
ca.EndRow = 0; | |
ca.EndColumn = 4; | |
let idx = sheet.getSparklineGroupCollection().add(aspose.cells.SparklineType.LINE, `${sheet.getName()}!A1:D1`, false, ca); | |
// Access the group and add a sparkline | |
let sparklineGroup = sheet.getSparklineGroupCollection().get(idx); | |
sparklineGroup.getSparklineCollection().add(`${sheet.getName()}!A1:D1`, 0, 4); | |
// Customize the sparkline color | |
let cellsColor = wb.createCellsColor(); | |
cellsColor.setColor(aspose.cells.Color.getGreen()); | |
sparklineGroup.setSeriesColor(cellsColor); | |
// Save the Excel file | |
wb.save("output.xlsx"); | |
console.log("Sparklines added successfully"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment