Csharp 打印Word文件默認打印機設置或選擇打印機設置代碼

简介: //打印文檔 object nullobj = Missing.Value; //aDoc = wordApp.Documents.Open(ref file, // ref nullobj, ref nullobj
 //打印文檔
                    object nullobj = Missing.Value;
                    //aDoc = wordApp.Documents.Open(ref file,
                    //                            ref nullobj, ref nullobj, ref nullobj,
                    //                            ref nullobj, ref nullobj, ref nullobj,
                    //                            ref nullobj, ref nullobj, ref nullobj,
                    //                            ref nullobj, ref nullobj, ref nullobj,
                    //                            ref nullobj, ref nullobj, ref nullobj);



                    //aDoc.Activate();
                    wordApp.Visible = false;
                    //wordApp.ActivePrinter = "My Printer Name";
                    try
                    {
                        // 參考:http://msdn.microsoft.com/en-us/library/b9f0ke7y.aspx 
                        //塗聚文 2011-11-04 缔友计算机信息技术有限公司
                        //1。默認打印機設置
                        PrintDialog print = new PrintDialog();
                        print.PrinterSettings = new PrinterSettings();
                        strDefaultPrinter = print.PrinterSettings.PrinterName;
                        aDoc.Application.ActivePrinter = strDefaultPrinter;
                        object copies = "1";
                        object pages = "1";
                        object range = Word.WdPrintOutRange.wdPrintCurrentPage;
                        object items = Word.WdPrintOutItem.wdPrintDocumentContent;
                        object pageType = Word.WdPrintOutPages.wdPrintAllPages;
                        object oTrue = true;
                        object oFalse = false;
                        aDoc.PrintOut(ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        ref nullobj, ref nullobj);

                    //    aDoc.PrintOut(ref oTrue, ref oFalse, ref range, ref nullobj,
                    //ref nullobj, ref nullobj, ref items, ref copies, ref pages, ref pageType, ref nullobj, ref nullobj,
                    //ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                    //ref nullobj, ref nullobj);
                        //2。弹出打印機设置
                        //塗聚文 2011-11-04 缔友计算机信息技术有限公司
                        //int dialogResult = wordApp.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref nullobj);
                        //if (dialogResult == 1)
                        //{
                        //    aDoc.PrintOut(ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        //                 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        //                 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        //                 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                        //                 ref nullobj, ref nullobj);
                        //}
                        while (wordApp.BackgroundPrintingStatus > 0)
                        {
                            System.Threading.Thread.Sleep(250);
                        }


                        Object saveChanges = Word.WdSaveOptions.wdSaveChanges;
                        Object originalFormat = Type.Missing;
                        Object routeDocument = Type.Missing;
                        wordApp.Documents.Close(ref saveChanges,
                            ref originalFormat, ref routeDocument);
                        Object saveChangesQuit = Word.WdSaveOptions.wdSaveChanges;
                        Object originalFormatQuit = Type.Missing;
                        Object routeDocumentQuit = Type.Missing;
                        wordApp.Quit(ref saveChangesQuit,
                            ref originalFormatQuit, ref routeDocumentQuit);


                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        MessageBox.Show("請設定默認打印機");
                    }
                    finally
                    {
                        //MessageBox.Show("你設定的默認打印機是:"+strDefaultPrinter.ToString());
                    }

                }


目录
相关文章
|
4月前
|
物联网 Linux 流计算
EasyLogger--不一样的打印输出
EasyLogger--不一样的打印输出
|
2月前
|
容器
打印
打印
46 0
Word打印
4.6 打印 4.6.1 分页符的插入及删除 1、插入水平分页符 选定要插入分页符位置的下一行,在“页面布局”选项卡的“页面设置”组单击“分隔符”,在出现的下拉列表中选择”插入分页符”命令 2、插入垂直分页符 选定要插入分页符位置的右侧列,在“页面布局”选项卡的“页面设置”组单击“分隔符”,在出现的下拉列表中选择”插入分页符”命令。 3、同时插入水平、垂直分页符 选定某单元格,在“页面布局”选项卡的“页面设置”组单击“分隔符”,在出现的下拉列表中选择“插入分页符”命令此时会在该单元格左边框和上边框位置同时插入水平、垂直分页符。 4、删除手动分页符 先选择紧邻水平分页符的下面行 (或该行
打印
4.6 打印 4.6.1 分页符的插入及删除 1、插入水平分页符 选定要插入分页符位置的下一行,在“页面布局”选项卡的“页面设置”组单击“分隔符”,在出现的下拉列表中选择”插入分页符”命令 2、插入垂直分页符 选定要插入分页符位置的右侧列,在“页面布局”选项卡的“页面设置”组单击“分隔符”,在出现的下拉列表中选择”插入分页符”命令。 3、同时插入水平、垂直分页符 选定某单元格,在“页面布局”选项卡的“页面设置”组单击“分隔符”,在出现的下拉列表中选择“插入分页符”命令此时会在该单元格左边框和上边框位置同时插入水平、垂直分页符。 4、删除手动分页符 先选择紧邻水平分页符的下面行 (或该行
|
安全 数据安全/隐私保护
文档的保存和打印
3.8 文档的保存与打印 3.8.1 防止文档内容丢失 1. 自动恢复 Word提供自动恢复功能,可在很大程度上避免因为停电、机器死机等问题引发的文档丢失现象。在“文件”选项卡中的“选项”命令,在其中的“保存”选项卡中设置,默认10分钟,可以修改(1-120分钟)。 2. 自动备份文档副本 在编辑Word文档时,如果不小心保存了不需要的信息,或者原文档损坏,可以使用文档备份的副本避免损失。当然,这需要你事先在Word系统设置了“始终创建备份副本”功能,具体操作如下: 1单击“文件”选项卡,选择“选项”命令,打开对话框设置。 2选择此选项可在每次保存文档时创建一个文档的备份副本扩展名为 .wbk
|
图形学 C++
Qt实现Qchart的打印和打印预览的几种方法
Qt实现Qchart的打印和打印预览的几种方法
|
Python
笨办法学 Python--跟书练习九~打印 打印 打印
笨办法学 Python--跟书练习九~打印 打印 打印
102 0
笨办法学 Python--跟书练习九~打印 打印 打印