C# e Crystal Report: esportare in excel e pdf

Un piccolo esempio di come aprire ed esportare un Crystal Report in c#:

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
 
class CrystalUtils
{
 
   public static void Export()
   {
   //Creo l'oggetto report e lo apro
   ReportDocument cryRpt;
   cryRpt = new ReportDocument();
   cryRpt.Load(@"C:\magazzino.rpt");
 
   /*
   Esempio di stampa su console dei parametri e valorizzazione
 
   ParameterFields parametri = cryRpt.ParameterFields;
   foreach (ParameterField parametro in parametri)
   {
   Console.WriteLine("Parametro: " + parametro.Name);
   }
   cryRpt.SetParameterValue(0, "(Tutti)");
   */
 
   //Logon del report su DB
   cryRpt.SetDatabaseLogon("user", "password", "server", "database");
 
   //Export su xls
   cryRpt.ExportToDisk(ExportFormatType.Excel, @"e:\magazzino.xls");
   //Export su pdf
   cryRpt.ExportToDisk(ExportFormatType.PortableDocumentFormat, @"e:\magazzino.pdf");
 
   //Chiudo
   cryRpt.Close();
 
   }
}

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>