admin管理员组文章数量:1530517
2024年3月19日发(作者:)
package emory;
import ;
import putStream;
import tputStream;
import iter;
import ption;
import tream;
import Stream;
import ;
import ar;
import ation;
import ry;
import e;
import putStream;
import ference;
import il;
import eet;
import rkbook;
/**
* 抽象excel2007读入器,先构建.xlsx一张模板,改写模板中的,使用这种方法
* 写入.xlsx文件,不需要太大的内存
*
*/
public abstract class AbstractExcel2007Writer {
// 保存模板
FileOutputStream os = new FileOutputStream("");
(os);
();
// 生成xml文件
File tmp = TempFile("sheet", ".xml");
/**
* 写入电子表格的主要流程
* @param fileName
* @throws Exception
*/
public void process(String fileName) throws Exception{
// 建立工作簿和电子表格对象
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = Sheet("sheet1");
// 持有电子表格数据的xml文件名 例如 /xl/worksheets/
String sheetRef = kagePart().getPartName().getName();
private SpreadsheetWriter sw;
}
Writer fw = new FileWriter(tmp);
sw = new SpreadsheetWriter(fw);
generate();
();
// 使用产生的数据替换模板
File templateFile = new File("");
FileOutputStream out = new FileOutputStream(fileName);
substitute(templateFile, tmp, ing(1), out);
();
//删除文件之前调用一下垃圾回收器,否则无法删除模板文件
();
// 删除临时模板文件
if (()&&()){
}
();
/**
* 类使用者应该使用此方法进行写操作
* @throws Exception
*/
public abstract void generate() throws Exception;
public void beginSheet() throws IOException {
}
public void insertRow(int rowNum) throws IOException {
}
public void createCell(int columnIndex, String value) throws IOException {
}
public void createCell(int columnIndex, double value) throws IOException {
}
public void endRow() throws IOException {
}
public void endSheet() throws IOException {
}
/**
*
et();
();
Cell(columnIndex, value, -1);
Cell(columnIndex, value, -1);
Row(rowNum);
heet();
版权声明:本文标题:解决poi读取excel2007出现内存溢出问题代码参考 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1710802001a284221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论