Table of Contents
Install with Maven
<dependency> <groupId>e-iceblue</groupId> <artifactId>spire.xls</artifactId> <version>15.5.1</version> </dependency>
Related Links
Working with Excel data can get overwhelming when numbers pile up and insights get buried. Data bars offer a quick, visual way to highlight values directly within cells, making it easy to spot trends and compare numbers at a glance. Whether it’s a sales report, project tracker, or budget sheet, data bars help turn raw data into clear visuals—no charts needed. In this guide, you’ll learn how to add data bars in Excel, both manually and with Java.
- Add Data Bars to Cells in Excel Manually
- Limitations of Manual Operation
- Add Data Bars in Excel Using Java
- Conclusion
How to Add Data Bars to Cells in Excel (Manual Method)
In this section, we’ll walk through the simple steps to add data bars to cells in Excel manually. This method allows you to quickly visualize your data without complex formulas, making it easy to highlight trends and compare values directly within your spreadsheet.
Steps to Add Data Bars in Excel:
- Open your source Excel file.
- Select the range of cells where you want to add data bars.
- Go to the Home tab.
- Click the Conditional Formatting dropdown arrow.
- In the expanded menu, select Data Bars, then choose either Gradient Fill or Solid Fill based on your preference.
Tip: If you want to add solid fill red data bars in Excel, just choose the "Red Data Bar" in the expanded menu.

Limitations of Manual Operation
While manually adding data bars in Excel can be useful for smaller tasks, there are several limitations:
-
Time-Consuming for Multiple Files: If you need to apply data bars to many spreadsheets or worksheets, doing it manually becomes a repetitive and time-consuming process. This is especially problematic when dealing with large datasets or multiple reports.
-
Inconsistent Chart Styles: When working with multiple sheets or teams, manually adding data bars can lead to inconsistencies in chart styles. Without a standardized approach, different users may apply different formats, resulting in uneven visual presentation across reports.
-
Not Ideal for Automated Reporting: For businesses or teams that need to generate reports frequently, manual data bar insertion is impractical. It’s inefficient when dealing with dynamic data or when reports need to be updated regularly, as each update requires manual intervention.
How to Add Data Bars in Excel Using Java
Now that we've covered the limitations of manual data bars, let's move on to an automated solution using Java. For this, we’ll be using Spire.XLS for Java, a powerful library that allows seamless manipulation of Excel files programmatically.
How to Get Started with Spire.XLS for Java
To get started, simply download Spire.XLS or include it in your Java project using Maven:
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls</artifactId>
<version>15.12.15</version>
</dependency>
</dependencies>
Once installed, you can start using it to automate your Excel tasks, including adding data bars to your sheets or adding traffic light icons. Now, let’s jump into the code!
The code below demonstrates how to add a light green solid data bar in Excel to visualize the product inventory levels:
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
workbook.loadFromFile("/sales report.xlsx");
// Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);
// Get the specific cell range
CellRange range = sheet.getCellRange("B2:B15");
// Add the conditional formatting of data bars in the cell range
IConditionalFormat format = range.getConditionalFormats().addCondition();
format.setFormatType( ConditionalFormatType.DataBar);
// Set color for the data bars
format.getDataBar().setBarColor(new Color(180, 220, 180));
format.getDataBar().setShowValue(true);
// Save to file
workbook.saveToFile("/ApplyDataBars.xlsx", ExcelVersion.Version2013);
}
}

Key Steps Explained:
- Create a Workbook object and load the Excel file
Create a new Workbook object, then load the existing Excel file with Workbook.loadFromFile() method.
- Get the worksheet and define the cell range for conditional formatting
Access the desired worksheet using Workbook.getWorksheets().get() method; and specify the range of cells where you want to apply data bars with Worksheet.getCellRange().
- Add a conditional format to the specified cell range
Use ConditionalFormats. addCondition() method to add a new conditional format to the selected range. Then call ConditionalFormatWrapper.setFormatType() method to set the conditional format type as data bar.
- Set the color of the data bars and choose whether to show values in the cells
Configure the data bar’s color using DataBar().setBarColor() method; and optionally, enable or disable the display of values in the cells with DataBar().setShowValue() method.
Tip: The RGB values in the code represent light green. If you prefer not to adjust the parameters, you can easily add green data bars in Excel by simply setting it to green with:format.getDataBar().setBarColor(Color.GREEN)
- Save the modified Excel workbook as a new file
Save the updated workbook with Workbook.saveToFile() method.
Conclusion
In this guide, we’ve learned how to add data bars in Excel using both manual and Java-based methods. Data bars are a powerful tool for quickly visualizing your data, whether you're working with sales reports, inventory management, or financial data. By automating the process with Java, you can save time and ensure consistency across multiple files.
Ready to boost your Excel productivity? Start applying data bars today and explore more automation options with Spire.XLS for Java!
ALSO READ: