使用文档模板openXML dll创建word文档 [英] Create word document using document template openXML dll

查看:114
本文介绍了使用文档模板openXML dll创建word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我必须使用openxml dll在C#中使用一个模板文件创建MS word文档。



我不知道应该如何开始。



要求是,在模板中会有一个页面包含的信息很少下面,我需要第n次重复这段内容。



---------



员工姓名:#姓名# 

地址:#地址#

员工ID:#EmployeeID#

状态:#状态#

详情:#详情#



-------------


现在我需要根据员工名单在c#代码中动态重复此部分。


如果有5名员工这样做内容应该重复5次。


Open XML的可行性。



我可以将现有块的文本替换为实际的。

但无法动态重复该块/页。


此外,我不知道我该怎么做d创建模板,我将获得内容的起点和终点。

我想文档模板需要以适当的格式创建。我不知道:(


提前致谢。







解决方案

我会给你通常的3部分办公室免责声明:


1.如果你可以将它限制为新的格式(docx,xl​​sx),你可以使用OpenXML SDK。或ZipArchive和XMLReader类。这些格式是公共的,然后重新命名.zip容器完全关闭。 xml文件。


2.如果你需要支持旧格式或新旧格式,你可以使用(t)生锈的办公室COM互操作。这有很多陷阱。尽可能避免。


3.对于任何给定的问题,源/目标格式和显示技术,可能会有第三种解决方案。但这些很少见,而且往往非常具体。


这里有一些关于这个主题的文章:

http://www.codeproject.com/Tips/666751/Use-OpenXML-to-Create-a-Word-Document-from-an-E xis


https://blogs.msdn.microsoft.com/vsod/2012/02/17/how -to-创建-A-文档从-A-模板DOTX-DOTM和 - 连接到它-使用开-XML的SDK /


Hello,

I have to create MS word document using one template file in C# using openxml dll.

I do not have any idea how should I start.

requirements is, In template there will be one page which will contain few information as below, and I need to repeat this block of content n'th times.

---------

Employee Name: #Name# 
Address: #Address#
Employee ID : #EmployeeID#
Status: #Status#
Details:#Details#

-------------

Now I need to repeat this section dynamically in c# code as per Employee List.

SO if there are 5 employees this content should get repeat 5 times.

How it is possible with Open XML.

I could replace text of existing block to actual one.
but unable to repeat that block / Page dynamically.

Also I'm not sure how I should create template where I will get starting and ending point of content.
I guess Document template needs to be create in proper format. Which I don't know :(

Thanks in advance.



解决方案

I will give you the usual 3 part office disclaimer:

1. If you can limit it to the new Formats (docx, xlsx) you can use OpenXML SDK. Or ZipArchive and XMLReader classes. these formats are public and little more then renamed .zip containers full off .xml files.

2. If you need to support the old formats or old and new, you ahve to use the (t)rusty office COM interop. Wich has seveal pitfalls. Avoid if possible.

3. For any given problem, source/target format and display technology there might be a 3rd Solution. But those are rare and often very specific.

Here some articles on this themathic:
http://www.codeproject.com/Tips/666751/Use-OpenXML-to-Create-a-Word-Document-from-an-Exis

https://blogs.msdn.microsoft.com/vsod/2012/02/17/how-to-create-a-document-from-a-template-dotx-dotm-and-attach-to-it-using-open-xml-sdk/


这篇关于使用文档模板openXML dll创建word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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