Search in sources :

Example 1 with DataFormatData

use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.

the class StyleDataTest method t03AbstractVerticalCellStyleStrategy.

@Test
public void t03AbstractVerticalCellStyleStrategy() {
    AbstractVerticalCellStyleStrategy verticalCellStyleStrategy = new AbstractVerticalCellStyleStrategy() {

        @Override
        protected WriteCellStyle headCellStyle(Head head) {
            WriteCellStyle writeCellStyle = new WriteCellStyle();
            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
            DataFormatData dataFormatData = new DataFormatData();
            dataFormatData.setIndex((short) 0);
            writeCellStyle.setDataFormatData(dataFormatData);
            writeCellStyle.setHidden(false);
            writeCellStyle.setLocked(true);
            writeCellStyle.setQuotePrefix(true);
            writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            writeCellStyle.setWrapped(true);
            writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            writeCellStyle.setRotation((short) 0);
            writeCellStyle.setIndent((short) 10);
            writeCellStyle.setBorderLeft(BorderStyle.THIN);
            writeCellStyle.setBorderRight(BorderStyle.THIN);
            writeCellStyle.setBorderTop(BorderStyle.THIN);
            writeCellStyle.setBorderBottom(BorderStyle.THIN);
            writeCellStyle.setLeftBorderColor(IndexedColors.RED.getIndex());
            writeCellStyle.setRightBorderColor(IndexedColors.RED.getIndex());
            writeCellStyle.setTopBorderColor(IndexedColors.RED.getIndex());
            writeCellStyle.setBottomBorderColor(IndexedColors.RED.getIndex());
            writeCellStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
            writeCellStyle.setShrinkToFit(Boolean.TRUE);
            if (head.getColumnIndex() == 0) {
                writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
                WriteFont writeFont = new WriteFont();
                writeFont.setItalic(true);
                writeFont.setStrikeout(true);
                writeFont.setTypeOffset(Font.SS_NONE);
                writeFont.setUnderline(Font.U_DOUBLE);
                writeFont.setBold(true);
                writeFont.setCharset((int) Font.DEFAULT_CHARSET);
            } else {
                writeCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
            }
            return writeCellStyle;
        }

        @Override
        protected WriteCellStyle contentCellStyle(Head head) {
            WriteCellStyle writeCellStyle = new WriteCellStyle();
            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
            if (head.getColumnIndex() == 0) {
                writeCellStyle.setFillForegroundColor(IndexedColors.DARK_GREEN.getIndex());
            } else {
                writeCellStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
            }
            return writeCellStyle;
        }
    };
    EasyExcel.write(fileVerticalCellStyleStrategy07, StyleData.class).registerWriteHandler(verticalCellStyleStrategy).sheet().doWrite(data());
}
Also used : AbstractVerticalCellStyleStrategy(com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy) Head(com.alibaba.excel.metadata.Head) WriteCellStyle(com.alibaba.excel.write.metadata.style.WriteCellStyle) DataFormatData(com.alibaba.excel.metadata.data.DataFormatData) WriteFont(com.alibaba.excel.write.metadata.style.WriteFont) Test(org.junit.Test)

Example 2 with DataFormatData

use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.

the class WriteWorkbookHolder method createDataFormat.

/**
 * create a data format.
 *
 * @param dataFormatData
 * @param useCache
 * @return
 */
public Short createDataFormat(DataFormatData dataFormatData, boolean useCache) {
    if (dataFormatData == null) {
        return null;
    }
    if (!useCache) {
        return StyleUtil.buildDataFormat(workbook, dataFormatData);
    }
    DataFormatData tempDataFormatData = new DataFormatData();
    DataFormatData.merge(dataFormatData, tempDataFormatData);
    Short dataFormat = dataFormatMap.get(tempDataFormatData);
    if (dataFormat != null) {
        return dataFormat;
    }
    dataFormat = StyleUtil.buildDataFormat(workbook, tempDataFormatData);
    dataFormatMap.put(tempDataFormatData, dataFormat);
    return dataFormat;
}
Also used : DataFormatData(com.alibaba.excel.metadata.data.DataFormatData)

Example 3 with DataFormatData

use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.

the class StyleProperty method build.

public static StyleProperty build(HeadStyle headStyle) {
    if (headStyle == null) {
        return null;
    }
    StyleProperty styleProperty = new StyleProperty();
    if (headStyle.dataFormat() >= 0) {
        DataFormatData dataFormatData = new DataFormatData();
        dataFormatData.setIndex(headStyle.dataFormat());
        styleProperty.setDataFormatData(dataFormatData);
    }
    styleProperty.setHidden(headStyle.hidden().getBooleanValue());
    styleProperty.setLocked(headStyle.locked().getBooleanValue());
    styleProperty.setQuotePrefix(headStyle.quotePrefix().getBooleanValue());
    styleProperty.setHorizontalAlignment(headStyle.horizontalAlignment().getPoiHorizontalAlignment());
    styleProperty.setWrapped(headStyle.wrapped().getBooleanValue());
    styleProperty.setVerticalAlignment(headStyle.verticalAlignment().getPoiVerticalAlignmentEnum());
    if (headStyle.rotation() >= 0) {
        styleProperty.setRotation(headStyle.rotation());
    }
    if (headStyle.indent() >= 0) {
        styleProperty.setIndent(headStyle.indent());
    }
    styleProperty.setBorderLeft(headStyle.borderLeft().getPoiBorderStyle());
    styleProperty.setBorderRight(headStyle.borderRight().getPoiBorderStyle());
    styleProperty.setBorderTop(headStyle.borderTop().getPoiBorderStyle());
    styleProperty.setBorderBottom(headStyle.borderBottom().getPoiBorderStyle());
    if (headStyle.leftBorderColor() >= 0) {
        styleProperty.setLeftBorderColor(headStyle.leftBorderColor());
    }
    if (headStyle.rightBorderColor() >= 0) {
        styleProperty.setRightBorderColor(headStyle.rightBorderColor());
    }
    if (headStyle.topBorderColor() >= 0) {
        styleProperty.setTopBorderColor(headStyle.topBorderColor());
    }
    if (headStyle.bottomBorderColor() >= 0) {
        styleProperty.setBottomBorderColor(headStyle.bottomBorderColor());
    }
    styleProperty.setFillPatternType(headStyle.fillPatternType().getPoiFillPatternType());
    if (headStyle.fillBackgroundColor() >= 0) {
        styleProperty.setFillBackgroundColor(headStyle.fillBackgroundColor());
    }
    if (headStyle.fillForegroundColor() >= 0) {
        styleProperty.setFillForegroundColor(headStyle.fillForegroundColor());
    }
    styleProperty.setShrinkToFit(headStyle.shrinkToFit().getBooleanValue());
    return styleProperty;
}
Also used : DataFormatData(com.alibaba.excel.metadata.data.DataFormatData)

Example 4 with DataFormatData

use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.

the class XlsxReadWorkbookHolder method dataFormatData.

public DataFormatData dataFormatData(int dateFormatIndexInteger) {
    return dataFormatDataCache.computeIfAbsent(dateFormatIndexInteger, key -> {
        DataFormatData dataFormatData = new DataFormatData();
        if (stylesTable == null) {
            return null;
        }
        XSSFCellStyle xssfCellStyle = stylesTable.getStyleAt(dateFormatIndexInteger);
        dataFormatData.setIndex(xssfCellStyle.getDataFormat());
        dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormatData.getIndex(), xssfCellStyle.getDataFormatString(), globalConfiguration().getLocale()));
        return dataFormatData;
    });
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) DataFormatData(com.alibaba.excel.metadata.data.DataFormatData)

Example 5 with DataFormatData

use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.

the class NumberRecordHandler method processRecord.

@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    NumberRecord nr = (NumberRecord) record;
    ReadCellData<?> cellData = ReadCellData.newInstance(BigDecimal.valueOf(nr.getValue()), nr.getRow(), (int) nr.getColumn());
    short dataFormat = (short) xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex(nr);
    DataFormatData dataFormatData = new DataFormatData();
    dataFormatData.setIndex(dataFormat);
    dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormat, xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatString(nr), xlsReadContext.readSheetHolder().getGlobalConfiguration().getLocale()));
    cellData.setDataFormatData(dataFormatData);
    xlsReadContext.xlsReadSheetHolder().getCellMap().put((int) nr.getColumn(), cellData);
    xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA);
}
Also used : DataFormatData(com.alibaba.excel.metadata.data.DataFormatData) NumberRecord(org.apache.poi.hssf.record.NumberRecord)

Aggregations

DataFormatData (com.alibaba.excel.metadata.data.DataFormatData)7 Cell (com.alibaba.excel.metadata.Cell)1 Head (com.alibaba.excel.metadata.Head)1 FormulaData (com.alibaba.excel.metadata.data.FormulaData)1 ReadCellData (com.alibaba.excel.metadata.data.ReadCellData)1 WriteCellStyle (com.alibaba.excel.write.metadata.style.WriteCellStyle)1 WriteFont (com.alibaba.excel.write.metadata.style.WriteFont)1 AbstractVerticalCellStyleStrategy (com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 NumberRecord (org.apache.poi.hssf.record.NumberRecord)1 CellType (org.apache.poi.ss.usermodel.CellType)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 Test (org.junit.Test)1