2010-01-12 26 views
1

以下是我打印Excel文档预览的代码。Excel PrintPreview

编译成功。

但预览窗口不可见。任何机构都可以指出我的错误。是否需要添加更多编码或dll。

(注:该文件包含数据)

 Excel.Application excelApp = new Excel.Application(); 

     Excel.Workbook wb = excelApp.Workbooks.Open(@"C:\\Documents and Settings\\Admin\\Desktop\\DoCoMo\\news5.xls", 
         Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
         Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
         Type.Missing, Type.Missing, Type.Missing, Type.Missing); 
     Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1]; 
     bool userDidntCancel = excelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogPrintPreview].Show(    
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 




     GC.Collect(); 
     GC.WaitForPendingFinalizers(); 
     wb.Close(false, Type.Missing, Type.Missing); 
     excelApp.Quit(); 

回答

0

您需要的excelApp可见属性设置为true。

Excel.Application excelApp = new Excel.Application(); 
excelApp.Visible = true; 
+0

谢谢你的支持者。 现在它工作正常。 From, M.Thillai。 – 2010-01-12 06:41:05

3

您可能需要手动显示Excel窗口:

excelApp.Visible = true; 

不过,我听说他们是与特定的Excel版本的一些问题(它可能对一些工作,而不是为其他)。

+0

谢谢你Zxpro。 现在它工作正常。 From, M.Thillai。 – 2010-01-12 06:40:21

+0

对版本问题发出警告。我知道这已经过了一年多了,但是关于它“可能为谁工作”的具体信息以及它可能无效的具体信息? – Yetti 2011-03-28 15:51:20