0
私はExcelワークブックは、ファイル作成せずに、次のように直接応答オブジェクトへのApache POIを使用して作成書いているでzip形式のXLSXとして:ダウンロードエクセル代わりにScalatra
val outputStream: ByteArrayOutputStream = new ByteArrayOutputStream()
workbook.write(outputStream)
ExcelOk(response.getOutputStream.write(outputStream.toByteArray))
をしかしサイズいったん応答が8kBを超えると、Chromeにzip
というファイルが、FireFoxにはoctet-stream
というファイルがダウンロードされ始めます。
マイExcelOk
オブジェクトは次のようになります。
object ExcelOk {
def apply(body: Any = Unit, headers: Map[String, String] = ExcelContentType, reason: String = "") = {
halt(ActionResult(responseStatus(200, reason), body, headers))
}
}
と私のExcelContentType
(すなわち、レスポンスヘッダー)は以下の通りです:
val ExcelContentType = Map(
"Access-Control-Allow-Credentials" -> "true",
"Access-Control-Allow-Methods" -> "GET, PUT, POST, DELETE, OPTIONS",
"Access-Control-Allow-Origin" -> "*",
"Access-Control-Max-Age" -> "1728000",
"Content-type" -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Content-disposition" -> "attachment; filename=excel_report.xlsx"
)
私もヘッダリストに"Transfer-Encoding" -> "chunked"
を追加しようとしたが、それ動作しません。
私も私のweb.xml
ファイルにこのスニペットを追加したが、それはどちらか助けていない:
<mime-mapping>
<extension>xlsx</extension>
<mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
</mime-mapping>
このに関するすべてのヘルプは有用であろう。この動作は、応答サイズが一定のしきい値を超えた後にのみ発生することに注意してください。