首页 > 编程 > .NET > 正文

Asp.net 水晶报表之打印和导出格式

2024-07-10 13:11:06
字体:
来源:转载
供稿:网友
  在asp.net中水晶报表没有象在windows form中那样提供报表的导出和打印功能,需要我们自己动手添加代码来控制,下面给个demo:

  导出:
myreport  reportdoc = new myreport();//表表的名称
private void btnexport_click(object sender, system.eventargs e)
  {
   crystaldecisions.shared.diskfiledestinationoptions diskopts = new  crystaldecisions.shared.diskfiledestinationoptions();
   reportdoc.exportoptions.exportdestinationtype = crystaldecisions.shared.exportdestinationtype.diskfile;
   switch (dropdownlist1.selecteditem.text)
   {
    case "rich text (rtf)":
       reportdoc.exportoptions.exportformattype =   crystaldecisions.shared.exportformattype.richtext;
       diskopts.diskfilename = "d://demo.rtf";
     break;
    case "portable document (pdf)":
       reportdoc.exportoptions.exportformattype =   crystaldecisions.shared.exportformattype.portabledocformat;
       diskopts.diskfilename = "d://demo.pdf";
     break;
    case "ms word (doc)":
       reportdoc.exportoptions.exportformattype =   crystaldecisions.shared.exportformattype.wordforwindows;
       diskopts.diskfilename = "d://demo.doc";
     break;
    case "ms excel (xls)":
       reportdoc.exportoptions.exportformattype =   crystaldecisions.shared.exportformattype.excel;
       diskopts.diskfilename = "d://demo.xls";
     break;
    default:
     break;
   }
   reportdoc.exportoptions.destinationoptions = diskopts;
    reportdoc.export();
  }

  打印:
private void btnprint_click(object sender, system.eventargs e)
  {
     string strprintername; // 指定打印机名称     
   strprintername = @"canon bubble-jet bjc-210sp"; 
   pagemargins margins;  // 设置打印页边距
   margins = reportdoc.printoptions.pagemargins;
   margins.bottommargin = 250;
   margins.leftmargin = 350;
   margins.rightmargin = 350;
   margins.topmargin = 450;    
   reportdoc.printoptions.applypagemargins(margins);     
   reportdoc.printoptions.printername = strprintername;  //应用打印机名称    
     // 打印报表.startpagen 和 endpagen
   // 参数设置为 0 表示打印所有页。
   reportdoc.printtoprinter(1, false,0,0);     
   }
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表