0% found this document useful (0 votes)
90 views2 pages

CellStyle Style

This document creates a cell style in Java code that sets the background color to aqua and the fill pattern to big spots. It applies this style to a row. The code imports the necessary POI libraries, creates a workbook and sheet, defines the cell style with the background formatting, creates a cell and row, sets the cell value, applies the cell style to the cell and row, and writes the workbook out to an Excel file.

Uploaded by

Manuel Bryant
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views2 pages

CellStyle Style

This document creates a cell style in Java code that sets the background color to aqua and the fill pattern to big spots. It applies this style to a row. The code imports the necessary POI libraries, creates a workbook and sheet, defines the cell style with the background formatting, creates a cell and row, sets the cell value, applies the cell style to the cell and row, and writes the workbook out to an Excel file.

Uploaded by

Manuel Bryant
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CellStyle style = wb.createCellStyle(); style.setFillBackgroundColor(IndexedColors.AQUA.getIndex()); style.setFillPattern(CellStyle.BIG_SPOTS); row.

setRowStyle(style);
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.PatternFormatting; import java.io.FileOutputStream; import java.io.File; import java.io.IOException; public class ExcelCellFormat { public static void main(String[] args) { // // Create an instance of workbook and sheet // HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); // // Create an instance of HSSFCellStyle which will be use to format the // cell. Here we define the cell top and bottom border and we also // define the background color. // HSSFCellStyle style = workbook.createCellStyle(); /*style.setBorderTop((short) 1); // double lines border style.setBorderBottom((short) 1); // single line border style.setBorderLeft((short) 1); style.setBorderRight((short) 1);*/ style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(PatternFormatting. SOLID_FOREGROUND); // // We also define the font that we are going to use for displaying the // data of the cell. We set the font to ARIAL with 20pt in size and // make it BOLD and give blue as the color. // HSSFFont font = workbook.createFont(); font.setFontName(HSSFFont. FONT_ARIAL); font.setFontHeightInPoints(( short) 20); font.setBoldweight(HSSFFont. BOLDWEIGHT_BOLD); font.setColor(HSSFColor.BLACK. index); style.setFont(font); // // We create a simple cell, set its value and apply the cell style.

// HSSFRow row = sheet.createRow(1); HSSFCell cell = row.createCell(5); cell.setCellValue(new HSSFRichTextString("BT SUPPLY CHAIN")); cell.setCellStyle(style); sheet.autoSizeColumn((short) 1); row.setRowStyle(style); // // Finally we write out the workbook into an excel file. // FileOutputStream fos = null; try { fos = new FileOutputStream(new File("ExcelDemo.xls")); workbook.write(fos); } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy