use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.
the class WriteContextImpl method initCurrentSheetHolder.
private void initCurrentSheetHolder(WriteSheet writeSheet) {
writeSheetHolder = new WriteSheetHolder(writeSheet, writeWorkbookHolder);
writeTableHolder = null;
currentWriteHolder = writeSheetHolder;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("CurrentConfiguration is writeSheetHolder");
}
}
use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.
the class ExcelWriteAddExecutor method initSortedAllFieldMapFieldList.
private void initSortedAllFieldMapFieldList(Class<?> clazz, Map<Integer, Field> sortedAllFieldMap) {
if (!sortedAllFieldMap.isEmpty()) {
return;
}
WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder();
boolean needIgnore = !CollectionUtils.isEmpty(writeSheetHolder.getExcludeColumnFieldNames()) || !CollectionUtils.isEmpty(writeSheetHolder.getExcludeColumnIndexes()) || !CollectionUtils.isEmpty(writeSheetHolder.getIncludeColumnFieldNames()) || !CollectionUtils.isEmpty(writeSheetHolder.getIncludeColumnIndexes());
ClassUtils.declaredFields(clazz, sortedAllFieldMap, needIgnore, writeSheetHolder);
}
use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.
the class DimensionWorkbookWriteHandler method afterWorkbookDispose.
@Override
public void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) {
if (writeWorkbookHolder == null || writeWorkbookHolder.getWorkbook() == null) {
return;
}
if (!(writeWorkbookHolder.getWorkbook() instanceof SXSSFWorkbook)) {
return;
}
Map<Integer, WriteSheetHolder> writeSheetHolderMap = writeWorkbookHolder.getHasBeenInitializedSheetIndexMap();
if (MapUtils.isEmpty(writeSheetHolderMap)) {
return;
}
for (WriteSheetHolder writeSheetHolder : writeSheetHolderMap.values()) {
if (writeSheetHolder.getSheet() == null || !(writeSheetHolder.getSheet() instanceof SXSSFSheet)) {
continue;
}
SXSSFSheet sxssfSheet = ((SXSSFSheet) writeSheetHolder.getSheet());
XSSFSheet xssfSheet;
try {
xssfSheet = (XSSFSheet) XSSF_SHEET_FIELD.get(sxssfSheet);
} catch (IllegalAccessException e) {
log.debug("Can not found _sh.", e);
continue;
}
if (xssfSheet == null) {
continue;
}
CTWorksheet ctWorksheet = xssfSheet.getCTWorksheet();
if (ctWorksheet == null) {
continue;
}
int headSize = 0;
if (MapUtils.isNotEmpty(writeSheetHolder.getExcelWriteHeadProperty().getHeadMap())) {
headSize = writeSheetHolder.getExcelWriteHeadProperty().getHeadMap().size();
if (headSize > 0) {
headSize--;
}
}
Integer lastRowIndex = writeSheetHolder.getLastRowIndex();
if (lastRowIndex == null) {
lastRowIndex = 0;
}
ctWorksheet.getDimension().setRef("A1:" + CellReference.convertNumToColString(headSize) + (lastRowIndex + 1));
}
}
use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.
the class ExcelWriteAddExecutor method add.
public void add(Collection<?> data) {
if (CollectionUtils.isEmpty(data)) {
data = new ArrayList<>();
}
WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder();
int newRowIndex = writeSheetHolder.getNewRowIndexAndStartDoWrite();
if (writeSheetHolder.isNew() && !writeSheetHolder.getExcelWriteHeadProperty().hasHead()) {
newRowIndex += writeContext.currentWriteHolder().relativeHeadRowIndex();
}
// BeanMap is out of order, so use sortedAllFieldMap
Map<Integer, Field> sortedAllFieldMap = new TreeMap<>();
int relativeRowIndex = 0;
for (Object oneRowData : data) {
int lastRowIndex = relativeRowIndex + newRowIndex;
addOneRowOfDataToExcel(oneRowData, lastRowIndex, relativeRowIndex, sortedAllFieldMap);
relativeRowIndex++;
}
}
Aggregations