layui+javapoi导出
前端发送请求:
window.location.href= config.base_server + “troutProve/ee?gida=”+aa+"&Authorization=" +
/**
* poi 批量导出excel
* @return
*/
@GetMapping("/ee")
public void Ee(String gida, HttpServletResponse response) throws IOException { //response 给前端显⽰List a = null;
String[] gid = gida.split(",");
a= troutProveService.poi(gid);
HSSFWorkbook workbook = new HSSFWorkbook();
//2.2创建⼀个标签页
HSSFSheet sheet = ateSheet("cesh");
//指定合并单元格
// CellRangeAddress cra=new CellRangeAddress(0, 2, 3, 6);
//在sheet⾥增加合并单元格
// sheet.addMergedRegion(cra);
//2.3创建标题⾏
HSSFRow headRow = ateRow(0);
sheet.setColumnWidth(0,17*256); //设置sheet标签页列宽
sheet.setColumnWidth(2,17*256);
sheet.setColumnWidth(3,13*256);
sheet.setColumnWidth(4,13*256);
sheet.setColumnWidth(6,10*256);
sheet.setColumnWidth(7,10*256);
sheet.setColumnWidth(8,10*256);
sheet.setColumnWidth(9,10*256);
sheet.setColumnWidth(5,17*256);
layui下载sheet.setColumnWidth(10,17*256);
sheet.setColumnWidth(11,50*256);
/
**
给表格填写数据
*/
for (int i = 0; i < a.size(); i++) {
int di=1;
HSSFRow dataRow = LastRowNum()+di); //创建⼀⾏,每条数据+1⾏
HSSFRow dataRow = LastRowNum()+di); //创建⼀⾏,每条数据+1⾏ dataRow.setHeight((short) (17*20));//设置⾏⾼
if (i<a.size()-1){
if (a.get(i+1).getCpName().(i).getCpName())&&(i<a.size()-1)){
}
}
if (a.get(i).getCpName() == null) {
}else{
}
if (a.get(i).getBatchNumber() == null) {
}else{
}
if (a.get(i).getCertificateTime() == null) {
}else{
}
if (a.get(i).getSendType() == null) {
}else{
}
if (a.get(i).getMailType() == null) {
}else {
}
if (a.get(i).getMailTime() == null) {
}else{
}
if (a.get(i).getRawMaterial() == 0) {
}else{
}
if (a.get(i).getExitAccomplish() == 0) {
}else{
}
if (a.get(i).getCost() == null) {
}else {
}
}
if (a.get(i).getMailPrice() == 0) {
}else{
}
if (a.get(i).getMailNum() == 0) {
}else{
}
if (a.get(i).getRemark() == null) {
}else{
}
}
String filename = “”;
try {
Date d = new Date();
long timeStemp = d.getTime(); //转换时间戳
//3.输出流进⾏⽂件下载
filename = "分区信息表.xls";
File file = new File(filename);
FileOutputStream file1 = new FileOutputStream(file);
workbook.write(file1);
file1.close();
//直接获取输出,直接输出excel(优先使⽤)
OutputStream OutputStream();
response.setHeader("Content-Disposition", "attachment;filename="
.
concat(String.de(filename, "UTF-8")))); response.setContentType("application/msexcel");
workbook.write(output);
output.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
File fileDelete = new File(filename);
if (ists()&&fileDelete.isFile()){
fileDelete.delete();
}
/* Date d = new Date();
long timeStemp = d.getTime(); //转换时间戳
String outPath =timeStemp+filename;
OutputStream os = null;
InputStream fin = null;
try {
os =new FileOutputStream(outPath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}*/
/
*    //设置头信息
OutputStream os = null;
try {
//根据路径创建输出流
//如果是在controller⾥可以使⽤OutputStream()⽅法获取输出流        os = new FileOutputStream(outPath);
workbook.write(os);
} catch (Exception e) {
System.out.println("导出出错");
e.printStackTrace();
}finally {
try {
if (os != null) {
os.close();
}
workbook.close();
} catch (Exception e) {
System.out.println("workbook 流关闭失败");
}
}
*/
// String fileName = “鲑鱼.xls”;
/* try {
File file = new File(outPath);
FileOutputStream file1 = new FileOutputStream(file); workbook.write(file1);
file1.close();
OutputStream out = OutputStream();
response.setHeader("Content-Disposition", "attachment;filename="
.concat(String.de(outPath, "UTF-8"))));    response.setContentType("application/msexcel;charset=UTF-8");
workbook.write(out);
out.flush();
out.close();
//删除⽂件
File fileDelete = new File(outPath);
if (ists()&&fileDelete.isFile()){
fileDelete.delete();
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "导出失败!");
e.printStackTrace();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "导出失败!");
e.printStackTrace();
}
*/
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。