0
我使用windows.open('url')
從c#web api下載excel。它正在每個瀏覽器中下載。但對於iPad和iPhone,該文件得到下載,但我得到我使用下面的代碼返回存儲在內存流Excel數據在屏幕上ERROR_MESSAGE_MAIN ERROR_MESSAGE_REASON iPad和Iphone在.Net應用程序中
ERROR_MESSAGE_MAIN ERROR_MESSAGE_REASON
以下錯誤
HttpResponseMessage result = null;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new StreamContent(mem);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "myexcel.xlsx"
};
return result;
我有看到了PHP中的同一個問題。我試着檢查相同的內容,但他提供了錯誤的內容類型。網址: - ERROR_MESSAGE_MAIN ERROR_MESSAGE_REASON on iPad and iPhone Safari
我在其他地方檢查了相同的問題,並嘗試下面的代碼更改。我添加了桌面變量,以便在移動設備上,我可以按照建議添加另一個流。但它不起作用。
if (isDesktop)
{
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
else
{
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
}
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "myexcel.xlsx"
};
return result;
編輯 - 我使用ClosedXml創建Excel。 Github鏈接關閉XMl問題 - https://github.com/ClosedXML/ClosedXML/issues/279