简体   繁体   English

在ASP NET MVC中打开没有Office Online的新格式Microsoft Office(网络应用程序)

[英]Open new formats Microsoft Office without Office Online (web apps) in ASP NET MVC

I have problem with open new format documents Microsoft Office (docx, xlsx etc). 我在打开新格式的文档Microsoft Office(docx,xl​​sx等)时遇到问题。 I develop my project using ASP NET MVC. 我使用ASP NET MVC开发项目。

I wrote new method: 我写了新方法:

[HttpGet]
[AllowAnonymous]
public ActionResult DownloadFileNew(Guid Id)
{
    FileTable fileTable = _DocumentService.GetFile(Id);

    HttpResponseBase response = ControllerContext.HttpContext.Response;
    response.ContentType = fileTable.ContentType;
    response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", fileTable.FileName));

    MemoryStream ms = new MemoryStream(fileTable.Data);
    FileStreamResult document = new FileStreamResult(ms, fileTable.ContentType);

    document.FileStream.Seek(0, SeekOrigin.Begin);
    document.FileStream.CopyTo(response.OutputStream, (int)document.FileStream.Length);

    response.Flush();
    return new EmptyResult();
}

But don't work with new formats, only old format (doc, xls etc). 但不要使用新格式,而只能使用旧格式(doc,xls等)。

When I try open document I take error message: "Excel web app cannot open this document ..." 当我尝试打开文档时,出现错误消息:“ Excel Web应用程序无法打开此文档...”

Log file: 日志文件:

  • Metro library failure: ShipAssert location: (0) condition: Metro库故障:ShipAssert位置:(0)条件:
    StackTrace: at uls.native.dll: StackTrace:位于uls.native.dll:
    (sig=35ebf2aa-983a-4c4a-a61b-a0d5e84ac5d0|2|uls.native.pdb, (sig = 35ebf2aa-983a-4c4a-a61b-a0d5e84ac5d0 | 2 | uls.native.pdb,
    offset=1CD84) at xlsrv.dll: xlsrv.dll中的offset = 1CD84):
    (sig=0beeafb2-5166-41c2-91f8-14cd1cedff75|2|xlsrv.pdb, offset=E7D801) at xlsrv.dll: (offset=E7CF26) at xlsrv.dll: (offset=5C2C8D) at (sig = 0beeafb2-5166-41c2-91f8-14cd1cedff75 | 2 | xlsrv.pdb,offset = E7D801)在xlsrv.dll:(offset = E7CF26)在xlsrv.dll:(offset = 5C2C8D)在
    xlsrv.dll: (offset=E249F2) at xlsrv.dll: (offset=E0FD6A) at xlsrv.dll:(偏移量= E249F2)在xlsrv.dll:(偏移量= E0FD6A)在
    xlsrv.dll: (offset=E0DFEE) at xlsrv.dll: (offset=DE0D20) at xlsrv.dll:(offset = E0DFEE)位于xlsrv.dll:(offset = DE0D20)位于
    xlsrv.dll: (offset=DD7D14) at xlsrv.dll: (offset=DDC413) at xlsrv.dll:(offset = DD7D14)位于xlsrv.dll:(offset = DDC413)位于
    xlsrv.dll: (offset=DD931F) at xlsrv.dll: (offset=DE0C28) at xlsrv.dll:(偏移量= DD931F)在xlsrv.dll:(偏移量= DE0C28)在
    xlsrv.dll: (offset=1D9A6A) at xlsrv.dll: (offset=1D9B03) at xlsrv.dll:(偏移量= 1D9A6A)在xlsrv.dll:(偏移量= 1D9B03)在
    xlsrv.dll: (offset=569A13) Watson bucket parameters: Uninitialized xlsrv.dll:(offset = 569A13)Watson存储桶参数:未初始化
    ULS, ULSShipAssert12, 2oxu, 15.0.4569.0 Data collection is not ULS,ULSShipAssert12、2oxu,15.0.4569.0未收集数据
    enabled for tag '2oxu' in the configuration or configuration file not available. 在配置或配置文件中为标签“ 2oxu”启用的标签不可用。 Not reporting to Watson Metro library failure 不向Watson Metro图书馆故障报告
    (0x80cb4204): (0x80cb4204):

Not sure what the ContentType you are using, but it has to be 不确定您使用的是什么ContentType,但必须

For docx files 对于docx文件

 Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

For doc files 对于文档文件

Response.ContentType = "application/ms-word"

List of all mime types here 此处列出所有哑剧类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM