我希望我的Web應用程序用戶將一些數據作爲Excel文件下載。如何從HSSFWorkbook對象獲得輸入流
我有下一個函數在響應對象中發送輸入流。
public static void sendFile(InputStream is, HttpServletResponse response) throws IOException {
BufferedInputStream in = null;
try {
int count;
byte[] buffer = new byte[BUFFER_SIZE];
in = new BufferedInputStream(is);
ServletOutputStream out = response.getOutputStream();
while(-1 != (count = in.read(buffer)))
out.write(buffer, 0, count);
out.flush();
} catch (IOException ioe) {
System.err.println("IOException in Download::sendFile");
ioe.printStackTrace();
} finally {
if (in != null) {
try { in.close();
} catch (IOException ioe) { ioe.printStackTrace(); }
}
}
}
我想將我的HSSFWorkbook對象轉換爲輸入流並將其傳遞給前一個方法。
public InputStream generateApplicationsExcel() {
HSSFWorkbook wb = new HSSFWorkbook();
// Populate the excel object
return null; // TODO. return the wb as InputStream
}
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html
+1。但我如何獲得HSSFWorkbook的文件大小?我想添加一個標題`Content-Length' – MyTitle 2012-09-19 04:48:46