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());
}
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;
}
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;
}
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;
});
}
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);
}
Aggregations