Last active
July 8, 2024 18:15
-
-
Save aspose-com-kb/c31d20177155bf3bf85b96c213668c60 to your computer and use it in GitHub Desktop.
Add Sparklines in Excel using Java. For further details: https://kb.aspose.com/cells/java/add-sparklines-in-excel-using-java/
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
import com.aspose.cells.*; | |
public class Main | |
{ | |
public static void main(String[] args) throws Exception // Sparklines in Excel | |
{ | |
// Set the licenses | |
new License().setLicense("License.lic"); | |
// Create a Workbook object | |
Workbook wb = new Workbook(); | |
Worksheet worksheet = wb.getWorksheets().get(0); | |
worksheet.getCells().get("A2").putValue(200); | |
worksheet.getCells().get("B2").putValue(189); | |
worksheet.getCells().get("C2").putValue(150); | |
worksheet.getCells().get("D2").putValue(250); | |
// Create the cell area | |
CellArea ca = new CellArea(); | |
ca.StartRow = 1; | |
ca.StartColumn = 4; | |
ca.EndRow = 1; | |
ca.EndColumn = 4; | |
// Add a group | |
int idx = worksheet.getSparklineGroups().add(SparklineType.LINE, worksheet.getName() + "!A2:D2", false, ca); | |
SparklineGroup sparklineGroup = worksheet.getSparklineGroups().get(idx); | |
// Add a spark line | |
sparklineGroup.getSparklines().add(worksheet.getName() + "!A2:D2", 1, 4); | |
// Set the color | |
CellsColor cellsColor = wb.createCellsColor(); | |
cellsColor.setColor(Color.getGreen()); | |
sparklineGroup.setSeriesColor(cellsColor); | |
// Saving the Excel file | |
wb.save("output.xlsx"); | |
System.out.println("Spark lines added successfully"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment