Add Data Bars in Excel using Java

Import JAR Dependency (2 Method)


Sample Code

import com.spire.xls.*;
import com.spire.xls.core.*;
import java.awt.*;

public class applyDataBars {
public static void main(String[] args) {

//Create a Workbook instance
Workbook workbook = new Workbook();

//Load an Excel file

//Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);

//Get the specific cell range
CellRange range = sheet.getCellRange("B2:B13");

//Add the condotional format of data bar to the cell range
IConditionalFormat format = range.getConditionalFormats().addCondition();
format.setFormatType( ConditionalFormatType.DataBar);

//Set color for the data bar
format.getDataBar().setBarColor( Color.GREEN);

//Save to file
workbook.saveToFile("ApplyDataBars.xlsx", ExcelVersion.Version2013);




Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Create Java Project From Maven

Let’s Understand about GitOps

Design Decisions for the First Embedded Analytics Open-Source Framework

How to browse project files on GitHub as if you are browsing in your IDE

How to write a program to find the factorial of a number explain in c++ ?

Exception handling in Scala

My First 100 days of Code…

Idena hard fork announcement

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Java/ Convert Excel to XPS

Solution for “Not able to find Java executable or version” in Jenkins

Log4Shell in SQL ? JNDI exploit for Java H2 (CVE-2021–42392)

Java Rest API with Spring Boot & JPA(Part-1)