Adding Custom colours to Excel sheet using Apache POI - java

Can anyone explain how to add Custom colours either using (rgb values or hex values ) to an excelsheet sheet(either in foreground or background) using Cellstyle in Apche poi to a Excelsheet(XSSF Workbook)?

Setting custom colors depends on the kind of Excel file (Office Open XML format *.xlsx vs. BIFF format *.xls). And it might be different using different versions of apache poi because of deprecation.
Using Office Open XML format *.xlsx we can simply set new colors using constructor of XSSFColor. In apache poi 4.0.0 XSSFColor(byte[] rgb, IndexedColorMap colorMap) can be used. IndexedColorMap can be null if no additional color map shall be used instead of the default one.
Using BIFF format *.xls only indexed colors are usable. But temporary overwriting some of the indexed colors is possible.
Following code shows both used for setting a cells's fill color. The used custom color is RGB(112,134,156). Using HSSF(BIFF format *.xls) the indexed color HSSFColor.HSSFColorPredefined.LIME will be temporary overwritten.
Note, the following is tested and works using apache poi 4.0.0. No guarantee using other versions.
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
public class CreateExcelCustomColor {
public static void main(String[] args) throws Exception {
Workbook workbook = new XSSFWorkbook();
//Workbook workbook = new HSSFWorkbook();
CellStyle cellcolorstyle = workbook.createCellStyle();
cellcolorstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
byte[] rgb = new byte[]{(byte)112, (byte)134, (byte)156};
if (cellcolorstyle instanceof XSSFCellStyle) {
XSSFCellStyle xssfcellcolorstyle = (XSSFCellStyle)cellcolorstyle;
xssfcellcolorstyle.setFillForegroundColor(new XSSFColor(rgb, null));
} else if (cellcolorstyle instanceof HSSFCellStyle) {
cellcolorstyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.LIME.getIndex());
HSSFWorkbook hssfworkbook = (HSSFWorkbook)workbook;
HSSFPalette palette = hssfworkbook.getCustomPalette();
palette.setColorAtIndex(HSSFColor.HSSFColorPredefined.LIME.getIndex(), rgb[0], rgb[1], rgb[2]);
}
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(0).createCell(0);
cell.setCellStyle(cellcolorstyle);
FileOutputStream out = null;
if (workbook instanceof XSSFWorkbook) {
out = new FileOutputStream("CreateExcelCustomColor.xlsx");
} else if (workbook instanceof HSSFWorkbook) {
out = new FileOutputStream("CreateExcelCustomColor.xls");
}
workbook.write(out);
out.close();
workbook.close();
}
}

Related

How to create an excel sheet with text format?

I am using SXSSFWorkbook for creating excel file. I know how to create data format for excel cell like this:
DataFormat fmt = workbook.createDataFormat();
CellStyle cellStyleText = workbook.createCellStyle();
cellStyleText.setDataFormat(
fmt.getFormat("#"));
But this one is good when you are trying to write the datas into the cell and at the same time indicate its format. But I want to set ALL cells in excel to text format, NOT only the cells I am writing datas into. In default it creates sheet with general cell format. So I would like to know is there any tips for setting this cells into text format?
At first, having all cells using text data format in a spreadsheet is not really a good idea. In such a sheet no formulas will work. This contradicts the main usage of spreadsheets.
But your question is mainly about how to set a special default cell style for each cell in the sheet. In your case the special text style but that also could be any other style.
One solution would be using a template which already has that special style set for all cells. Then one could do something like this:
...
Workbook workbook = WorkbookFactory.create(new FileInputStream("./template.xlsx"));
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook((XSSFWorkbook)workbook);
Sheet sxssfSheet = sxssfWorkbook.getSheetAt(0);
// stream in the data into the sheet
...
If you need doing this from scratch, then one could start having a new XSSFWorkbook. Then create the needed cell style and apply this for all cells.
The class ColumnHelper provides methods to set a default style to all cells in one given column. But it lacks methods to do this for all columns. So org.apache.poi.xssf.usermodel.helpers.ColumnHelper needs to be extended to provide that functionality.
Following complete example shows this:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
class CreateExcelDefaultColumnStyle {
public static void main(String[] args) throws Exception {
Workbook workbook = new XSSFWorkbook();
DataFormat format = workbook.createDataFormat();
CellStyle textStyle = workbook.createCellStyle();
textStyle.setDataFormat(format.getFormat("#"));
Sheet sheet = workbook.createSheet();
MyColumnHelper columnHelper = new MyColumnHelper(((XSSFSheet)sheet).getCTWorksheet());
columnHelper.setColDefaultStyle(0, workbook.getSpreadsheetVersion().getLastColumnIndex(), textStyle);
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook((XSSFWorkbook)workbook);
Sheet sxssfSheet = sxssfWorkbook.getSheetAt(0);
// stream in the data into the sheet
FileOutputStream fileout = new FileOutputStream("./Excel.xlsx");
sxssfWorkbook.write(fileout);
fileout.close();
sxssfWorkbook.close();
sxssfWorkbook.dispose();
}
}
class MyColumnHelper extends org.apache.poi.xssf.usermodel.helpers.ColumnHelper {
public MyColumnHelper(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet worksheet) {
super(worksheet);
}
public void setColDefaultStyle(long fromCol, long toCol, CellStyle style) {
setColDefaultStyle(fromCol, toCol, style.getIndex());
}
public void setColDefaultStyle(long fromCol, long toCol, int styleId) {
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol col = getOrCreateColumn1Based(fromCol+1, true);
col.setMax(toCol+1);
col.setStyle(styleId);
}
}
After running this code Excel.xls contains one sheet having all cells using the cell style where data format "Text" is set. It is tested and works using current apache poi 5.2.2.

Apache Poi setActiveCell() for multiple cells

I'm trying to use the method sheet.setActiveCell(CellAddress addr) to set a range of multiple cells active at the same time. I've tryed with multiple versions of Apache poi-ooxml library and now i'm using 3.16 which also supports the method sheet.setActiveCell(String addr)(I know 3.16 is old but the issue stays the same also with the latest version).
Following the suggestions on this question: Is it possible to set the active range with Apache POI XSSF?
I've managed to get it to work, both with the custom CellAddress and the String in the format "A1:B5".
The problem is that every time I try to open an xlsx in which a range of cells has been set to active using apache poi, I get an error message from Excel saying that the file is damaged and need to be recovered. If I do, the recovery completes correctly, but this error is annoying since I have to open a great number of these files each day.
Is there a way to avoid this error from excel (maybe modifying the creation of the xlsx or changing some setting in Excel)?
Only one cell can be the active cell. And Sheet.setActiveCell only sets that one active cell. So sheet.setActiveCell("A1:B5") will work if setActiveCell(String addr) is available but it leads to a corrupted sheet. That's why it was removed.
Multiple cells can be selected. But there are no methods to set the selected cells in apache poi's high level classes. So the underlying low level classes needs to be used. Doing this one needs differentiate between XSSF and HSSF because different low level classes needs to be used.
Following complete example sets active cell to B2. This also sets sheet view having selection and active cell to that one given cell B2. Then it uses low level methods of XSSF and HSSF to set the selection to B2:E5.
import java.io.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
class CreateExcelSelectMultipleCells {
public static void main(String[] args) throws Exception {
try (Workbook workbook = new XSSFWorkbook(); FileOutputStream out = new FileOutputStream("Excel.xlsx") ) {
//try (Workbook workbook = new HSSFWorkbook(); FileOutputStream out = new FileOutputStream("Excel.xls") ) {
Sheet sheet = workbook.createSheet();
Row row;
Cell cell;
for (int r = 0; r < 6; r++) {
row = sheet.createRow(r);
for (int c = 0; c < 6; c++) {
cell = row.createCell(c);
cell.setCellValue("R" + (r+1) + "C" + (c+1));
}
}
// set active cell; this also sets sheet view having selection and active cell to one given cell
sheet.setActiveCell(new CellAddress("B2"));
// set selected cells
if (sheet instanceof XSSFSheet) {
XSSFSheet xssfSheet = (XSSFSheet) sheet;
xssfSheet.getCTWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).setSqref(
java.util.Arrays.asList("B2:E5"));
} else if (sheet instanceof HSSFSheet) {
HSSFSheet hssfSheet = (HSSFSheet) sheet;
org.apache.poi.hssf.record.SelectionRecord selectionRecord = hssfSheet.getSheet().getSelection();
java.lang.reflect.Field field_6_refs = org.apache.poi.hssf.record.SelectionRecord.class.getDeclaredField("field_6_refs");
field_6_refs.setAccessible(true);
field_6_refs.set(
selectionRecord,
new org.apache.poi.hssf.util.CellRangeAddress8Bit[] { new org.apache.poi.hssf.util.CellRangeAddress8Bit(1,4,1,4) }
);
}
workbook.write(out);
}
}
}

copy cells between Excel workbooks with Apache POI

I'm trying to copy from cells from one workbook to another with the latest version of Apache POI (4.1.2).
If both workbooks are .xlsx files, everything works fine. But if the source workbook is an (old) .xls file and the destination workbook is an .xlsx file, the following code fails
// Copy style from old cell and apply to new cell
CellStyle newCellStyle = targetWorkbook.createCellStyle();
newCellStyle.cloneStyleFrom(sourceCell.getCellStyle());
targetCell.setCellStyle(newCellStyle);
The exception that's thrown is:
java.lang.IllegalArgumentException: Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle
If we can't use cloneStyleFrom when the files (or Workbook objects) are of different types, how can we convert a HSSFCellStyle object to a XSSFCellStyle?
The answer to your question "How can we convert a HSSFCellStyle object to a XSSFCellStyle?" is: We can't do that using apache poi 4.1.2. This simply is not supported as clearly stated in CellStyle.cloneStyleFrom: "However, both of the CellStyles will need to be of the same type (HSSFCellStyle or XSSFCellStyle)."
The other question is: Should we at all convert one cell style into another? Or what use cases are there for CellStyle.cloneStyleFrom at all? In my opinion there are none. There are Excel limitations for the count of unique cell formats/cell styles. See Excel specifications and limits. So we should not create a single cell style for each single cell because then those limitations will be reached very fast. So instead of cloning cell styles we should get the style properties from source style style1 and then using CellUtil.setCellStyleProperties to set those style properties to the other cell in question. This method attempts to find an existing CellStyle that matches the cell's current style plus styles properties in properties. A new style only is created if the workbook does not contain a matching style.
Since your question title is "Copy cells between Excel workbooks with Apache POI", I have created a working draft of how I woud do this.
The following code first gets a existent Workbook.xls as HSSFWorkbook wb1 and creates a new XSSFWorkbook wb2. Then it loops over all cells of the first sheet of wb1 and tries copying those cells into the first sheet of wb2. To do so there is a method copyCells(Cell cell1, Cell cell2) which uses copyStyles(Cell cell1, Cell cell2). The latter gets the style properties from source style style1 got from cell1 and then uses CellUtil.setCellStyleProperties to set those style properties to cell2. For copying fonts copyFont(Font font1, Workbook wb2) is used. This tries creating new fonts in wb2 only if such a font is not already present in that workbook. This is necessary because there also is a limit of unique font types per workbook in Excel.
Working example:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellUtil;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.*;
class ExcelCopyCells {
static Font copyFont(Font font1, Workbook wb2) {
boolean isBold = font1.getBold();
short color = font1.getColor();
short fontHeight = font1.getFontHeight();
String fontName = font1.getFontName();
boolean isItalic = font1.getItalic();
boolean isStrikeout = font1.getStrikeout();
short typeOffset = font1.getTypeOffset();
byte underline = font1.getUnderline();
Font font2 = wb2.findFont(isBold, color, fontHeight, fontName, isItalic, isStrikeout, typeOffset, underline);
if (font2 == null) {
font2 = wb2.createFont();
font2.setBold(isBold);
font2.setColor(color);
font2.setFontHeight(fontHeight);
font2.setFontName(fontName);
font2.setItalic(isItalic);
font2.setStrikeout(isStrikeout);
font2.setTypeOffset(typeOffset);
font2.setUnderline(underline);
}
return font2;
}
static void copyStyles(Cell cell1, Cell cell2) {
CellStyle style1 = cell1.getCellStyle();
Map<String, Object> properties = new HashMap<String, Object>();
//CellUtil.DATA_FORMAT
short dataFormat1 = style1.getDataFormat();
if (BuiltinFormats.getBuiltinFormat(dataFormat1) == null) {
String formatString1 = style1.getDataFormatString();
DataFormat format2 = cell2.getSheet().getWorkbook().createDataFormat();
dataFormat1 = format2.getFormat(formatString1);
}
properties.put(CellUtil.DATA_FORMAT, dataFormat1);
//CellUtil.FILL_PATTERN
//CellUtil.FILL_FOREGROUND_COLOR
FillPatternType fillPattern = style1.getFillPattern();
short fillForegroundColor = style1.getFillForegroundColor(); //gets only indexed colors, no custom HSSF or XSSF colors
properties.put(CellUtil.FILL_PATTERN, fillPattern);
properties.put(CellUtil.FILL_FOREGROUND_COLOR, fillForegroundColor);
//CellUtil.FONT
Font font1 = cell1.getSheet().getWorkbook().getFontAt(style1.getFontIndexAsInt());
Font font2 = copyFont(font1, cell2.getSheet().getWorkbook());
properties.put(CellUtil.FONT, font2.getIndexAsInt());
//BORDERS
BorderStyle borderStyle = null;
short borderColor = -1;
//CellUtil.BORDER_LEFT
//CellUtil.LEFT_BORDER_COLOR
borderStyle = style1.getBorderLeft();
properties.put(CellUtil.BORDER_LEFT, borderStyle);
borderColor = style1.getLeftBorderColor();
properties.put(CellUtil.LEFT_BORDER_COLOR, borderColor);
//CellUtil.BORDER_RIGHT
//CellUtil.RIGHT_BORDER_COLOR
borderStyle = style1.getBorderRight();
properties.put(CellUtil.BORDER_RIGHT, borderStyle);
borderColor = style1.getRightBorderColor();
properties.put(CellUtil.RIGHT_BORDER_COLOR, borderColor);
//CellUtil.BORDER_TOP
//CellUtil.TOP_BORDER_COLOR
borderStyle = style1.getBorderTop();
properties.put(CellUtil.BORDER_TOP, borderStyle);
borderColor = style1.getTopBorderColor();
properties.put(CellUtil.TOP_BORDER_COLOR, borderColor);
//CellUtil.BORDER_BOTTOM
//CellUtil.BOTTOM_BORDER_COLOR
borderStyle = style1.getBorderBottom();
properties.put(CellUtil.BORDER_BOTTOM, borderStyle);
borderColor = style1.getBottomBorderColor();
properties.put(CellUtil.BOTTOM_BORDER_COLOR, borderColor);
CellUtil.setCellStyleProperties(cell2, properties);
}
static void copyCells(Cell cell1, Cell cell2) {
switch (cell1.getCellType()) {
case STRING:
/*
//TODO: copy HSSFRichTextString to XSSFRichTextString
RichTextString rtString1 = cell1.getRichStringCellValue();
cell2.setCellValue(rtString1); // this fails if cell2 is XSSF and rtString1 is HSSF
*/
String string1 = cell1.getStringCellValue();
cell2.setCellValue(string1);
break;
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell1)) {
Date date1 = cell1.getDateCellValue();
cell2.setCellValue(date1);
} else {
double cellValue1 = cell1.getNumericCellValue();
cell2.setCellValue(cellValue1);
}
break;
case FORMULA:
String formula1 = cell1.getCellFormula();
cell2.setCellFormula(formula1);
break;
//case : //TODO: further cell types
}
copyStyles(cell1, cell2);
}
public static void main(String[] args) throws Exception {
Workbook wb1 = WorkbookFactory.create(new FileInputStream("Workbook.xls"));
Workbook wb2 = new XSSFWorkbook();
Sheet sheet1 = wb1.getSheetAt(0);
Sheet sheet2 = wb2.createSheet();
Set<Integer> columns = new HashSet<Integer>();
Row row2 = null;
Cell cell2 = null;
for (Row row1 : sheet1) {
row2 = sheet2.createRow(row1.getRowNum());
for (Cell cell1 : row1) {
columns.add(cell1.getColumnIndex());
cell2 = row2.createCell(cell1.getColumnIndex());
copyCells(cell1, cell2);
}
}
wb1.close();
for (Integer column : columns) {
sheet2.autoSizeColumn(column);
}
FileOutputStream out = new FileOutputStream("Workbook.xlsx");
wb2.write(out);
out.close();
wb2.close();
}
}
If Workbook.xls looks like this:
then the resulting Workbook.xlsx looks like this:
Note: This is a working draft and needs to be completed. See TODO comments in the code. RichTextString cell values needs to be considered. Further cell types needs to be considered.
Method copyStyles only provides copying data format, fill pattern and fill foreground color (only for indexed colors), font and borders. Further cell style properties needs to be considered.

How to import both xls and xlsx files using java in spring mvc

In this method i used xssf class which is used to read xlsx file but we cant do it for xls file.for xls we need to have Hssf class .User can import any format there .My requirement,Is there any Class that can be used instead of xssf and hssf to read both kind of file. in my example i used xssf.
#RequestMapping(value="/import",method = RequestMethod.POST)
public ModelAndView imports(Model model, #RequestParam("excelFile") MultipartFile excelfile){
try {
List<DepartmentModel> lstUser = new ArrayList<>();
int i = 0;
XSSFWorkbook workbook = new XSSFWorkbook(excelfile.getInputStream());
XSSFSheet worksheet = workbook.getSheetAt(0);
while (i <= worksheet.getLastRowNum()) {
DepartmentModel user = new DepartmentModel();
XSSFRow row = worksheet.getRow(i++);
user.setHrName(row.getCell(0).getStringCellValue());
user.setDepartmentName(row.getCell(1).getStringCellValue());
user.setParentDepartment(row.getCell(2).getStringCellValue());
lstUser.add(user);
}
departmentService.updateList(lstUser);
model.addAttribute("lstUser", lstUser);
} catch (Exception e) {
e.printStackTrace();
}
return new ModelAndView("redirect:/listOfDepartment");
}
Im having another method which i used Hssf to read xls file.But iam having only one import button user can upload any type of file xls,xlsx but for import button i can have one action eigther go to xssf or hssf method.So i like to know is there any possible way to have botth in single method.Or any other super class to having property of both Xssf and Hssf Class.
For supporting both HSSF as well as XSSF for reading and rewriting *.xls and *.xlsx, you will using WorkbookFactory for creating Workbook. This is able creating Workbook from InputStream of *.xls as well as of *.xlsx files.
FileInputStream fileinputstream = new FileInputStream("pathToExcelFile.xls_or_.xlsx");
Workbook workbook = WorkbookFactory.create(fileinputstream);
Then, as long as possible, you will working with the interfaces of Package org.apache.poi.ss.usermodel instead of the special HSSF or XSSF classes.
This is not always possible since apache poi is in development until now. But if not possible you can detect via instanceof what object (HSSF or XSSF) you really are working with.
And for writing you will using the appropriate methods dependent of the instanceof the Workbook.
if (workbook instanceof XSSFWorkbook) {
workbook.write(new FileOutputStream("pathToExcelFile.xlsx"));
} else if (workbook instanceof HSSFWorkbook) {
workbook.write(new FileOutputStream("pathToExcelFile.xls"));
}
workbook.close();
Up to apache poi 3.17 Workbook.write has closed the OutputStream. Now in apache poi 4.0.* versions it not more closes the OutputStream. So we need using
FileOutputStream out = null;
if (workbook instanceof XSSFWorkbook) out = new FileOutputStream("pathToExcelFile.xlsx");
else if (workbook instanceof HSSFWorkbook) out = new FileOutputStream("pathToExcelFile.xls");
if (out != null) {
workbook.write(out);
out.close();
}
workbook.close();

Apache Poi Apply Gradient Color to Cell

i have been searching the web and found no real good example for applying a gradient color to an excel sheet cell using Apache Poi.
The example I found are pretty old and the classes not really exist anymore in the current Apache Poi version. I'm currently using Apache Poi version 3.16.
Can somebody point out the steps which are needed to apply a gradient color to excel sheet using the poi library. All hints are appreciated.
There is always still not a possibility to set gradient cell fills using the default actual apache poi versions.
So I suspect that the code you found was for XSSF (*.xlsx) and for the code you found it was just not mentioned that this code needs the full jar of all of the schemas ooxml-schemas-*.jar or poi-ooxml-full-*.jar in the class path as mentioned in faq-N10025.
The following example works but also needs the full jar of all of the schemas in the class path as mentioned in faq-N10025.
It first sets pattern fill settings to the CellStyle only to have some fill to get the fill index from it. Then it gets the low level CTFill used in this CellStyle. An then it unsets the pattern fill and then it sets the gradient fill.
To get informations about how to use CTFill one needs download the sources of ooxml-schemas and do javadoc. There is no API documentation for ooxml-schemas public available.
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTGradientFill;
public class CreateExcelCellGradientFillColor {
public static void main(String[] args) throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
XSSFCellStyle cellstyle = workbook.createCellStyle();
//set pattern fill settings only to have some fill to get the fill index from it
cellstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//get fill index used in this CellStyle
int fillidx = (int)cellstyle.getCoreXf().getFillId();
//get the low level CTFill used in this CellStyle
CTFill ctfill = workbook.getStylesSource().getFillAt(fillidx).getCTFill();
System.out.println(ctfill);
//unset the pattern fill
ctfill.unsetPatternFill();
//now low level set the gradient fill
byte[] rgb1 = new byte[3];
rgb1[0] = (byte) 0; // red
rgb1[1] = (byte) 0; // green
rgb1[2] = (byte) 255; // blue
byte[] rgb2 = new byte[3];
rgb2[0] = (byte) 255; // red
rgb2[1] = (byte) 255; // green
rgb2[2] = (byte) 255; // blue
CTGradientFill ctgradientfill = ctfill.addNewGradientFill();
ctgradientfill.setDegree(90.0);
ctgradientfill.addNewStop().setPosition(0.0);
ctgradientfill.getStopArray(0).addNewColor().setRgb(rgb1);
ctgradientfill.addNewStop().setPosition(0.5);
ctgradientfill.getStopArray(1).addNewColor().setRgb(rgb2);
ctgradientfill.addNewStop().setPosition(1.0);
ctgradientfill.getStopArray(2).addNewColor().setRgb(rgb1);
System.out.println(ctfill);
Cell cell = row.createCell(0);
cell.setCellValue("");
cell.setCellStyle(cellstyle);
FileOutputStream out = new FileOutputStream("CreateExcelCellGradientFillColor.xlsx");
workbook.write(out);
out.close();
workbook.close();
}
}

Categories

Resources