如何制作动态水晶报表?

如何制作动态水晶报表?

创建动态水晶报表的官方 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();
}