如何使用OpenXml将CSV /文本文件对象嵌入到word文档中 [英] How to embedded CSV/Text file object in to the word document using OpenXml

查看:274
本文介绍了如何使用OpenXml将CSV /文本文件对象嵌入到word文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用OpenXml sdk将CSV /文本文件对象嵌入到word文档中?



问候,

Ratheesh

解决方案

您可以使用 AltChunk类 [ ^ ]用于导入文件的内容。

你可以找到一个很好的视频教程(介绍)到altChunks 这里



但我需要指出的是,在这种情况下,你有一个 AlternativeFormatImportPartType.TextPlain ,您将获得此文本显示为Courier New,大小为10.5 d我相信不能改变。

但还有其他支持 AlternativeFormatImportPartType s [ ^ ]您可以使用(例如HTML),它可以让您定义此内容的样式(格式化)。


我有类似的场景,我必须在MS Word表格中提供外部文件的CSV文本数据,这也需要格式化。我正在使用第三方工具,因为它很容易创建模板文档,格式化然后我将CSV文件读入.NET类。在我的最后一步中,我合并模板和数据,并生成最终文档为.docx,pdf或xps。在某些情况下,我需要实现条件逻辑,根据用户选择的内容隐藏某些数据。该工具包基于数据中的布尔值在模板级别处理该工具包。



您可以看到如何使用该工具包的示例此处

How can i embedded CSV/Text file object in to the word document using OpenXml sdk?

Regards,
Ratheesh

解决方案

You can use AltChunk Class[^] which is used for importing the file's content.
You can find a nice video tutorial (introduction) to altChunks here.

But I need to point out that in this case, where you have an AlternativeFormatImportPartType.TextPlain, you will get this text displayed as "Courier New" with "10.5" size and I believe that cannot be changed.
But there are other supported AlternativeFormatImportPartTypes[^] that you could use (like HTML for example) which would enable you to define this content's styling (formatting).


I have similar scenario, where I have to present CSV text data from external file in MS Word table, which needs to be formatted as well. I am using 3rd party tool for that, because it is very easy to create a template document, format it and then I am reading CSV file into a .NET class. In my last step I merge template and data and generate final document as .docx, pdf or xps. In certain cases I need to implement conditional logic, which hides certain data, based on what user selects. The toolkit handles that on template level based on Boolean values in data.

You can see an example of how to use the toolkit here.


这篇关于如何使用OpenXml将CSV /文本文件对象嵌入到word文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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