简体   繁体   English

Excel打印预览

[英]Excel PrintPreview

The Following is my code to print preview for an excel document. 以下是我的代码,用于打印Excel文档的预览。

The compilation is successful. 编译成功。

But the preview window is not visible. 但是预览窗口不可见。 Can any body point me what is the error. 任何人都可以指出我的错误是什么。 Is there is need to add any more codings or dlls. 是否需要添加更多的编码或dll。

(Note: The Document contains data) (注意:文档包含数据)

        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();

You might have to manually show the Excel window: 您可能必须手动显示Excel窗口:

excelApp.Visible = true;

However, I've heard that they are some issues related to specific Excel versions (it might work for some, and not for others). 但是,我听说它们是与特定Excel版本有关的一些问题(可能对某些版本有效,而对另一些版本无效)。

You need to set the Visible property of the excelApp to true. 您需要将excelAppVisible属性设置为true。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM