【发布时间】:2013-12-20 19:33:47
【问题描述】:
我正在使用下面的代码将简单的报告呈现到 Excel 或 PDF,它在 PDF 中运行良好,但是在 Excel 中,如果 dtTable 的行数超过 64K,则会出现错误。我正在使用 Microsoft 发布的 ReportDefinition 以允许从 DataTable 动态创建 rdlc,可从此处获得 http://www.gotreportviewer.com/
有人知道如何设置报告生成器以将电子表格分成每 64K 行的新标签页吗?
var localReport = new LocalReport();
var availableFields = new List<string>();
for (var i = 0; i < dtTable.Columns.Count; i++)
{
if (dtTable.Columns[i].ColumnName != "RowID")
availableFields.Add(dtTable.Columns[i].ColumnName);
}
MemoryStream m_rdl = new MemoryStream();
RdlGenerator gen = new RdlGenerator();
gen.AllFields = availableFields;
gen.SelectedFields = availableFields;
gen.WriteXml(m_rdl);
m_rdl.Position = 0;
localReport.LoadReportDefinition(m_rdl);
ReportDataSource reportDataSource = new ReportDataSource("MyData", dtTable);
localReport.DataSources.Add(reportDataSource);
string reportType = "Excel";
string encoding;
string fileNameExtension;
string mimeType;
string deviceInfo = "<DeviceInfo><OutputFormat>Excel</OutputFormat></DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes;
renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
【问题讨论】: