Java/ Add and Read Comments in Excel

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls.free</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
import com.spire.xls.*;

public class InsertComments {
public static void main(String[] args){
//Load a Excel file
Workbook workbook = new Workbook();
workbook.loadFromFile("Sales1.xlsx");

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

//Create fonts
ExcelFont font = workbook.createFont();
font.setFontName("Arial");
font.setSize(11);
font.setKnownColor(ExcelColors.Orange);
ExcelFont fontBlue = workbook.createFont();
fontBlue.setKnownColor(ExcelColors.LightBlue);
ExcelFont fontRed = workbook.createFont();
fontRed.setKnownColor(ExcelColors.Red);

//Add regular comment to specific cell range
CellRange range = sheet.getCellRange("A8");
range.getComment().setText("A new employee.");
range.autoFitColumns();

//Add rich text comment to specific cell range
range = sheet.getCellRange("F8");
range.getComment().getRichText().setText("Best sales of the month.");
range.getComment().getRichText().setFont(0, 10, fontRed);
range.getComment().getRichText().setFont(17, 23, fontBlue);

//Save the resultant file
workbook.saveToFile("AddComments.xlsx", ExcelVersion.Version2013);
}
}
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class ReadComments {
public static void main(String[] args){
//Load Excel file
Workbook workbook = new Workbook();
workbook.loadFromFile("AddComments.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Print out the comment
System.out.println("The first comment: " + sheet.getCellRange("A8").getComment().getText());
System.out.println("The second comment: " + sheet.getCellRange("F8").getComment().getRichText().getRtfText());
}
}

--

--

--

Sharing Java Code

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

Recommended from Medium

How to install, upgrade or downgrade a specific version of Laravel?

CSS Grid: What is CSS Grid and Columns?

creating vs counting

What framework is a good choice for web developers?

Bumper APRs on the $EZ Bumper farming programs on @0xPolygon : 👉@_DFyn Dual Farms - @ 153%…

App modularization and module lazy loading at Instagram and beyond

How to Improve the Efficiency of Development and Testing team

Add a item to an array in a record in MongoDB

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

How To Read Emails Using Java Imaps? — Devstringx

Java Imaps

Spring Annotations — 1 — @Autowired, @Qualifier

TOP Git Commands, Every Programmer Must know

JAVA & Git-Hub