English 中文(简体)
C# Open Office Documents and Xps file from MemoryStream
原标题:C# Open Office Documents and Xps Files from MemoryStream
  • 时间:2011-07-20 19:11:14
  •  标签:
  • c#
  • .net
  • wpf

我曾申请通过Xps Viewer查看Word和Excel文档。 我将办公室档案转换成Xps文档,并在世界森林基金XPS文件观点中显示。

But here is a little problem; I don t want the users see the files, i delete the files after closing.

我很想知道,是否有任何办法将微粒转换为记忆流,并在Xps Viewer中看到。

<><>Edit>:

我不想在磁盘上制造任何微薄文档。 转换过程必须在记忆中进行。

最佳回答

Following lines of code worked fine for me on a poc project and can give you a starting point. For the document conversion part (word/excel -> xps) you could just print them via automation using XPS Document Writer.

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();
问题回答

请列出一些法典......

如果将你的XPS文件编成一流,你可以将这一流传到<代码>。 开放,然后是<代码>XpsDocument>,然后是Xpsdocument-。 这样一来,微粒就永远保持记忆。

例如,Aspose。 说 明 电池可以从文字和Excel中生成XPS,从而不会涉及任何档案。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...