use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method setBold.
public void setBold(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.getBold()) {
newFont = getInternalFont(true, fontCell.getColor(), fontCell.getFontHeight(), fontCell.getFontName(), fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setBold(true);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
break;
case 1:
if (!fontCell.getBold()) {
newFont = getInternalFont(true, fontCell.getColor(), fontCell.getFontHeight(), fontCell.getFontName(), fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setBold(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 bold value");
}
}
use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method setFont.
public void setFont(String 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;
if (!fontCell.getFontName().equals(value)) {
newFont = getInternalFont(fontCell.getBold(), fontCell.getColor(), fontCell.getFontHeight(), value, fontCell.getItalic(), fontCell.getStrikeout(), fontCell.getTypeOffset(), fontCell.getUnderline());
copyPropertiesFont(newFont, fontCell);
newFont.setFontName(value);
newStyle = stylesCache.getCellStyle(newFont);
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setFont(newFont);
pCells[i].setCellStyle(newStyle);
}
}
} catch (Exception e) {
throw new ExcelException(7, "Invalid cell value");
}
}
use of com.genexus.msoffice.excel.exception.ExcelException in project JavaClasses by genexuslabs.
the class ExcelCells method setDate.
public boolean setDate(Date value) throws ExcelException {
CheckReadonlyDocument();
try {
if (!CommonUtil.nullDate().equals(value)) {
// this.doc.getDateFormat().toLowerCase();
String dformat = "";
// creates a new calendar instance
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(value);
if (calendar.get(Calendar.MINUTE) == 0 && calendar.get(Calendar.HOUR) == 0 && calendar.get(Calendar.SECOND) == 0 && dformat.indexOf(' ') > 0) {
dformat = dformat.substring(0, dformat.indexOf(' '));
}
DataFormat df = pWorkbook.createDataFormat();
XSSFCellStyle newStyle = stylesCache.getCellStyle(df.getFormat(dformat));
for (int i = 1; i <= cellCount; i++) {
XSSFCellStyle cellStyle = pCells[i].getCellStyle();
copyPropertiesStyle(newStyle, cellStyle);
newStyle.setDataFormat(df.getFormat(dformat));
pCells[i].setCellValue(value);
pCells[i].setCellStyle(newStyle);
fitColumnWidth(i, dformat.length() + 4);
}
return true;
}
} catch (Exception e) {
throw new ExcelException(7, "Invalid cell value");
}
return false;
}
Aggregations