RTF格式的WordML转换在C#格式、RTF、WordML

2023-09-04 04:45:49 作者:为爱搁浅心脏

我有一个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.