如何使用C#visual studio 2010中的word文档生成报告 [英] How do i.generate a report with word documents in C# visual studio 2010

查看:176
本文介绍了如何使用C#visual studio 2010中的word文档生成报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是Visual Studio编程C#的新手,喜欢这样做:



我使用的工具:

1-带有数字命理计算结果的文本框,

是一个数字例如7



2 - 具有固定布局的word文档必须存储在这个程序中,但我不知道如何。我不喜欢使用外部数据库。在那个地方是9个字的文件,编号1到9.



3 - 生成报告的按钮。

单击时,方法必须取7号文档并将其放入新的word文档中(具有不同计算/文档的最终报告与一个报告相同,并且与单词的布局相同使用的ducument。



任何sugestions?



灵感的问候,Wilco



我尝试了什么:



我看一看报告向导和快速报告,但我不认为这对我来说是正确的解决方案。

Hello, I am a newby in programming C# in Visual Studio and like to do the following:

Tools I use:
1- Textbox with outcome of numerology calculation,
is a number for exemple 7

2 - A word document with a fixed lay-out that must be stored in this program, but I don't know how. I don't like to use an external database. In that place are 9 word documents, number 1 to 9.

3 - a Button to generate the report.
When clicked the method had to take the number 7 document and put that in a new word document (The final report with different calculations/documents fit together to one report with the same lay-out as the word ducument that is used.

Any sugestions?

Inspired greetings, Wilco

What I have tried:

I have take a look to report wizard and fast report, but I don't think this is the right sollution for me.

推荐答案

嗯......你可以使用'MS Word文档作为模板' - 文章如这个 C#:使用DocX以编程方式创建和处理Word文档 [ ^ ]很容易找到 - 谷歌'C#word文档模板' - 你也可以用PDF文档和iTextSharp做同样的事情......你给我们足够的信息,说明'文档'是多么复杂,所以我不能建议哪个更好。



我使用PDF和iTextSharp来生成一些非常复杂的报告,每个2页的2个'模板',我只是从磁盘读取它们 - 另一种方法是将模板嵌入为资源,在这种情况下,您将使用反射来读取它们。简而言之,您为System.Reflection添加使用,将模板文件添加到项目中并设置他们对嵌入资源和跟随代码的构建操作



well ... you can use 'a MS Word Document as a template' - articles like this C#: Create and Manipulate Word Documents Programmatically Using DocX[^] are pretty easy to find - google 'C# word document template' - you can also do the same with PDF documents and iTextSharp for instance ... you havnt given us enough info on how complex the 'document' is, so I cant suggest which is better.

I use PDF and iTextSharp to produce some very complex reports, there's 2 'templates' of 2 pages each, and I just read them from disk - the other approach would be to embed the 'templates' as a resource, in which case you would use reflection to read them .. in a nutshell, you add a 'using' for System.Reflection, add the template file(s) to the project and set the build action for them to 'Embedded Resource' and 'follow' the code

var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyCompany.MyProduct.MyFile.txt";

using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
    string result = reader.ReadToEnd();
}





resourceName是程序集中嵌入的资源之一的名称。例如,如果您嵌入一个名为MyFile.txt的文本文件,该文件位于具有默认命名空间MyCompany.MyProduct的项目的根目录中,则resourceName为MyCompany.MyProduct.MyFile.txt



您还可以使用Assembly.GetManifestResourceNames()方法获取嵌入资源列表 - 我通常这样做,所以我可以在调试时转储资源的名称



(这个资源来自SO btw,我的代码不是'手')



resourceName is the name of one of the resources embedded in assembly. For example, if you embed a text file named "MyFile.txt" that is placed in the root of a project with default namespace "MyCompany.MyProduct", then resourceName is "MyCompany.MyProduct.MyFile.txt"

You can also use Assembly.GetManifestResourceNames() Method to get a list of embedded resources - I usually do this so I can dump the names of the resources while Im debugging

(this resource stuff is from SO btw, my code isnt 'to hand')


这篇关于如何使用C#visual studio 2010中的word文档生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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