目前我用的是WebBrowser 的打印功能,把页面不需要的隐藏,然后通过下列方法打印。
document.all.WebBrowser.ExecWB(8,1) 页面设置
document.all.WebBrowser.ExecWB(7,1) 打印预览
document.all.WebBrowser.ExecWB(6,1) 打印
通过上面说的方式打印。想不需要通过打印设置,用代码写死打印参数,比例:字体在小、横纵响、边距、纸张大小等。有别的打印方法也可以提供,不管理前台还是后台都可。谢谢!

解决方案 »

  1.   

    可以试一试这个控件
    预览这些都有
    DataPrinter.dll
      

  2.   

    这个需要自己绘制word,给你个我以前做的,看看对你有帮助吗,  string savepath = "";
                    FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        savepath = folderBrowserDialog1.SelectedPath;
                    }
                    else
                    {
                        return;
                    }                Object Nothing = System.Reflection.Missing.Value;
                    object filename = savepath + "/" + "客户交易信息单" + DateTime.Now.ToShortDateString() + "-" + DateTime.Now.ToShortTimeString().Substring(0, DateTime.Now.ToShortTimeString().IndexOf(":")) + "-" + DateTime.Now.ToShortTimeString().Substring(DateTime.Now.ToShortTimeString().IndexOf(":") + 1);                Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();                Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);                WordApp.ActiveDocument.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;                //11/04/14加入
                    ////页面设置  
                    WordApp.ActiveDocument.PageSetup.LeftMargin = WordApp.CentimetersToPoints(float.Parse("1.67"));//左页边距                  WordApp.ActiveDocument.PageSetup.RightMargin = WordApp.CentimetersToPoints(float.Parse("1.67"));//右页边距 
                    WordApp.Selection.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints(float.Parse("0"));//左缩进   
                    WordApp.Selection.ParagraphFormat.RightIndent = WordApp.CentimetersToPoints(float.Parse("0"));//右缩进                   WordApp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceMultiple;//单倍行距                   //文本不换行
                    WordApp.Selection.ParagraphFormat.FarEastLineBreakControl = 0;
                    WordApp.Selection.ParagraphFormat.WordWrap = 0;
                    //11/04/14加入
                    WordApp.Selection.Font.Bold = 0;
                    WordApp.Selection.Font.Size = 18;
                    WordApp.Selection.Font.Name = "黑体";
                    WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    WordApp.Selection.TypeText("客户交易信息单");
                    WordApp.Selection.TypeParagraph();                WordApp.Selection.Font.Bold = 0;
                    WordApp.Selection.Font.Size = 10;
                    WordApp.Selection.Font.Name = "宋体";
                    WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
                    WordApp.Selection.TypeText("日期:" + DateTime.Now.ToShortDateString());
                    WordApp.Selection.TypeParagraph();
                    Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(WordApp.Selection.Range, listOfTraShow.Count + 2, 8, ref Nothing, ref Nothing);                object style = "网格型";
                    table.set_Style(ref style);                //外边框颜色
                    table.Rows.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleInset;
                    table.Borders.OutsideColor = Microsoft.Office.Interop.Word.WdColor.wdColorBlack;
                    table.Borders.OutsideLineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth150pt;                //编写表格格式
                    table.LeftPadding = 0;
                    table.RightPadding = 0;
                    table.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;                table.Cell(1, 1).Range.Text = "aa";
                    table.Cell(1, 2).Range.Text = "bb";
                    table.Cell(1, 3).Range.Text = "cc";
                    table.Cell(1, 4).Range.Text = "dd";
                    table.Cell(1, 5).Range.Text = "ee";
                    for (int i = 0; i < listOfTraShow.Count; i++)
                    {
                        TransactionRecords tra = listOfTraShow[i];
                        table.Cell(i + 2, 1).Range.Text = "";
                        table.Cell(i + 2, 2).Range.Text = "";
                        table.Cell(i + 2, 3).Range.Text = "";
                        table.Cell(i + 2, 4).Range.Text = "";
                        table.Cell(i + 2, 5).Range.Text = "";
                    }                table.Cell(listOfTraShow.Count + 2, 1).Range.Text = "总计";
                                   //添加页脚
                    if (WordApp.ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView || WordApp.ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)
                    {
                        WordApp.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
                    }
                    WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryFooter;
                    string sFooter = "编制:" + "                                                  " + "审核:                                              ";
                    object objATEntry_Page = "第 X 页 共 Y 页";
                    WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//设置居中齐
                    object objTrue = true;
                    Range rng = WordApp.Selection.HeaderFooter.Range;
                    WordApp.NormalTemplate.AutoTextEntries.get_Item(ref objATEntry_Page).Insert(rng, ref objTrue);
                    WordApp.Selection.HeaderFooter.Range.InsertBefore(sFooter);
                    //退出页脚,返回正文
                    WordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;                WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                    WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
                    WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
                    MessageBox.Show("导出成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
      

  3.   


    <script language="javascript" type="text/javascript">
      var HKEY_Root, HKEY_Path, HKEY_Key;
      HKEY_Root = "HKEY_CURRENT_USER";
      HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      //设置网页打印的页眉页脚为空  
      function PageSetup_Null() {
      try {
      var Wsh = new ActiveXObject("WScript.Shell");
      HKEY_Key = "header";
      Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
      HKEY_Key = "footer";
      Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
      }
      catch (e)
    { }
    }
      function printpage(myDiv){ //DIV控制打印
        
      //var newstr = document.all.item(myDiv).innerHTML;  
      var newstr = document.getElementById(myDiv).innerHTML;
    // alert(newstr);
      var oldstr = document.body.innerHTML;  
      document.body.innerHTML = newstr;  
      window.print();  
      document.body.innerHTML = oldstr;  
      return false;  
      }  
    function preview() {
      PageSetup_Null();
      bdhtml=window.document.body.innerHTML;
      sprnstr="<!--startprint-->";
      eprnstr="<!--endprint-->";
      prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
      prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
      window.document.body.innerHTML=prnhtml;
      window.print();
    }
        </script>    <style>
            body
            {
                font-size: 16px;
                color: Black;
            }
        </style>
        <style media="print">
            .Noprint
            {
                display: none;
            }
            .PageNext
            {
                page-break-after: always;
            }
        </style>
    <div style="text-align: center; height: 30px; width: 595" class="Noprint">
                <input class="Noprn" type="button" onclick="window.print()" value="打印" />
                <input type="button" name="print" value="预览并打印" onclick="preview()" />
                <input type="button" id="bt" onclick="javascript:printpage('bt')" value="DIV打印" />
                <asp:Button ID="Button1" runat="server" Text="编辑" onclick="Button1_Click" />
                <asp:Button ID="Button2" runat="server" Text="保存" Visible="false" 
                    onclick="Button2_Click" />
            </div>
    这是借用一位大牛的
      

  4.   

    http://blog.csdn.net/happy09li/article/details/6931959