首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#开放办公文档和来自MemoryStream的Xps文件

C#开放办公文档和来自MemoryStream的Xps文件
EN

Stack Overflow用户
提问于 2011-07-20 19:11:14
回答 2查看 5.9K关注 0票数 2

我有一个通过Xps查看器查看Word和Excel文件的应用程序。我将office文件转换为xps文件,并在WPF XPS文档查看器中显示。

但是这里有一个小问题,我不希望用户看到这些文件,而是在关闭后删除这些文件。

我想知道有没有办法将xps转换成内存流,并在Xps Viewer中查看它

编辑:

我不想在磁盘上创建任何xps文件。转换过程必须在内部完成到MemoryStream。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-20 19:18:16

在poc项目中,下面的代码行对我很好,可以给您一个起点。对于文档转换部分(word/excel -> xps),您只需使用自动打印它们。

代码语言:javascript
复制
System.IO.Stream docStream = ...any xps as stream;
Package package = Package.Open(docStream);

//Create URI for Xps Package
//Any Uri will actually be fine here. It acts as a place holder for the
//Uri of the package inside of the PackageStore
string inMemoryPackageName = string.Format("memorystream://{0}.xps", Guid.NewGuid());
Uri packageUri = new Uri(inMemoryPackageName);

//Add package to PackageStore
PackageStore.AddPackage(packageUri, package);

XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum, inMemoryPackageName);
FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();

// Do operations on xpsDoc here
DocViewer.Document = fixedDocumentSequence;

//Note: Please note that you must keep the Package object in PackageStore until you
//are completely done with it since certain operations on XpsDocument can trigger
//delayed resource loading from the package.

//PackageStore.RemovePackage(packageUri);
//xpsDoc.Close();
票数 8
EN

Stack Overflow用户

发布于 2011-07-20 19:23:21

请出示一些密码..。

如果您的XPS文档被写入流中,则可以将该流传递给Package.Open,然后将包传递给XpsDocument,然后将Xpsdocument传递给DocumentViewer.这样,xps就一直保存在内存中。

例如,Aspose.Words/..Cells可以从word和Excel生成XPS到流中,因此不涉及任何文件.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6767192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档