本帖最后由 lihuioooo 于 2016-8-10 10:58 编辑
尝试了, 报错
这个过程是在 报表数据填充后执行的转换,然后报错
/// <summary>
/// 导出为pdf
/// </summary>
/// <param name="pg"></param>
private void ExportToPdf(PageReport pg)
{
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\Demo");
outputDirectory.Create();
// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = pdfSetting;
try
{
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
_pageDocument.Render(pdfRenderingExtension, outputProvider, pdfSetting);
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.pdf"));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
throw;
}
//Set the rendering extension and render the report.
}
private void Cah020_LocateDataSource2(object sender, LocateDataSourceEventArgs args)
{
string sql = "";
string where = "";
if (args.Report.PageReport.Report.DataSets.Count > 0)
{
sql = args.Report.PageReport.Report.DataSets[0].Query.CommandText;//获取报表的sql 语句
}
for (int i = 0; i < args.Report.Parameters.Count; i++)
{
if (args.Report.Parameters.Name.ToLower() == "sql")
{
where = args.Report.Parameters.CurrentValue == null ? "" : args.Report.Parameters.CurrentValue.ToString();
break;
}
}
CYW.Hotel.IBLL.IGetDataForReport data = new CYW.Hotel.BLL.GetReportData();
DataTable tab = data.GetSelectReportDatas(sql);
args.Data = tab;
ExportToPdf(definition);
}
我如果想不存文件, 直接把报表处理为流入库呢? 以上是我的代码实现
|