Ich schreibe die Excel-Arbeitsmappe mit Apache POI direkt mit dem Response-Objekt wie folgt erstellt, ohne eine Datei zu erstellen:Download Excel als xlsx statt Zip-Format in Scalatra
val outputStream: ByteArrayOutputStream = new ByteArrayOutputStream()
workbook.write(outputStream)
ExcelOk(response.getOutputStream.write(outputStream.toByteArray))
Aber einmal die Größe der Antwort übersteigt 8kB, es beginnt heruntergeladen als zip
Datei in Chrome und als octet-stream
in FireFox.
Mein ExcelOk
Objekt sieht wie folgt aus:
object ExcelOk {
def apply(body: Any = Unit, headers: Map[String, String] = ExcelContentType, reason: String = "") = {
halt(ActionResult(responseStatus(200, reason), body, headers))
}
}
und mein ExcelContentType
(dh Response-Header) ist wie folgt:
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"
)
Ich habe sogar versucht "Transfer-Encoding" -> "chunked"
in der Header-Liste hinzufügen, aber es funktioniert nicht.
Ich habe diesen Schnipsel in meiner web.xml
als auch Datei, aber es hat auch nicht helfen:
<mime-mapping>
<extension>xlsx</extension>
<mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
</mime-mapping>
Jede Hilfe dies nützlich wäre in Bezug auf. Beachten Sie, dass dieses Verhalten nur beobachtet wird, nachdem die Antwortgröße einen bestimmten Schwellenwert überschritten hat.