The official VB. Net Program cmd.exe for creating dynamic Crystal Reports
Http://blog.csdn.net/haibodotnet/archive/2003/12/11/21546.aspx
Create reports that are not subject to database restrictions
Http://blog.csdn.net/babyt/category/39074.aspx
You can also create some empty formula fields, pre-prevent them on the report, and then dynamically support the formula fields.
Crreportdocument. setdatasource (DS );
Exportoptions crexportoptions; // export options
Diskfiledestinationoptions crdiskfiledestinationoptions;
String fname; // export the complete name
// String filename = "";
String filename = "myfolder ";
String _ systempath = request. physicalapplicationpath;
If (! System. Io. Directory. exists (_ systempath ))
System. Io. Directory. createdirectory (_ systempath );
Fname = _ systempath + filename; // export the complete name
Crdiskfiledestinationoptions = new diskfiledestinationoptions ();
Crdiskfiledestinationoptions. diskfilename = fname;
Crexportoptions = crreportdocument. exportoptions;
Crexportoptions. destinationoptions = crdiskfiledestinationoptions;
Crexportoptions. exportdestinationtype = exportdestinationtype. diskfile;
Crexportoptions. exportformattype = exportformattype. portabledocformat;
Crreportdocument. Export ();
//////////////////////////////
// ================================================ ========================================================== ============
// Print and export the Crystal Report
// ================================================ ========================================================== ============
/// <Summary>
/// Print a crystal report
/// </Summary>
/// <Param name = "reportpath"> report path </param>
/// <Param name = "reportset"> dataset of the report data source </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 ();
}