1. Create Report File
2. Open Report Explorer and create a report data source according to the following information
|
|
|
|
|
|
|
|
3. Add Dataset
SELECT TOP 10 Order. Order ID, order. customer ID, order. order date, product. product name, order details. quantity, order details. unit price, order details. discount, order. owner city, order. owner address, order. owner name, order. owner zip code, customer. telephone
FROM (Order INNER JOIN order details ON Order. Order ID=Order Details. Order ID) INNER JOIN product ON Order details. Product ID=Product. Product ID) INNER JOIN customer ON Order.customer ID=Customer.customer ID
ORDER BY Order. Order Date DESC ;
4. Design report interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5. Add report export function
protected void btnExcel_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../ ") + " Reports/ " + report + " .rdlx "));
_reportDef. Report.DataSources[0]. DataSourceReference = Server.MapPath(" ../Data/NWind_CHS_Access.rdsx ");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
XlsExport1.Export(_reportRuntime, ms);
Response.ContentType = " application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.xlsx "));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
protected void btnWord_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../ ") + " Reports/ " + report + " .rdlx "));
_reportDef. Report.DataSources[0]. DataSourceReference = Server.MapPath(" ../Data/NWind_CHS_Access.rdsx ");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Word.Page.Settings s = new GrapeCity.ActiveReports.Export.Word.Page.Settings();
s.UseMhtOutput = true ;
_reportRuntime. Render(_renderingExtension, _provider, s);
Response.ContentType = " application/msword ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.doc "));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider. GetPrimaryStream(). OpenStream(). CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
}
protected void btnPdf_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../ ") + " Reports/ " + report + " .rdlx "));
_reportDef. Report.DataSources[0]. DataSourceReference = Server.MapPath(" ../Data/NWind_CHS_Access.rdsx ");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
_reportRuntime. Render(_renderingExtension, _provider);
Response.ContentType = " application/pdf ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.pdf "));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider. GetPrimaryStream(). OpenStream(). CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
}
protected void btnHtml_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../ ") + " Reports/ " + report + " .rdlx "));
_reportDef. Report.DataSources[0]. DataSourceReference = Server.MapPath(" ../Data/NWind_CHS_Access.rdsx ");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Html.Page.Settings s = new GrapeCity.ActiveReports.Export.Html.Page.Settings();
s.StyleStream = false ;
s.MhtOutput = false ;
s.Fragment = false ;
s.OutputTOC = true ;
s.Mode = GrapeCity.ActiveReports.Export.Html.Page.RenderMode.Paginated;
_reportRuntime. Render(_renderingExtension, _provider, s);
Response.ContentType = " text/html ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.html "));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider. GetPrimaryStream(). OpenStream(). CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
}
protected void btnText_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../ ") + " Reports/ " + report + " .rdlx "));
_reportDef. Report.DataSources[0]. DataSourceReference = Server.MapPath(" ../Data/NWind_CHS_Access.rdsx ");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Xml.Section.TextExport txtExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
txtExport1.Encoding = Encoding.Unicode;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
txtExport1.Export(_reportRuntime, ms);
Response.ContentType = " text/plain ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.txt "));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
protected void btnCSV_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../ ") + " Reports/ " + report + " .rdlx "));
_reportDef. Report.DataSources[0]. DataSourceReference = Server.MapPath(" ../Data/NWind_CHS_Access.rdsx ");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Xml.Section.TextExport csvExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
csvExport1.Encoding = Encoding.Unicode;
csvExport1.TextDelimiter = " \t ";
csvExport1.SuppressEmptyLines = true ;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
csvExport1.Export(_reportRuntime, ms);
Response.ContentType = " text/plain ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.csv "));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
protected void btnExport_Click( object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport( new System.IO.FileInfo(Server. MapPath(" ../Reports/ " + reportname + " .rdlx ")));
report.Report.DataSources[0]. DataSourceReference = "";
report.Report.DataSources[0]. ConnectionProperties.DataProvider = " OLEDB ";
report.Report.DataSources[0]. ConnectionProperties.ConnectString = string .Format(" Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; ", Server.MapPath(" ../Data/NWind_CHS.mdb "));
GrapeCity.ActiveReports.Document.PageDocument document = new GrapeCity.ActiveReports.Document.PageDocument(report);
GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
switch (C1Tabs1.Selected)
{
case 0:
break ;
case 1:
pdfExport1.Security.Encrypt = true ;
pdfExport1.Security.Use128Bit = true ;
if (txtPwd.Text.Length > 0)
pdfExport1.Security.UserPassword = txtPwd.Text;
pdfExport1.Security.Permissions = GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.None;
if (chkCopy.Checked)
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowCopy;
if (chkEidt1.Checked)
{
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowFillIn;
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowModifyAnnotations;
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowModifyContents;
}
if (chkPrint.Checked)
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowPrint;
break ;
case 2:
// ImageText signature.
pdfExport1.Signature.VisibilityType = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.VisibilityType.ImageText;
// Bounds (Container of Text & Image).
pdfExport1.Signature.Stamp.Bounds = new RectangleF(0, 0, 4, 1);
// Text area.
pdfExport1.Signature.Stamp.TextAlignment = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.Alignment.Left;
pdfExport1.Signature.Stamp.Font = new Font(" Comic Sans MS ", 8, FontStyle.Regular);
// Note: Specify (x, y) in relative coordinate from Bounds top-left.
pdfExport1.Signature.Stamp.TextRectangle = new RectangleF(1, 0, 3, 1);
// Image area.
pdfExport1.Signature.Stamp.Image = System.Drawing.Image.FromFile(Server. MapPath(" ../Resources/Grapecity_powertools_bg.png "));
pdfExport1.Signature.Stamp.ImageAlignment = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.Alignment.Center;
// Note: Specify (x, y) in relative coordinate from Bounds top-left.
pdfExport1.Signature.Stamp.ImageRectangle = new RectangleF(0, 0, 1, 1);
// Set certificate & password.
pdfExport1.Signature.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Server. MapPath(" ../Resources/ActiveReports6.pfx "), " one hundred and twenty-three thousand four hundred and fifty-six ");
// set the certifiation level
if (chkEidt2.Checked)
pdfExport1.Signature.CertificationLevel = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.CertificationLevel.FormFillingAnnotations;
else
pdfExport1.Signature.CertificationLevel = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.CertificationLevel.NoChangesAllowed;
//Signature items.
pdfExport1.Signature.Contact = new GrapeCity.ActiveReports.Export.Pdf.Section.Signing.SignatureField< string >(txtEmail.Text, true );
if (chkDate.Checked)
pdfExport1.Signature.SignDate = new GrapeCity.ActiveReports.Export.Pdf.Section.Signing.SignatureField<System.DateTime>(System. DateTime.Now, true );
break ;
default :
break ;
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
pdfExport1.Export(document,ms);
Response.ContentType = " application/pdf ";
Response.AddHeader(" content-disposition ", Server.UrlPathEncode(" Attachment; filename=Customer Order.pdf "));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
Online demonstration and source code download address: