diff --git a/gxoffice/src/main/java/com/genexus/gxoffice/ExcelCells.java b/gxoffice/src/main/java/com/genexus/gxoffice/ExcelCells.java index d99716263..d3635a4d9 100644 --- a/gxoffice/src/main/java/com/genexus/gxoffice/ExcelCells.java +++ b/gxoffice/src/main/java/com/genexus/gxoffice/ExcelCells.java @@ -25,6 +25,9 @@ public class ExcelCells implements IExcelCells public native long getColor(); public native void setColor(long nNewVal); + public native long getBackColor(); + public native void setBackColor(long nNewVal); + public native double getSize(); public native void setSize(double nNewVal); diff --git a/gxoffice/src/main/java/com/genexus/gxoffice/IExcelCells.java b/gxoffice/src/main/java/com/genexus/gxoffice/IExcelCells.java index 4257db48e..5636de97b 100644 --- a/gxoffice/src/main/java/com/genexus/gxoffice/IExcelCells.java +++ b/gxoffice/src/main/java/com/genexus/gxoffice/IExcelCells.java @@ -1,34 +1,39 @@ package com.genexus.gxoffice; -import java.util.*; -public interface IExcelCells -{ -public double getNumber(); - public Date getDate(); - public String getText(); - public String getValue(); +import java.util.Date; - public void setNumber(double Value); - public void setDate(Date Value); - public void setText(String Value); +public interface IExcelCells { + public String getValue(); - public String getFont(); - public void setFont(String sNewVal); + public double getNumber(); + public void setNumber(double Value); - public long getColor(); - public void setColor(long nNewVal); + public Date getDate(); + public void setDate(Date Value); - public double getSize(); - public void setSize(double nNewVal); + public String getText(); + public void setText(String Value); - public String getType(); + public String getFont(); + public void setFont(String sNewVal); - public short getBold(); - public void setBold(short nNewVal); + public long getColor(); + public void setColor(long nNewVal); - public short getItalic(); - public void setItalic(short nNewVal); + public long getBackColor(); + public void setBackColor(long nNewVal); - public short getUnderline(); - public void setUnderline(short nNewVal); + public double getSize(); + public void setSize(double nNewVal); + + public String getType(); + + public short getBold(); + public void setBold(short nNewVal); + + public short getItalic(); + public void setItalic(short nNewVal); + + public short getUnderline(); + public void setUnderline(short nNewVal); } diff --git a/gxoffice/src/main/java/com/genexus/gxoffice/poi/hssf/ExcelCells.java b/gxoffice/src/main/java/com/genexus/gxoffice/poi/hssf/ExcelCells.java index efb917494..6b5485342 100644 --- a/gxoffice/src/main/java/com/genexus/gxoffice/poi/hssf/ExcelCells.java +++ b/gxoffice/src/main/java/com/genexus/gxoffice/poi/hssf/ExcelCells.java @@ -12,13 +12,14 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.*; import com.genexus.CommonUtil; import com.genexus.gxoffice.IExcelCells; import com.genexus.gxoffice.IGxError; import org.apache.poi.ss.util.NumberToTextConverter; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFColor; /** * @author Diego @@ -752,6 +753,45 @@ public void setColor(long value) // 05/07/05 B@tero } } + @Override + public long getBackColor() { + if (pCells.length == 0) { + return 0; + } + + Cell cell = pCells[1]; + if (cell.getCellStyle() == null) { + return 0; + } + + return cell.getCellStyle().getFillForegroundColor(); + } + + @Override + public void setBackColor(long value) { + int val = (int) value; + int red = val >> 16 & 0xff; + int green = val >> 8 & 0xff; + int blue = val & 0xff; + XSSFColor newColor = new XSSFColor(new java.awt.Color(red, green, blue), null); + + for (int i = 1; i <= cntCells; i++) { + Cell cell = pCells[i]; + CellStyle cellStyle = cell.getCellStyle(); + if (cellStyle == null) { + cellStyle = cell.getSheet().getWorkbook().createCellStyle(); + } + if (cellStyle.getFillPattern() == FillPatternType.NO_FILL) { + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + + ((HSSFCellStyle)cellStyle).setFillForegroundColor(newColor.getIndexed()); + cellStyle.setFillForegroundColor((short) value); + cell.setCellStyle(cellStyle); + } + } + + private void copyPropertiesStyle(HSSFCellStyle dest, HSSFCellStyle source) { dest.setAlignment(source.getAlignment()); dest.setBorderBottom(source.getBorderBottom()); diff --git a/gxoffice/src/main/java/com/genexus/gxoffice/poi/xssf/ExcelCells.java b/gxoffice/src/main/java/com/genexus/gxoffice/poi/xssf/ExcelCells.java index f1205e06b..ea811a4d8 100644 --- a/gxoffice/src/main/java/com/genexus/gxoffice/poi/xssf/ExcelCells.java +++ b/gxoffice/src/main/java/com/genexus/gxoffice/poi/xssf/ExcelCells.java @@ -5,18 +5,10 @@ import java.util.Date; import java.util.GregorianCalendar; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.DataFormat; -import org.apache.poi.ss.usermodel.DataFormatter; -import org.apache.poi.ss.usermodel.Font; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.formula.functions.Index; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.NumberToTextConverter; -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFColor; -import org.apache.poi.xssf.usermodel.XSSFFont; +import org.apache.poi.xssf.usermodel.*; import com.genexus.CommonUtil; import com.genexus.gxoffice.IExcelCells; @@ -637,7 +629,11 @@ public void setColor(long value) // 05/07/05 B@tero try { for (int i = 1; i <= cntCells; i++) { - CellStyle cellStyle = pCells[i].getCellStyle(); + Cell cell = pCells[i]; + CellStyle cellStyle = cell.getCellStyle(); + if (cellStyle == null) { + cellStyle = cell.getSheet().getWorkbook().createCellStyle(); + } Font fontCell = pWorkbook.getFontAt(cellStyle.getFontIndexAsInt()); CellStyle newStyle = null; XSSFFont newFont = null; @@ -731,6 +727,45 @@ public void setColor(long value) // 05/07/05 B@tero } } + @Override + public long getBackColor() { + if (pCells.length == 0) { + return 0; + } + + Cell cell = pCells[1]; + if (cell.getCellStyle() == null) { + return 0; + } + + return cell.getCellStyle().getFillForegroundColor(); + } + + @Override + public void setBackColor(long value) { + int val = (int) value; + int red = val >> 16 & 0xff; + int green = val >> 8 & 0xff; + int blue = val & 0xff; + + XSSFColor newColor = new XSSFColor(new java.awt.Color(red, green, blue),null); + + for (int i = 1; i <= cntCells; i++) { + Cell cell = pCells[i]; + CellStyle cellStyle = cell.getCellStyle(); + if (cellStyle == null) { + cellStyle = cell.getSheet().getWorkbook().createCellStyle(); + } + + if (cellStyle.getFillPattern() == FillPatternType.NO_FILL) { + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + + ((XSSFCellStyle)cellStyle).setFillForegroundColor(newColor); + cell.setCellStyle(cellStyle); + } + } + protected void copyPropertiesStyle(CellStyle dest, CellStyle source) { dest.cloneStyleFrom(source); }