Search in sources :

Example 6 with ExcelException

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");
    }
}
Also used : ExcelException(com.genexus.msoffice.excel.exception.ExcelException) ExcelReadonlyException(com.genexus.msoffice.excel.exception.ExcelReadonlyException) ExcelException(com.genexus.msoffice.excel.exception.ExcelException)

Example 7 with ExcelException

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");
    }
}
Also used : ExcelException(com.genexus.msoffice.excel.exception.ExcelException) ExcelReadonlyException(com.genexus.msoffice.excel.exception.ExcelReadonlyException) ExcelException(com.genexus.msoffice.excel.exception.ExcelException)

Example 8 with ExcelException

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;
}
Also used : ExcelException(com.genexus.msoffice.excel.exception.ExcelException) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ExcelReadonlyException(com.genexus.msoffice.excel.exception.ExcelReadonlyException) ExcelException(com.genexus.msoffice.excel.exception.ExcelException)

Aggregations

ExcelException (com.genexus.msoffice.excel.exception.ExcelException)8 ExcelReadonlyException (com.genexus.msoffice.excel.exception.ExcelReadonlyException)7 ExcelTemplateNotFoundException (com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException)1 GXFile (com.genexus.util.GXFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1