[wp-night-mode-button]
In this post , we will see how to set style in excel using apache poi.
You can put cell style with below code:
// create font
XSSFFont font= workbook.createFont();
font.setFontHeightInPoints((short)10);
font.setFontName("Arial");
font.setColor(IndexedColors.WHITE.getIndex());
font.setBold(true);
font.setItalic(false);
// Create cell style
CellStyle style=workbook.createCellStyle();;
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
// Setting font to style
style.setFont(font);
// Setting cell style
cell.setCellStyle(style);
Java Program :
package org.arpit.java2blog;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class WriteExcelMain {
public static void main(String[] args) throws IOException {
writeFileUsingPOI();
}
public static void writeFileUsingPOI() throws IOException
{
//create blank workbook
XSSFWorkbook workbook = new XSSFWorkbook();
//Create a blank sheet
XSSFSheet sheet = workbook.createSheet("Country");
ArrayList
When you run above program, you will get following output:
CountriesDetails.xlsx has been created successfully
Lets see content of CountriesDetails.xlsx now.
Share this
[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]
Author
[author_social_connect follow_on="facebook,twitter,linkedin,reddit"]