4

给定以下代码片段

wordApp.Documents.Open(FileName: wordDoc, Visible: false); 

if (wordApp.Documents.Count > 0)
{
      _Document thisDoc = wordApp.ActiveDocument;
      thisDoc.SaveAs(FileName: rtfDoc, FileFormat: WdSaveFormat.wdFormatRTF);

谁能建议一种方法来执行此转换而不保存到磁盘?

我想要 rtf 文档的原始文本在内存中,也许是一个 StringBuilder 对象。

4

1 回答 1

2

Unfortunately, this is just not possible.

With Office Interop, there is NO way to use such methods (Open, SaveAs) with something else than a valid file (so it must exist or be saved on the disk or somewhere else).

What you need to keep in mind, is that Interop allows you to do at most what you could do with the Office application itself. And there is currently no way to work with MemoryStream with Office Application, just existing files.

Working with MemoryStream is possible with OpenXML SDK. Unfortunately, OpenXml SDK does not provide method to convert to Rtf format.

See also: How can I form a Word document using stream of bytes

于 2013-09-12T19:03:04.990 回答