RTF格式的WordML转换在C# [英] Rtf to WordML Convert in C#

查看:280
本文介绍了RTF格式的WordML转换在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序来生成报告。 它在RTF模板, {\\ \\ RTF1 ANSI \\ ansicpg1252 \\ deff0 \\ deflang2057 {\\ fonttbl {\\ \\ F0 \\ fnil宋体fcharset0;}} \ r \ ñ\\ viewkind4 \\ \\ UC1 PARD \\ FS20 \\ \\标签卡\\ \\标签标签AF \\面值\ r \ n}的\ r \ N,这是写以Word文档文件。那么这个词被保存,如XML和关闭。然后,标签,如(说)提取和一些新的

这里的问题是字,这是作为转换的过程中,它会消耗宝贵的时间在循环中,它会打开一个word实例,保存,关闭,删除。

I have a windows application to generate report. It has templates in RTF as "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\r\n\\viewkind4\\uc1\\pard\\fs20\\tab\\tab\\tab\\tab af\\par\r\n}\r\n", which is written to word doc file. then the word is Saved-As XML and close. Then, tags like (say) are extracted and some new

The problem here is Word, which is used as converter in the process and it consumes valuable time in Loop, where it opens word instance, save, close, delete.

请纠正任何错误,如果我做了,帮我一个替代转换为WordML中。

Please correct any mistake if i have made and help me with an alternative to convert to WordML .

推荐答案

使用的Aspose .Words

Use Aspose .Words

//your rtf string
string rtfStrx = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\r\n\\viewkind4\\uc1\\pard\\fs20\\tab\\tab\\tab\\tab af\\par\r\n}\r\n"

//convert string to bytes for memory stream
byte[] rtfBytex = Encoding.UTF8.GetBytes(rtfStrx);
MemoryStream rtfStreamx = new MemoryStream(rtfBytex);

Document rtfDocx = new Document(rtfStreamx);

rtfDocx.Save(@"C:\Temp.xml", SaveFormat.WordML);

这节省了在新的文档的WordML您的RTF文本。我不能说这一次将采取循环。但它肯定会少得多的时间,那么微软Word文件的物理打开和关闭。

This saves your RTF text in new document as WordML. I cannot say about time it will take in loop. But it will surely have much less time then MS Word being physically opened and closed.

这篇关于RTF格式的WordML转换在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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