• WOrd ,excel实现打印功能


                PrintDocument print = new PrintDocument();
                string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
                string s = "";
                foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
                {
                    s = sPrint;
                }
                return;
                OpenFileDialog fileDialog = new OpenFileDialog();
                //fileDialog.Title = "请选择文件";
                //fileDialog.Filter = "excel03文件(*.xls)|*.xls";
                //fileDialog.FilterIndex = 1;
                //fileDialog.RestoreDirectory = true;

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    #region excel
                    //Microsoft.Office.Interop.Excel.ApplicationClass xlsApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                    //xlsApp.Visible = true;
                    //object oMissing = System.Reflection.Missing.Value;
                    //Microsoft.Office.Interop.Excel.Workbook xlsWorkbook = xlsApp.Workbooks.Open(fileDialog.FileName, 0, true, 5, oMissing, oMissing, true, 1, oMissing, false, false, oMissing, false, oMissing, oMissing);
                    //Microsoft.Office.Interop.Excel.Worksheet xlsWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsWorkbook.Worksheets[1];
                    ////xlsWorksheet.PrintPreview(null);
                    //xlsWorksheet.PrintOut(1, 2, 1, false, oMissing, true, false, oMissing);
                    //xlsApp.Visible = false;
                    //xlsWorksheet = null;
                    #endregion
                    #region word
                    object wordFile = fileDialog.FileName;
                    object oMissing = Missing.Value;
                    object copies = "1";
                    object oTrue = true;
                    object oFalse = false;
                    object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
                    Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
                    appWord.Visible = false;
                    appWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
                    string defaultPrinter = appWord.ActivePrinter;
                    Microsoft.Office.Interop.Word.Document doc = appWord.Documents.Open(
                        ref wordFile ,
                        ref oMissing,
                        ref oTrue ,
                        ref oFalse ,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing);
                    //弹出打印设置
                    //appWord.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref oMissing);
                    //appWord.Visible = false;
                    appWord.ActivePrinter = "hp3030 ";
                    doc.PrintOut(
                        ref oTrue,
                        ref oFalse,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref copies,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing,
                        ref oMissing);
                    appWord.ActivePrinter = defaultPrinter;
                    doc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
                    appWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                    doc = null;
                    appWord = null;
                    GC.Collect();
                    #endregion word

                }

  • 相关阅读:
    在 Students 的 Index 页面增加列标题链接(排序),分页,过滤和分组功能
    Contoso 大学
    如何搭建MVC + EF 框架
    EF与手写Model的区别以及联系
    報錯:One or more validation errors were detected during model generation:System.Data.Edm.EdmEntityType: : EntityType 'Movie' has no key
    Oracle四舍五入,向上取整,向下取整
    datagrid中设置编辑,删除列是否可以访问
    datagrid中设置编辑,删除列是否可以访问
    C#实现打印
    C#中rpt的数据类型和Oracle中数据类型的匹配
  • 原文地址:https://www.cnblogs.com/swarb/p/9924430.html
Copyright © 2020-2023  润新知