Documentviewer WPF 中的奇怪迹象

发布于 2024-11-10 00:54:50 字数 1842 浏览 4 评论 0原文

我正在向我的 WPF 项目添加一个文档查看器,一切看起来都很完美。但是,当我尝试打开另一个 xps 文件时,文档查看器会在我的文档中放置一些 [?] 符号。

这是我的代码:

 if (xps != null)
                {
                    xps.Close();
                    xps = null;
                }

                docViewer.Document = null;
                Microsoft.Office.Interop.Excel.Application eApp = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbook eWb;
                Microsoft.Office.Interop.Excel.Worksheet eWs;

                eApp.Visible = false;

                eWb = eApp.Workbooks.Open(gekozenProductBestand, false,false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, false, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                eWs = (Microsoft.Office.Interop.Excel.Worksheet)eWb.Worksheets[1];
                eWs.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
                eWb.ExportAsFixedFormat(XlFixedFormatType.xlTypeXPS, System.IO.Path.GetTempPath() + "producten", XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing, Type.Missing, false, Type.Missing);

                eApp.DisplayAlerts = false;
                eApp.Quit();
                xps = new XpsDocument(System.IO.Path.GetTempPath() + "producten.xps", System.IO.FileAccess.Read);

                docViewer.Document = xps.GetFixedDocumentSequence();
                docViewer.FitToWidth();


                eApp.DisplayAlerts = false;
                eWs = null;
                eWb = null;
                eApp.Quit();
                eApp = null;

                GC.Collect();

最后一张图片让我清楚: http://img818.imageshack.us/img818/7043/knipselq.png

I'm adding a document viewer to my WPF project and all seems perfect. But when I try to open another xps file, the documentviewer places some [?] signs in my document.

Here's my code :

 if (xps != null)
                {
                    xps.Close();
                    xps = null;
                }

                docViewer.Document = null;
                Microsoft.Office.Interop.Excel.Application eApp = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbook eWb;
                Microsoft.Office.Interop.Excel.Worksheet eWs;

                eApp.Visible = false;

                eWb = eApp.Workbooks.Open(gekozenProductBestand, false,false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, false, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                eWs = (Microsoft.Office.Interop.Excel.Worksheet)eWb.Worksheets[1];
                eWs.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
                eWb.ExportAsFixedFormat(XlFixedFormatType.xlTypeXPS, System.IO.Path.GetTempPath() + "producten", XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing, Type.Missing, false, Type.Missing);

                eApp.DisplayAlerts = false;
                eApp.Quit();
                xps = new XpsDocument(System.IO.Path.GetTempPath() + "producten.xps", System.IO.FileAccess.Read);

                docViewer.Document = xps.GetFixedDocumentSequence();
                docViewer.FitToWidth();


                eApp.DisplayAlerts = false;
                eWs = null;
                eWb = null;
                eApp.Quit();
                eApp = null;

                GC.Collect();

And finally an image to make myself clear :
http://img818.imageshack.us/img818/7043/knipselq.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文