动态水晶报表

创建动态水晶报表的官方 VB.NET 程序实例.exe
http://blog.csdn.net/haibodotnet/archive/2003/12/11/21546.aspx

创建不受数据库限制的报表
http://blog.csdn.net/babyt/category/39074.aspx

也可以创建一些空的公式字段,预先防在报表上,然后动态给公式字段扶植。

crReportDocument.SetDataSource(Ds);
   
   ExportOptions crExportOptions; //导出选项
   
   DiskFileDestinationOptions crDiskFileDestinationOptions;
   
   String Fname;    //导出完整名称
   

   //String FileName = "";
   String FileName = "my.pdf";
   
   String _SystemPath =Request.PhysicalApplicationPath;
   if(!System.IO.Directory.Exists(_SystemPath))
    System.IO.Directory.CreateDirectory(_SystemPath);
   
   Fname = _SystemPath + FileName; //导出完整名称

   
   crDiskFileDestinationOptions = new DiskFileDestinationOptions();
   crDiskFileDestinationOptions.DiskFileName = Fname;

   crExportOptions = crReportDocument.ExportOptions;
   
   crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
   crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
   crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
   
   crReportDocument.Export();

//
//========================================================================================
  // 打印和导出水晶报表
  //========================================================================================
  /// <summary>
  /// 打印一份crystal Report
  /// </summary>
  
  /// <param name="reportPath">报表路径</param>
  /// <param name="reportSet">报表数据源的DataSet</param>
  public void printReport(string reportPath,string PrinterPath,string passWrd)
  {
   ReportDocument  crystalReportObject=new ReportDocument();
   //   crystalReportObject.
   crystalReportObject.Load(reportPath);//"e://temp//crt.rpt"
   //   crystalReportObject.s
   //crystalReportObject.SetDataSource(reportSet);
   crystalReportObject.Refresh();
   this.SetConnectionInfo(crystalReportObject,passWrd);
   //crystalReportObject.PrintOptions.PrinterName =@"//office1/HP1000";
   crystalReportObject.PrintOptions.PrinterName =PrinterPath ;
   try
   {
    crystalReportObject.PrintToPrinter(1,false, 0, 0);
   }
   catch
   {
    ;
   }
   finally
   {
    crystalReportObject.Close();
   }
   //   CrystalDecisions.Web.CrystalReportViewer myView=new CrystalDecisions.Web.CrystalReportViewer();
   //   myView.LogOnInfo
  }


  public void printReport(string PrinterPath,ReportDocument crystalReportObject)
  {

   crystalReportObject.PrintOptions.PrinterName =PrinterPath ;
   try
   {
    crystalReportObject.PrintToPrinter(1,false, 0, 0);
   }
   catch
   {
    ;
   }
   finally
   {
    crystalReportObject.Close();
   }
   //   CrystalDecisions.Web.CrystalReportViewer myView=new CrystalDecisions.Web.CrystalReportViewer();
   //   myView.LogOnInfo
  }

  //  public ReportDocument InitReportDoc(DataSet myDs,string reportPath,string passWrd)
  //  {
  //   ReportDocument oRD = new ReportDocument();
  //   oRD.Load(reportPath);
  //   oRD.SetDataSource(myDs);
  //   oRD.Refresh();
  //   this.SetConnectionInfo(oRD,passWrd);
  //   return oRD;
  //   
  //  }

  public void ExportCrystalReport(string targetFileName,string reportPath,string docFormat,string passWrd)
  {
   ReportDocument oRD = new ReportDocument();
   ExportOptions  oExO  ;
   DiskFileDestinationOptions oExDo=new DiskFileDestinationOptions();
   oRD.Load(reportPath);
   //oRD.SetDataSource(myDS);
   oRD.Refresh();
   this.SetConnectionInfo(oRD,passWrd);

   oExDo.DiskFileName = targetFileName ;
   oExO = oRD.ExportOptions;
   oExO.ExportDestinationType = ExportDestinationType.DiskFile;
   switch (docFormat)
   {
    case "pdf":
     oExO.ExportFormatType = ExportFormatType.PortableDocFormat;
     break;
    case "doc":
     oExO.ExportFormatType = ExportFormatType.WordForWindows;
     break;
    case "xls":
     oExO.ExportFormatType = ExportFormatType.Excel;
     break;
    case "htm":
     oExO.ExportFormatType = ExportFormatType.HTML40;
     break;
    case "html":
     oExO.ExportFormatType = ExportFormatType.HTML40;
     break;
    default:oExO.ExportFormatType = ExportFormatType.Excel;break;
   }
   oExO.DestinationOptions = oExDo;
   
   oRD.Export();
   oRD.Close();
  }


  public void ExportCrystalReport(ReportDocument oRD,string docFormat,string targetFileName)
  {
   //ReportDocument oRD = new ReportDocument();
   ExportOptions  oExO  ;
   DiskFileDestinationOptions oExDo=new DiskFileDestinationOptions();
   //   oRD.Load(reportPath);
   //   oRD.SetDataSource(myDS);
   //oRD.Refresh();
   //this.SetConnectionInfo(oRD,passWrd);

   oExDo.DiskFileName = targetFileName ;
   oExO = oRD.ExportOptions;
   oExO.ExportDestinationType = ExportDestinationType.DiskFile;
   switch (docFormat)
   {
    case "pdf":
     oExO.ExportFormatType = ExportFormatType.PortableDocFormat;
     break;
    case "doc":
     oExO.ExportFormatType = ExportFormatType.WordForWindows;
     break;
    case "xls":
     oExO.ExportFormatType = ExportFormatType.Excel;
     break;
    case "htm":
     oExO.ExportFormatType = ExportFormatType.HTML40;
     break;
    case "html":
     oExO.ExportFormatType = ExportFormatType.HTML40;
     break;
    default:oExO.ExportFormatType = ExportFormatType.Excel;break;
   }
   oExO.DestinationOptions = oExDo;
   
   oRD.Export();
   oRD.Close();
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值