我在我的 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