请用以下代码覆盖 Export.aspx.cs 文件中的代码:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Text;
- namespace ControlExplorer.Viewers
- {
- public partial class Export : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- string viewtype = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("viewtype").Value;
- switch (viewtype.ToLower())
- {
- case "htmlviewer":
- this.WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.HtmlViewer;
- this.WebViewer1.HtmlExportOptions.IncludePageMargins = true;
- break;
- case "rawhtml":
- this.WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.RawHtml;
- break;
- case "acrobatreader":
- this.WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.AcrobatReader;
- break;
- case "flashviewer":
- this.WebViewer1.FlashViewerOptions.ResourceLocale = "zh_CN";
- this.WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.FlashViewer;
- break;
- default:
- break;
- }
- LoadReport(report);
- C1Dialog1.ContentUrl = string.Format("ImageExportSetting.aspx?category={0}&action={1}", categoryid, actionid);
- }
- }
- protected override void OnInit(EventArgs e)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string height = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("height").Value;
- this.WebViewer1.Height = Unit.Pixel(Convert.ToInt32(height));
- base.OnInit(e);
- }
- private void LoadReport(string report)
- {
- switch (report)
- {
- case "rptInvoice":
- GrapeCity.ActiveReports.PageReport report1 = null;
- report1 = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../Reports/" + report + ".rdlx")));
- report1.Report.DataSources[0].DataSourceReference = "";
- report1.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- report1.Report.DataSources[0].ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("../Data/NWind_CHS.mdb"));
- WebViewer1.Report = report1;
- break;
- default:
- break;
- }
- }
- protected void btnExcel_Click(object sender, EventArgs e)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
- _reportDef.Report.DataSources[0].DataSourceReference = "";
- _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- _reportDef.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 _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=客户订单.xlsx"));
- Response.BinaryWrite(ms.ToArray());
- Response.End();
- }
- protected void btnWord_Click(object sender, EventArgs e)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
- _reportDef.Report.DataSources[0].DataSourceReference = "";
- _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- _reportDef.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 _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=客户订单.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)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
- _reportDef.Report.DataSources[0].DataSourceReference = "";
- _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- _reportDef.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 _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=客户订单.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)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
- _reportDef.Report.DataSources[0].DataSourceReference = "";
- _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- _reportDef.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 _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=客户订单.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)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
- _reportDef.Report.DataSources[0].DataSourceReference = "";
- _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- _reportDef.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 _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=客户订单.txt"));
- Response.BinaryWrite(ms.ToArray());
- Response.End();
- }
- protected void btnCSV_Click(object sender, EventArgs e)
- {
- System.Xml.Linq.XElement xEle;
- if (Cache["ControlList"] == null)
- {
- xEle = System.Xml.Linq.XElement.Load(Server.MapPath("~/ControlList.xml"));
- Cache["ControlList"] = xEle;
- }
- else
- {
- xEle = (System.Xml.Linq.XElement)Cache["ControlList"];
- }
- string categoryid = Request.QueryString["category"];
- string actionid = Request.QueryString["action"];
- string report = xEle.Elements("Control").Where(c => c.Attribute("id").Value == categoryid).First().Elements("action").Where(a => a.Attribute("id").Value == actionid).First().Attribute("report").Value;
- GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
- _reportDef.Report.DataSources[0].DataSourceReference = "";
- _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- _reportDef.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 _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=客户订单.csv"));
- Response.BinaryWrite(ms.ToArray());
- Response.End();
- }
- protected void btnImage_Click(object sender, EventArgs e)
- {
- }
- }
- }
复制代码 |