Dynamic CRYSTAL REPORT

Source: Internet
Author: User

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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.