我有以下代码:
private void CreateExcel(string fileName)
{
var operationDate = System.DateTime.ParseExact(txtStartDate.Text, "dd/MMM/yyyy", CultureInfo.CurrentCulture);
var ds1 = new _spAvailabilityEventDailyReport1TableAdapter();
var ds2 = new _spAvailabilityEventDailyReport2TableAdapter();
var ds3 = new _spAvailabilityEventDailyReport3TableAdapter();
var ds4 = new _spAvailabilityEventTotalTableAdapter();
var ds5 = new _spAvailabilityNoteDailyReportTableAdapter();
var ds6 = new _spAvailabilityDailyReportTableAdapter();
var ds7 = new _spAvailabilityReadingTotalTableAdapter();
var ds8 = new _spAvailabilityEventSum1TableAdapter();
var ds9 = new _spAvailabilityEventSum2TableAdapter();
var ds10 = new _spAvailabilityEventSum3TableAdapter();
//default margin setting
string outputType = "Excel";
string pageHeight = "11.69in";
string pageWidth = "8.27in";
string marginTop = "0.3937in";
string marginBottom = "0.3937in";
string marginLeft = "0.3937in";
string marginRight = "0.3937in";
string reportPath = Server.MapPath("~/rdlc/dailyavailability.rdlc");
try
{
//search setting margin report & kind output export -> for parameter 2nd render RDLC
var xml = System.IO.File.ReadAllText(reportPath);
var matches = Regex.Matches(xml, @"<(?<property>PageHeight|PageWidth|TopMargin|BottomMargin|LeftMargin|RightMargin)>(?<value>[^<]+)</\k<property>>", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
if (!match.Success)
continue;
switch (match.Groups["property"].Value)
{
case "PageHeight":
pageHeight = match.Groups["value"].Value;
break;
case "PageWidth":
pageWidth = match.Groups["value"].Value;
break;
case "TopMargin":
marginTop = match.Groups["value"].Value;
break;
case "BottomMargin":
marginBottom = match.Groups["value"].Value;
break;
case "LeftMargin":
marginLeft = match.Groups["value"].Value;
break;
case "RightMargin":
marginRight = match.Groups["value"].Value;
break;
}
}
}
catch (System.Exception) { }
string reportType = string.IsNullOrEmpty(outputType) ? "Excel" : outputType.Trim().ToUpper();
string encoding;
string deviceInfo = string.Format(@"<DeviceInfo>
<OutputFormat>{6}</OutputFormat>
<PageWidth>{0}</PageWidth>
<PageHeight>{1}</PageHeight>
<MarginTop>{2}</MarginTop>
<MarginLeft>{3}</MarginLeft>
<MarginBottom>{4}</MarginBottom>
<MarginRight>{5}</MarginRight>
</DeviceInfo>", pageWidth, pageHeight, marginTop, marginLeft, marginBottom, marginRight, reportType);
var rds = new ReportDataSource("dsAvailabilityEventDailyReport1", (DataTable)ds1.GetData(operationDate)); //fill data report in parameter
var rds2 = new ReportDataSource("dsAvailabilityEventDailyReport2", (DataTable)ds2.GetData(operationDate)); //fill data report in parameter
var rds3 = new ReportDataSource("dsAvailabilityEventDailyReport3", (DataTable)ds3.GetData(operationDate)); //fill data report in parameter
var rds4 = new ReportDataSource("dsAvailabilityEventTotal", (DataTable)ds4.GetData(operationDate)); //fill data report in parameter
var rds5 = new ReportDataSource("dsAvailabilityNoteDailyReport", (DataTable)ds5.GetData(operationDate)); ///fill data report in parameter
var rds6 = new ReportDataSource("dsAvailabilityDailyReport", (DataTable)ds6.GetData(operationDate)); //fill data report in parameter
var rds7 = new ReportDataSource("dsAvailabilityReadingTotal", (DataTable)ds7.GetData(operationDate)); //fill data report in parameter
var rds8 = new ReportDataSource("dsAvailabilityEventSum1", (DataTable)ds8.GetData(operationDate)); //fill data report in parameter
var rds9 = new ReportDataSource("dsAvailabilityEventSum2", (DataTable)ds9.GetData(operationDate)); //fill data report in parameter
var rds10 = new ReportDataSource("dsAvailabilityEventSum3", (DataTable)ds10.GetData(operationDate)); //fill data report in parameter
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string extension = string.Empty;
// Setup the report viewer object and get the array of bytes
var report = new LocalReport();
report.ReportPath = reportPath;
report.DataSources.Add(rds); // Add datasource here
report.DataSources.Add(rds2); // Add datasource here
report.DataSources.Add(rds3); // Add datasource here
report.DataSources.Add(rds4); // Add datasource here
report.DataSources.Add(rds5); // Add datasource here
report.DataSources.Add(rds6); // Add datasource here
report.DataSources.Add(rds7); // Add datasource here
report.DataSources.Add(rds8); // Add datasource here
report.DataSources.Add(rds9); // Add datasource here
report.DataSources.Add(rds10); // Add datasource here
//set parameter report (jika ada)
report.SetParameters(new List<ReportParameter>
{
//new ReportParameter("FacilitySubClassID", facilitySubClassId.ToString()),
new ReportParameter("OperationDate", operationDate.ToString())
});
byte[] bytes = report.Render(reportType, deviceInfo, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "." + extension + "\"");
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
}
我有一份关于我的rdlc报告的子报告,当我试图将它导出到excel时。错误消息显示在Excel文件(子报告部分)上。
"Data retrieval failed for the subreport, 'srAvailabilityList', located at: C:\Users\xxxxx\Documents\Visual Studio 2010\Projects\coco\rdlc\availabilityreading.rdlc. Please check the log files for more information."
子报告正在使用ds6
和ds7
。
我的问题是:
如何检索子报告中的数据?
我在哪里可以找到日志文件?
谢谢。
答案 0 :(得分:1)
找到答案:
void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
var operationDate = System.DateTime.ParseExact(txtStartDate.Text, "dd/MMM/yyyy", CultureInfo.CurrentCulture);
var ds6 = new _spAvailabilityDailyReportTableAdapter();
var ds7 = new _spAvailabilityReadingTotalTableAdapter();
var rds6 = new ReportDataSource("dsAvailabilityDailyReport", (DataTable)ds6.GetData(operationDate)); //isi data report di parameter kedua
var rds7 = new ReportDataSource("dsAvailabilityReadingTotal", (DataTable)ds7.GetData(operationDate)); //isi data report di parameter kedua
e.DataSources.Add(rds6);
e.DataSources.Add(rds7);
}
然后在report.SetParameter
之前添加此代码:
report.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportEventHandler);
谢谢。