1. 程式人生 > >Excel下載模板配合的工具類

Excel下載模板配合的工具類

public class ExportUtil {


/**
* 匯出檔案

* @param response
* @param file
*            匯出檔案
* @param name
* @param contentType
* @throws IOException
*/
public static void download(HttpServletResponse response, File file,
String name, String contentType) throws IOException {
String fileName = StringUtils.isBlank(name) ? file.getName() : name;
download(response, new FileInputStream(file), fileName, contentType);
}


/**
* 下載資料/檔案

* @param response
*            HTTP輸出
* @param inputStream
*            檔案流
* @param fileName
*            檔名
* @param contentType
*            ContentType in HTTP Header
* @throws IOException
*             IO異常
*/
public static void download(HttpServletResponse response,
InputStream inputStream, String fileName, String contentType)
throws IOException {


response.setContentType(StringUtils.isEmpty(contentType) ? "application/octet-stream"
: contentType);