Commit 81f94227 authored by yanzg's avatar yanzg

输出内容

parent 7a386d76
......@@ -3,9 +3,11 @@ package com.yanzuoguang.cloud.excel;
import com.yanzuoguang.cloud.helper.HttpFileHelper;
import com.yanzuoguang.excel.*;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.springframework.http.MediaType;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
......@@ -66,6 +68,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
// 临时文件
String fileNameTemp = this.getFileNameTemp();
File fileTemp = new File(fileNameTemp);
// 临时文件行数
String fileNameRow = this.getFileNameRow();
File fileRow = new File(fileNameRow);
boolean isDown = file.exists();
if (isDown) {
......@@ -77,7 +82,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
ExportTempRes res = new ExportTempRes();
res.setFileName(fileName);
res.setSize(fileTemp.length());
res.setRow(StringHelper.toLong(FileHelper.readFile(fileRow, "utf-8")));
// 输出结果
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.getWriter().print(JsonHelper.serialize(res));
}
return isDown;
......
......@@ -10,6 +10,7 @@ import com.yanzuoguang.util.table.TableHeadItem;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
......@@ -42,7 +43,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
/**
* 工作薄
*/
private Workbook workbook;
private SXSSFWorkbook workbook;
/**
* 工作Sheet
......@@ -170,7 +171,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
columnBytes = new HashMap<>();
// 创建工作簿对象
workbook = new XSSFWorkbook();
workbook = new SXSSFWorkbook(100);
sheet = workbook.createSheet();
style = initColumnCenterstyle(workbook);
......@@ -308,6 +309,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
rowIndex++;
if (this.rowIndex % 100 == 0) {
FileHelper.writeFile(new File(this.getFileNameRow()), StringHelper.toString(this.rowIndex), "utf-8");
}
}
/**
......@@ -409,6 +414,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
if (this.workbook != null) {
workbook = null;
}
File fileRow = new File(this.getFileNameRow());
if (fileRow.exists()) {
fileRow.delete();
}
File file = new File(this.getFileName());
if (file.exists()) {
if (!file.delete()) {
......@@ -438,6 +447,15 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
return getFileName() + ".tmp";
}
/**
* 获取保存文件名(全路径)
*
* @return 文件名
*/
public String getFileNameRow() {
return getFileName() + ".row";
}
/**
* 创建单元格
*
......
......@@ -22,6 +22,12 @@ public class ExportTempRes extends BaseVo {
@ApiModelProperty(notes = "已生成文件大小")
private long size;
/**
* 已生成文件行数
*/
@ApiModelProperty(notes = "已生成文件行数")
private long row;
public String getFileName() {
return fileName;
}
......@@ -37,4 +43,12 @@ public class ExportTempRes extends BaseVo {
public void setSize(long size) {
this.size = size;
}
public long getRow() {
return row;
}
public void setRow(long row) {
this.row = row;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment