|
|
@ -9,6 +9,7 @@ import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
|
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
@ -343,39 +344,52 @@ public class WriteContextImpl implements WriteContext { |
|
|
|
if (writeWorkbookHolder == null) { |
|
|
|
if (writeWorkbookHolder == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
writeWorkbookHolder.getWorkbook().write(writeWorkbookHolder.getOutputStream()); |
|
|
|
writeWorkbookHolder.getWorkbook().write(writeWorkbookHolder.getOutputStream()); |
|
|
|
writeWorkbookHolder.getWorkbook().close(); |
|
|
|
writeWorkbookHolder.getWorkbook().close(); |
|
|
|
} catch (Throwable e) { |
|
|
|
} catch (Throwable t) { |
|
|
|
throw new ExcelGenerateException("Can not close IO", e); |
|
|
|
throwCanNotCloseIo(t); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Workbook workbook = writeWorkbookHolder.getWorkbook(); |
|
|
|
|
|
|
|
if (workbook instanceof SXSSFWorkbook) { |
|
|
|
|
|
|
|
((SXSSFWorkbook)workbook).dispose(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Throwable t) { |
|
|
|
|
|
|
|
throwCanNotCloseIo(t); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getOutputStream() != null) { |
|
|
|
if (writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getOutputStream() != null) { |
|
|
|
writeWorkbookHolder.getOutputStream().close(); |
|
|
|
writeWorkbookHolder.getOutputStream().close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Throwable e) { |
|
|
|
} catch (Throwable t) { |
|
|
|
throw new ExcelGenerateException("Can not close IO", e); |
|
|
|
throwCanNotCloseIo(t); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getTemplateInputStream() != null) { |
|
|
|
if (writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getTemplateInputStream() != null) { |
|
|
|
writeWorkbookHolder.getTemplateInputStream().close(); |
|
|
|
writeWorkbookHolder.getTemplateInputStream().close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Throwable e) { |
|
|
|
} catch (Throwable t) { |
|
|
|
throw new ExcelGenerateException("Can not close IO", e); |
|
|
|
throwCanNotCloseIo(t); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getFile() != null |
|
|
|
if (!writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getFile() != null |
|
|
|
&& writeWorkbookHolder.getOutputStream() != null) { |
|
|
|
&& writeWorkbookHolder.getOutputStream() != null) { |
|
|
|
writeWorkbookHolder.getOutputStream().close(); |
|
|
|
writeWorkbookHolder.getOutputStream().close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Throwable e) { |
|
|
|
} catch (Throwable t) { |
|
|
|
throw new ExcelGenerateException("Can not close IO", e); |
|
|
|
throwCanNotCloseIo(t); |
|
|
|
} |
|
|
|
} |
|
|
|
if (LOGGER.isDebugEnabled()) { |
|
|
|
if (LOGGER.isDebugEnabled()) { |
|
|
|
LOGGER.debug("Finished write."); |
|
|
|
LOGGER.debug("Finished write."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void throwCanNotCloseIo(Throwable t) { |
|
|
|
|
|
|
|
throw new ExcelGenerateException("Can not close IO", t); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Sheet getCurrentSheet() { |
|
|
|
public Sheet getCurrentSheet() { |
|
|
|
return writeSheetHolder.getSheet(); |
|
|
|
return writeSheetHolder.getSheet(); |
|
|
|