use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelSpreadsheet method saveAsImpl.
private Boolean saveAsImpl(String fileName) throws ExcelException {
ByteArrayOutputStream fs = null;
ByteArrayInputStream in = null;
GXFile file = null;
boolean savedOK = false;
autoFitColumns();
recalculateFormulas();
try {
fs = new ByteArrayOutputStream();
_workbook.write(fs);
in = new ByteArrayInputStream(fs.toByteArray());
fs.close();
file = new GXFile(fileName, Constants.EXTERNAL_PRIVATE_UPLOAD);
savedOK = file.create(in, true);
in.close();
file.close();
} catch (Exception e) {
try {
if (fs != null)
fs.close();
if (in != null)
in.close();
if (file != null)
file.close();
} catch (Exception e1) {
logger.error("saveAsImpl", e1);
}
throw new ExcelException(12, "GeneXus Office Module Error: " + e.toString());
}
return savedOK;
}
use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method setItalic.
public void setItalic(short value) throws ExcelException {
CheckReadonlyDocument();
try {
for (int i = 1; i <= cellCount; i++) {
XSSFCellStyle cellStyle = pCells[i].getCellStyle();
XSSFFont fontCell = pWorkbook.getFontAt(cellStyle.getFontIndex());
XSSFCellStyle newStyle = null;
XSSFFont newFont = null;
switch(value) {
case 0:
if (fontCell.getItalic()) {
newFont = getInternalFont(fontCell.getBold(), fontCell.getColor(), fontCell.getFontHeight(), fontCell.getFontName(), false, fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setItalic(false);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
break;
case 1:
if (!fontCell.getItalic()) {
newFont = getInternalFont(fontCell.getBold(), fontCell.getColor(), fontCell.getFontHeight(), fontCell.getFontName(), true, fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setItalic(true);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
break;
default:
throw new ExcelException(6, "Invalid font properties");
}
}
} catch (Exception e) {
throw new ExcelException(6, "Invalid font properties");
}
}
use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method getValue.
public BigDecimal getValue() throws ExcelException {
BigDecimal value = new BigDecimal(0);
try {
CellType cType = pCells[1].getCellTypeEnum();
switch(cType) {
case FORMULA:
String type = getFormulaType();
if (type == "N")
value = new BigDecimal(pCells[1].getNumericCellValue());
else if (type == "D")
value = new BigDecimal(getDate().getTime());
break;
case BOOLEAN:
Boolean b = pCells[1].getBooleanCellValue();
value = new BigDecimal((b) ? 1 : 0);
break;
default:
value = new BigDecimal(pCells[1].getNumericCellValue());
}
} catch (Exception e) {
throw new ExcelException(7, "Invalid cell value");
}
return value;
}
use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method setColor.
// Ver setColor()
/*
* public void setColor(long value) //Willy version { int val=(int)value; int
* r=val >> 16 & 0xff; int g=val >> 8 & 0xff; int b=val & 0xff; HSSFPalette
* palette = pWorkbook.getCustomPalette(); try { for (int i=1;i <= cntCells;
* i++) { XSSFCellStyle cellStyle = pCells[i].getCellStyle(); XSSFFont fontCell
* = pWorkbook.getFontAt(cellStyle.getFontIndex()); CellStyle newStyle = null;
* XSSFFont newFont = null;
*
* newStyle = pWorkbook.createCellStyle();
* PropertyUtils.copyProperties(newStyle, cellStyle); newFont =
* pWorkbook.createFont(); int colorIdx=ColorManager.getColor(pWorkbook);
* PropertyUtils.copyProperties(newFont,
* pWorkbook.getFontAt(cellStyle.getFontIndex()));
* palette.setColorAtIndex((short)colorIdx,(byte)r,(byte)g,(byte)b);
* newFont.setColor((short)colorIdx); //newFont.setColor(XSSFFont.COLOR_RED);
* newStyle.setFont(newFont); pCells[i].setCellStyle(newStyle);
*
* }
*
* } catch (Exception e) {
*
* } }
*/
// Esta version optimiza la paleta de colores existente en la planilla
// Busca colores parecidos y si los encuentra, los toma para no recargar
// la paleta de colores que tiene un maximo de 40h-10h posiciones.
public // 05/07/05 B@tero
void setColor(// 05/07/05 B@tero
long value) throws // 05/07/05 B@tero
ExcelException {
CheckReadonlyDocument();
try {
for (int i = 1; i <= cellCount; i++) {
XSSFCellStyle cellStyle = pCells[i].getCellStyle();
XSSFFont fontCell = pWorkbook.getFontAt(cellStyle.getFontIndex());
XSSFCellStyle newStyle = null;
XSSFFont newFont = null;
XSSFColor newColor = null;
XSSFColor fontColor = ((XSSFFont) fontCell).getXSSFColor();
int val = (int) value;
int red = val >> 16 & 0xff;
int green = val >> 8 & 0xff;
int blue = val & 0xff;
if (// Si es value esta entre 1 y 56 entonces supongo que es un
red != 0 || green != 0 || blue > 56) // color Index de Excel y voy por el else
{
if ((fontColor != null && (fontColor.getRGB() == null || (fontColor.getRGB()[0] == 0 && fontColor.getRGB()[1] == 0 && fontColor.getRGB()[2] == 0)))) {
if ((red + green + blue) != 0) {
newColor = new XSSFColor(new java.awt.Color(red, green, blue));
newFont = (XSSFFont) pWorkbook.createFont();
copyPropertiesFont(newFont, fontCell);
newFont.setColor(newColor);
newStyle = pWorkbook.createCellStyle();
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
} else {
if (fontColor != null) {
byte[] triplet = fontColor.getRGB();
if (triplet[0] != red || triplet[1] != green || triplet[2] != blue) {
newColor = new XSSFColor(new java.awt.Color(red, green, blue));
newFont = (XSSFFont) pWorkbook.createFont();
copyPropertiesFont(newFont, fontCell);
newFont.setColor(newColor);
newStyle = pWorkbook.createCellStyle();
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
}
}
} else {
// Es el ofset que hay que sumar para que el colorIndex quede igual
// al de la implementacion anterior de excel
value = value + 7;
if (fontColor != null) {
if (fontColor.getIndexed() != value) {
newFont = (XSSFFont) getInternalFont(fontCell.getBold(), (short) value, fontCell.getFontHeight(), fontCell.getFontName(), fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setColor((short) value);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
} else {
newFont = (XSSFFont) getInternalFont(fontCell.getBold(), (short) value, fontCell.getFontHeight(), fontCell.getFontName(), fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setColor((short) value);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
}
}
} catch (Exception e) {
throw new ExcelException(6, "Invalid font properties", e);
}
}
use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method setUnderline.
public void setUnderline(short value) throws ExcelException {
CheckReadonlyDocument();
try {
for (int i = 1; i <= cellCount; i++) {
XSSFCellStyle cellStyle = pCells[i].getCellStyle();
XSSFFont fontCell = pWorkbook.getFontAt(cellStyle.getFontIndex());
XSSFCellStyle newStyle = null;
XSSFFont newFont = null;
switch(value) {
case 0:
if (fontCell.getUnderline() != XSSFFont.U_NONE) {
newFont = getInternalFont(fontCell.getBold(), fontCell.getColor(), fontCell.getFontHeight(), fontCell.getFontName(), fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), XSSFFont.U_NONE);
copyPropertiesFont(newFont, fontCell);
newFont.setUnderline(XSSFFont.U_NONE);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
break;
case 1:
if (fontCell.getUnderline() != XSSFFont.U_SINGLE) {
newFont = getInternalFont(fontCell.getBold(), fontCell.getColor(), fontCell.getFontHeight(), fontCell.getFontName(), fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), XSSFFont.U_SINGLE);
copyPropertiesFont(newFont, fontCell);
newFont.setUnderline(XSSFFont.U_SINGLE);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
break;
default:
throw new ExcelException(6, "Invalid font property");
}
}
} catch (Exception e) {
throw new ExcelException(6, "Invalid font properties");
}
}
Aggregations