如何在asp.net windows应用程序中创建word文档 [英] how can create word documents in asp.net windows application

查看:55
本文介绍了如何在asp.net windows应用程序中创建word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,每个人都好。我是在asp.net中创建word文档的新手。我的问题是我在我的数据库中有内容,当我在Windows应用程序中使用clink按钮时,数据内容将需要显示在一个word文档中。我怎么能这样做。任何身体帮助我解决我的问题。





提前感谢!。

解决方案

你需要使用word自动化来完成你的任务

添加com对象的参考Microsoft.office.interop.word

这里是一篇很好的文章,你可以使用以下链接,

办公自动化c#.net [ ^ ]

办公自动化:通过MSDN [ ^ ]


Prasad的回答可以给你一个想法如何在服务器端使用Word文档,那又怎样?如何在网页上显示Word文档。问题看起来像这样:Word文档格式是专有的,而不是标准格式。并非每个客户端系统都提供呈现Word文档的方法。默认情况下,没有系统可以做到这一点,不仅仅是在某些Web浏览器中 - 无论如何。这是因为Microsoft Word(以及一般的Microsoft Office)是商业软件。这与围绕开放标准构建的WWW原则正好相反。



因此,快速答案是:Word文档不属于Web的单词。



但这并不是很令人满意。 Word文档成为现实生活的一部分,因此有许多网站允许以大多数版本的格式上传Word文档,甚至可以在Web浏览器的屏幕上以与某些简化处理器非常类似的方式对其进行编辑Word文档(典型示例:像Dice或Monster这样的求职网站)。怎么做?



答案是:无论你做什么,在网页上你需要提供一个HTML文档(甚至HTML编辑器)的方式类似于Word文档。您将需要开发Word文档的映射(更现实地,一些合理的,也许是非常适度的Word功能的子集),并将所有内容重写为HTML,其样式具有Word文档和输入时的映射。



我想说,将内部格式保留为HTML是明智之举。或者,如果可以是通过XSLT样式表进行XSLT转换而映射到HTML + CSS或XML的特殊XML格式( http:// en。 wikipedia.org/wiki/XSLT [ ^ ]) 。



对于转换,您需要在内部读取/解析Word文档,因此这是Prasad建议使用Office互操作的地方。



祝你好运,

-SA


您的问题令人困惑。

首先你说

我是新的用于在asp.net中创建word文档

然后你说

我在我的数据库中有内容当我在Windows应用程序中的clink按钮

ASP.NET应用程序或Windows应用程序也是如此?



您可以使用Microsoft C#Word Autom如果安装了Microsoft Office,则为Windows应用程序提供

对于ASP.NET应用程序Microsoft C#Word Interop - http://support.microsoft.com/kb/257757。

相反,你可以尝试使用此代码中的 ASP.NET Word 组件:

  //  在免费模式下使用该组件。 
ComponentInfo.SetLicense( FREE-LIMITED-KEY);

// 创建一个新的空文档。
DocumentModel文档= new DocumentModel();

// 添加文档内容。
document.Sections。添加(
new 部分(文档,
new 段落(文档, Hello World!)));

// Microsoft Packaging API无法直接写入Response.OutputStream。
// 因此我们使用临时MemoryStream。
使用(MemoryStream documentStream = new MemoryStream())
{
document.Save(documentStream,SaveOptions.DocxDefault) ;

// 将文件流式传输到浏览器。
Response.Clear ();
Response.ContentType = application / vnd.openxmlformats;
Response.AddHeader( Content-Disposition attachment; filename = Document.docx);

documentStream.WriteTo(Response.OutputStream);

Response.End();
}


hello every body. i am new for creating word documents in asp.net .what my problem is i have content in my database when i clink button in windows application the data content will need to display in one word document. how can i do it.can any body help me to solve my problem.


thanks in advance!.

解决方案

You need to use word automation to accomplish your task
Add reference of com object "Microsoft.office.interop.word"
here is good article you can use following links,
office automation with c#.net[^]
office automation: by MSDN[^]


The answer by Prasad can give you the idea on how to work with Word documents on the server side, so what? How can you show the Word document on the Web page. The problem looks like this: the Word document formats are proprietary and not standard. Not every client system provides the means of rendering Word documents. There are no systems which can do it by default, not only in some Web browser — in any way. This is because Microsoft Word (and Microsoft Office in general) is commercial software. This is directly opposite to the principles of WWW which is build around open standards.

So, the quick answer is: Word documents do not belong in the word of the Web.

This is not very satisfying though. Word documents became a part of real life, so there is a number of sites which allow to upload Word document in the formats of most versions and view or even edit it on the screen of the Web browser in a way very similar to some simplified processor of the Word documents (typical example: job search sites like Dice or Monster). How to do this?

The answer is: no matter what you do, on the Web page you need to present an HTML document (or even HTML editor) the way resembling a Word document. You will need to develop mapping of the Word document (more realistically, some reasonable and perhaps pretty modest subset of the Word features) and re-write everything into HTML with style having a Word document and this mapping on input.

I would say, you would be wise to keep internal format to HTML. Alternatively, if could be a special XML format mapped to HTML+CSS or XML with XSLT transformation through XSLT style sheet (http://en.wikipedia.org/wiki/XSLT[^]).

And for transformation you will need to read/parse a Word document internally, so this is where you can use Office interop as Prasad advised.

Good luck,
—SA


Your questions is confusing.
First you say

i am new for creating word documents in asp.net

and then you say

i have content in my database when i clink button in windows application

, so is it ASP.NET application or Windows application?

You can use Microsoft C# Word Automation for Windows application if you have Microsoft Office installed.
For ASP.NET application Microsoft C# Word Interop is not recommended by Microsoft - http://support.microsoft.com/kb/257757.
Instead you can try using this ASP.NET Word component like in this code:

// Use the component in free mode.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create a new empty document.
DocumentModel document = new DocumentModel();

// Add document content.
document.Sections.Add(
  new Section(document, 
    new Paragraph(document, "Hello World!")));

// Microsoft Packaging API cannot write directly to Response.OutputStream.
// Therefore we use temporary MemoryStream.
using (MemoryStream documentStream = new MemoryStream())
{
  document.Save(documentStream, SaveOptions.DocxDefault);

  // Stream file to browser.
  Response.Clear();
  Response.ContentType = "application/vnd.openxmlformats";
  Response.AddHeader("Content-Disposition", "attachment; filename=Document.docx");

  documentStream.WriteTo(Response.OutputStream);

  Response.End();
}


这篇关于如何在asp.net windows应用程序中创建word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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