给商品导出初步增加带模板导出的逻辑
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import jxl.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import jxl.format.*;
|
||||
import jxl.write.Label;
|
||||
@@ -13,10 +17,25 @@ import jxl.write.WritableFont;
|
||||
import jxl.write.WritableSheet;
|
||||
import jxl.write.WritableWorkbook;
|
||||
|
||||
@Slf4j
|
||||
public class ExcelUtils {
|
||||
|
||||
public static WritableFont arial14font = null;
|
||||
|
||||
public static InputStream getPathByFileName(String template, String tmpFileName) {
|
||||
File tmpFile = new File(template, tmpFileName);
|
||||
InputStream path = null;
|
||||
//判断文件或文件夹是否存在
|
||||
if (tmpFile.exists()) {
|
||||
try {
|
||||
path = new FileInputStream(tmpFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static File exportObjects(String fileName, String[] names,
|
||||
String title, List<String[]> objects) throws Exception {
|
||||
File excelFile = new File("fileName.xls");
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.OutputStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
@Slf4j
|
||||
public class ExportExecUtil {
|
||||
|
||||
public static void showExec(File excelFile,String fileName,HttpServletResponse response) throws Exception{
|
||||
@@ -25,4 +28,31 @@ public class ExportExecUtil {
|
||||
fis.close();
|
||||
}
|
||||
|
||||
public static void downloadFile(InputStream inputStream, String fileName , HttpServletResponse response) {
|
||||
try {
|
||||
response.setContentType("multipart/form-data");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
byte[] buff = new byte[1024];
|
||||
int length = 0;
|
||||
while ((length = inputStream.read(buff)) != -1) {
|
||||
outputStream.write(buff, 0, length);
|
||||
}
|
||||
if (outputStream != null) {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("关闭资源出错" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user