use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.
the class FormulaRecordHandler method processRecord.
@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
FormulaRecord frec = (FormulaRecord) record;
Map<Integer, Cell> cellMap = xlsReadContext.xlsReadSheetHolder().getCellMap();
ReadCellData<?> tempCellData = new ReadCellData<>();
tempCellData.setRowIndex(frec.getRow());
tempCellData.setColumnIndex((int) frec.getColumn());
CellType cellType = CellType.forInt(frec.getCachedResultType());
String formulaValue = null;
try {
formulaValue = HSSFFormulaParser.toFormulaString(xlsReadContext.xlsReadWorkbookHolder().getHssfWorkbook(), frec.getParsedExpression());
} catch (Exception e) {
log.debug("Get formula value error.", e);
}
FormulaData formulaData = new FormulaData();
formulaData.setFormulaValue(formulaValue);
tempCellData.setFormulaData(formulaData);
xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA);
switch(cellType) {
case STRING:
// Formula result is a string
// This is stored in the next record
tempCellData.setType(CellDataTypeEnum.STRING);
xlsReadContext.xlsReadSheetHolder().setTempCellData(tempCellData);
break;
case NUMERIC:
tempCellData.setType(CellDataTypeEnum.NUMBER);
tempCellData.setNumberValue(BigDecimal.valueOf(frec.getValue()));
int dataFormat = xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex(frec);
DataFormatData dataFormatData = new DataFormatData();
dataFormatData.setIndex((short) dataFormat);
dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormatData.getIndex(), xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatString(frec), xlsReadContext.readSheetHolder().getGlobalConfiguration().getLocale()));
tempCellData.setDataFormatData(dataFormatData);
cellMap.put((int) frec.getColumn(), tempCellData);
break;
case ERROR:
tempCellData.setType(CellDataTypeEnum.ERROR);
tempCellData.setStringValue(ERROR);
cellMap.put((int) frec.getColumn(), tempCellData);
break;
case BOOLEAN:
tempCellData.setType(CellDataTypeEnum.BOOLEAN);
tempCellData.setBooleanValue(frec.getCachedBooleanValue());
cellMap.put((int) frec.getColumn(), tempCellData);
break;
default:
tempCellData.setType(CellDataTypeEnum.EMPTY);
cellMap.put((int) frec.getColumn(), tempCellData);
break;
}
}
use of com.alibaba.excel.metadata.data.DataFormatData in project easyexcel by alibaba.
the class StyleProperty method build.
public static StyleProperty build(ContentStyle contentStyle) {
if (contentStyle == null) {
return null;
}
StyleProperty styleProperty = new StyleProperty();
if (contentStyle.dataFormat() >= 0) {
DataFormatData dataFormatData = new DataFormatData();
dataFormatData.setIndex(contentStyle.dataFormat());
styleProperty.setDataFormatData(dataFormatData);
}
styleProperty.setHidden(contentStyle.hidden().getBooleanValue());
styleProperty.setLocked(contentStyle.locked().getBooleanValue());
styleProperty.setQuotePrefix(contentStyle.quotePrefix().getBooleanValue());
styleProperty.setHorizontalAlignment(contentStyle.horizontalAlignment().getPoiHorizontalAlignment());
styleProperty.setWrapped(contentStyle.wrapped().getBooleanValue());
styleProperty.setVerticalAlignment(contentStyle.verticalAlignment().getPoiVerticalAlignmentEnum());
if (contentStyle.rotation() >= 0) {
styleProperty.setRotation(contentStyle.rotation());
}
if (contentStyle.indent() >= 0) {
styleProperty.setIndent(contentStyle.indent());
}
styleProperty.setBorderLeft(contentStyle.borderLeft().getPoiBorderStyle());
styleProperty.setBorderRight(contentStyle.borderRight().getPoiBorderStyle());
styleProperty.setBorderTop(contentStyle.borderTop().getPoiBorderStyle());
styleProperty.setBorderBottom(contentStyle.borderBottom().getPoiBorderStyle());
if (contentStyle.leftBorderColor() >= 0) {
styleProperty.setLeftBorderColor(contentStyle.leftBorderColor());
}
if (contentStyle.rightBorderColor() >= 0) {
styleProperty.setRightBorderColor(contentStyle.rightBorderColor());
}
if (contentStyle.topBorderColor() >= 0) {
styleProperty.setTopBorderColor(contentStyle.topBorderColor());
}
if (contentStyle.bottomBorderColor() >= 0) {
styleProperty.setBottomBorderColor(contentStyle.bottomBorderColor());
}
styleProperty.setFillPatternType(contentStyle.fillPatternType().getPoiFillPatternType());
if (contentStyle.fillBackgroundColor() >= 0) {
styleProperty.setFillBackgroundColor(contentStyle.fillBackgroundColor());
}
if (contentStyle.fillForegroundColor() >= 0) {
styleProperty.setFillForegroundColor(contentStyle.fillForegroundColor());
}
styleProperty.setShrinkToFit(contentStyle.shrinkToFit().getBooleanValue());
return styleProperty;
}
Aggregations