如何使用ASP.NET编辑Word文件? [英] How can i edit Word files using ASP.NET ?

查看:109
本文介绍了如何使用ASP.NET编辑Word文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的团队

我已经在我的服务器上上传了一些word文档(使用IIS),现在我想编辑它们,我的客户机已经安装了Microsoft Word。

I have upload some word documents on my server (using IIS) now I want to edit them, my client machine already have Microsoft word installed on them.

如何使用asp.net编辑word文件

How can I edit word files using asp.net

谢谢

Prasad

推荐答案

您好,

Microsoft目前不推荐也不支持任何Microsoft Office应用程序的自动化无人值守的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务),因为Office在此环境中运行时可能会出现不稳定的
行为和/或死锁。

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

如需了解更多信息,请访问  服务器端Office自动化的注意事项

For more information, please visit Considerations for server-side Automation of Office

所以我建议你使用Open XML SDK来操作Office文档。

So i suggest you use Open XML SDK to manipulate Office documents.

你可以访问&n bsp; 文字处理(Open XML SDK) 以查看多个示例。 

You could visit Word processing (Open XML SDK) to see several samples. 

下面是打开word文档并添加一些文本的示例代码。

Here is the sample code to open word document and add some text.

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;


string strDoc = @"C:\Users\Public\Documents\Letter.docx";
string strTxt = "Append text in body - OpenAndAddTextToWordDocument";
OpenAndAddTextToWordDocument(strDoc, strTxt);


public static void OpenAndAddTextToWordDocument(string filepath, string txt)
{   
    // Open a WordprocessingDocument for editing using the filepath.
    WordprocessingDocument wordprocessingDocument = 
        WordprocessingDocument.Open(filepath, true);

    // Assign a reference to the existing document body.
    Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
    
    // Add new text.
    Paragraph para = body.AppendChild(new Paragraph());
    Run run = para.AppendChild(new Run());
    run.AppendChild(new Text(txt));
    
    // Close the handle explicitly.
    wordprocessingDocument.Close();
}

问候,

Celeste


这篇关于如何使用ASP.NET编辑Word文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆