我使用下面的代码将简单的报告呈现为 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);
最佳答案
要将每 64K 行放入一个单独的工作表中,请根据行号在报表中创建分页符。
How to Export Data in Excel of SSRS Report if data exceeds greater than 65k
Export to EXCEL error in SSRS 2005
发生此错误的原因是报表查看器控件使用旧的 BIFF Excel 格式,每个工作表仅处理 65536 行。
关于c# - 本地报告至 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20710740/