怎么实现打印功能

解决方案 »

  1.   

      private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
       /*
        *
        */
    }
      

  2.   

    不带格式的  table 字体 加粗斜体 都没了
      

  3.   

    <P class=msonormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 25pt; TEXT-ALIGN: center; mso-line-height-rule: exactly" align=center><SPAN style="FONT-SIZE: 22pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.0pt; mso-hansi-font-family: times new roman; mso-ascii-font-family: times new roman">经济开发区区内企业用电情况综合调查表</SPAN><SPAN lang=en-us style="FONT-SIZE: 22pt; mso-bidi-font-size: 10.0pt"><FONT face="times new roman"> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
    <P class=msonormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 25pt; mso-line-height-rule: exactly"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-hansi-font-family: times new roman; mso-ascii-font-family: times new roman">区内各企业:</SPAN><SPAN lang=en-us style="FONT-SIZE: 14pt"><o:p></o:p></SPAN></P>
      

  4.   


     // 设置报告的设备信息
            protected void SetDeviceInfo(LocalReport report)
            {
                Warning[] warnings;
                m_streams = new List<Stream>();
                m_currentPageIndex = 0;            try
                {
                    report.Render("Image", DeviceInfo, CreateStream, out warnings);
                }
                catch (Exception e)
                {
                    ErrMessage = e.Message + e.InnerException.Message;
                    System.Windows.Forms.MessageBox.Show(ErrMessage);
                }            foreach (Stream stream in m_streams)
                    stream.Position = 0;
            }        // 构建流 
            protected Stream CreateStream(string name, string fileNameExtension, Encoding enfcoding, string mimeType, bool willSeek)
            {
                Stream stream;
                m_currentPageIndex++;
                stream = new FileStream(ReportNo + "-" + m_currentPageIndex.ToString() + ".emf", FileMode.OpenOrCreate); 
                m_streams.Add(stream);
                return stream;
            }        // 打印报告
            protected void PrintDialog()
            {
                if (m_streams == null || m_streams.Count == 0)
                    return;            m_currentPageIndex = 0;  // 从首页开始打印            PrintDocument printDoc = new PrintDocument();
                printDoc.PrintController = new System.Drawing.Printing.StandardPrintController();
                printDoc.DocumentName = "报告-" + ReportNo + "-" + SpecimenXhSet;            if (PrinterName != "")  // 如指定过打印机,则用指定的,一般使用默认打印机
                    printDoc.PrinterSettings.PrinterName = PrinterName;
                if (!printDoc.PrinterSettings.IsValid)
                {
                    string msg = String.Format("打印机不可用!! \"{0}\".", PrinterName);
                    Console.WriteLine(msg);
                    ErrMessage = msg;
                    return;
                }
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                try
                {
                    printDoc.Print();                              // 开始打印
                    Thread.Sleep(500);
                    foreach (Stream stream in m_streams)           // 使用完后,一定要关闭文件流对象!!
                    {
                        stream.Close();
                    }
                    if (System.IO.File.Exists(ReportNo + ".emf"))  // 删除报告图像文件名!
                        File.Delete(ReportNo + ".emf");
                    for (int j = 0; j <= m_currentPageIndex; j++)
                    {
                        if (System.IO.File.Exists(ReportNo + "-" + j.ToString() + ".emf"))  // 删除报告图像文件名!
                            File.Delete(ReportNo + "-" + j.ToString() + ".emf");
                    }
                }
                catch (Exception e)
                {
                    if (!e.Message.Contains("成功"))  // 对于提示"操作成功完成"的提醒,不做处理!
                        MessageBox.Show("现在不能打印," + e.Message);
                }
            }        // 页打印事件处理
            protected void PrintPage(object sender, PrintPageEventArgs ev)
            {
                Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);  // 根据数据流,生成图形数据            ev.Graphics.DrawImage(pageImage, ev.PageBounds);            m_currentPageIndex++;
                ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
            }
      

  5.   

    这个也可以  这两个不一样 别弄错了
    // 打印
            protected void PrintDialog()
            {     
                PrintDocument printDoc = new PrintDocument();
                printDoc.PrintController = new System.Drawing.Printing.StandardPrintController();
                printDoc.DocumentName = "报告-" + this.ReportNo;            if (PrinterName != "")  // 如指定过打印机,则用指定的,一般使用默认打印机
                    printDoc.PrinterSettings.PrinterName = PrinterName;
                if (!printDoc.PrinterSettings.IsValid)
                {
                    string msg = String.Format("打印机不可用!! \"{0}\".", PrinterName);
                    Console.WriteLine(msg);
                    ErrMessage = msg;
                    return;
                }            printDoc.PrintPage += new PrintPageEventHandler(PrintPage);            try
                {
                    printDoc.Print();                              // 开始打印
                    // ... 
                     
                }
                catch (Exception e)
                {
                    if (!e.Message.Contains("成功"))  // 对于提示"操作成功完成"的提醒,不做处理!
                        MessageBox.Show("现在不能打印," + e.Message);
                }
            }        // 页打印事件处理
            protected void PrintPage(object sender, PrintPageEventArgs ev)
            {
                Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);  // 根据数据流,生成图形数据
                
                ev.Graphics.DrawImage(pageImage, ev.PageBounds);            m_currentPageIndex++;
                ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
            }
      

  6.   

    参数m_streams,m_currentPageIndex 是什么啊
      

  7.   

    导出到页面window.print打印
      

  8.   

    页面打印<div class="Noprint" align="center">
    <OBJECT id="WebBrowser" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
    VIEWASTEXT>
    </OBJECT>
    <input onclick="document.all.WebBrowser.ExecWB(6,1)" type="button" value="打印"> <input onclick="document.all.WebBrowser.ExecWB(6,6)" type="button" value="直接打印">
    <input onclick="document.all.WebBrowser.ExecWB(8,1)" type="button" value="页面设置">
    <input onclick="document.all.WebBrowser.ExecWB(7,1)" type="button" value="打印预览">
    </div>
      

  9.   

    using Microsoft.Reportint.WinForms;在winform中不支持
    LocalReport应该是上面命名空间的吧?这就不行了啊
      

  10.   


      用Web打印也是可以的而且比较简单。  希望对你有帮助
     
    <head>
    //这个是用来隐藏不打印的部分 CSS
    <style type="text/css" media=print>
        .noprint{display : none }
        </style>
    </head>
    <form>
    <OBJECT id="WebBrowser" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" VIEWASTEXT>
    </OBJECT><p class="noprint" align="center">  //来隐藏不打印的部分
    <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>  
        <input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>  
        <input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>    
        <input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印 id="Button2">    
        <input name=Button onClick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>  
        <input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>      
        <input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>  
        </p>
    </form>
      

  11.   


    private Excel.Application xApp = null;
    private Excel.Workbook xBook = null;
    private Excel.Worksheet xSheet = null;private void Print()
            {
               // check条件
                 CheckPrint();
                // excel output method
                // new Application
                xApp = new Excel.ApplicationClass();
                xApp.Visible = false;
                xApp.DisplayAlerts = false;
                //_excel.DisplayAlerts = false;
                xApp.AlertBeforeOverwriting = false;
                // get file path 模板
                string path = Application.StartupPath.Trim() + @"\report\test.xls";
                // open xml file 
                xBook = xApp.Workbooks.Open(path,
                        Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                        Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                        Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                // open file's sheet
                xSheet = (Excel.Worksheet)xBook.Sheets[1];
                // Sheet名
                xSheet.Name = ReplaceString(txtSozai.Text);            object missing = System.Reflection.Missing.Value;
                #region 插入数据            
                  // 比如画面上有个textbox,放到模板中的A2
                xSheet[2,1] = textbox.text;
                #endregion            #region 印刷
                  xApp.Visible = true;
                //EXCEL印刷
                xSheet.PrintOut(missing, missing, missing, true, cboPrint.Text, missing, missing, missing);
                // 打印出来存放位置
                string pathFile = Application.StartupPath.Trim()
                    + @"\test";
                if (Directory.Exists(pathFile) == false)
                {
                    // 创建pathFile  
                    Directory.CreateDirectory(pathFile);
                }
                // 文件名
                String pathName = pathFile + ".xls";
                if (File.Exists(pathName))
                {
                    FileInfo fi1 = new FileInfo(pathName);
                    fi1.Attributes = FileAttributes.Normal;
                    File.Delete(pathName);
                }
                xApp.ActiveWorkbook.SaveAs(
                    pathName,
                    Excel.XlFileFormat.xlExcel9795,
                    null,
                    null,
                    false,
                    false,
                    Excel.XlSaveAsAccessMode.xlNoChange,
                    null,
                    null,
                    null,
                    null);            FileInfo fi = new FileInfo(pathName);            fi.Attributes = fi.Attributes | FileAttributes.ReadOnly;
                // Close
                xApp.Application.Workbooks.Close();
                xApp.Quit();
                #endregion
            }