为什么我的 Excel RDLC 数据中的所有数据都从第 2 行开始?
Why does all data in my Excel RDLC data start at row 2?
使用 RDLC 生成的 Excel 报告的 header 列似乎总是从第 2 行开始。但是,我需要从第一行开始的数据,但我似乎无法弄明白。
我的问题:
有没有办法强制 data-rows 从第一行开始?
呈现的报告如下所示:
如您所见,数据从第 2 行开始...
我的报告设计器看起来像:
如您所见,header 列位于设计器的顶部,下面列出了字段。当然,Title和Image在该区域之上,与数据结果查看区域无关。
我的初始代码如下所示:
我可以 post 更多代码。但是,这是唯一特定于 "Local Drivers Report" 导出的部分。
public ActionResult Export(string id)
{
var format = !string.IsNullOrEmpty(id) ? id : SsrsExportFormat.Image.ToString();
var localDrivers = from x in LocalDriverInfo
select new
{
Title = x.Title.TranslatedName,
x.Driver.ConfirmedWith,
x.Driver.CurrentState,
x.Driver.Description,
x.Driver.DesiredState,
x.Driver.LocalDriverId,
x.Driver.LocalDriverTitleId
};
var lsDs = new List<ReportDataSource> { ReportGenerator.GetDataSource(localDrivers, "LocalDrivers"), ReportGenerator.GetDataSource(GetReportResource(), "Resource") };
var lsDsResult = lsDs.ToList();
var message = string.Format("Controller: LocalDrivers, Action: Export(id), "
+ "Parameters: [id: {0}, lsDs count: {1}, format: {2}]"
, id, lsDsResult.Count, format);
TraceHandler.AddEntry(message, TraceHandler.TraceTypes.Information);
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
return GetRenderedReport(format, "~/Reports/LocalDrivers/LocalDrivers.rdlc", lsDs, "Local Drivers", ReportGenerator.GetDeviceInfoLetterLandscape(format), null);
}
确保 table 的顶部和左侧绝对没有白色 space。任何白色 space 都会创建额外的行。
事实证明,设备信息设置是这个特定问题的答案。
设备信息 XML 应该如下所示:
DeviceInfo 在创建 'local report'.
时被传递到 ServerReport.Render method
<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>
代码看起来像:
注意最后附加的行...
var deviceInfo = new StringBuilder();
deviceInfo.Append("<DeviceInfo>");
deviceInfo.AppendFormat("<OutputFormat>{0}</OutputFormat>", format);
deviceInfo.AppendFormat("<PageWidth>{0}</PageWidth>", pageWidth);
deviceInfo.AppendFormat("<PageHeight>{0}</PageHeight>", pageHeight);
deviceInfo.AppendFormat("<MarginTop>{0}</MarginTop>", marginTop);
deviceInfo.AppendFormat("<MarginLeft>{0}</MarginLeft>", marginLeft);
deviceInfo.AppendFormat("<MarginRight>{0}</MarginRight>", marginRight);
deviceInfo.AppendFormat("<MarginBottom>{0}</MarginBottom>", marginBottom);
deviceInfo.AppendFormat("<SimplePageHeaders>{0}</SimplePageHeaders>", isSimplePageHeaders);
deviceInfo.Append("</DeviceInfo>");
使用 RDLC 生成的 Excel 报告的 header 列似乎总是从第 2 行开始。但是,我需要从第一行开始的数据,但我似乎无法弄明白。
我的问题:
有没有办法强制 data-rows 从第一行开始?
呈现的报告如下所示:
如您所见,数据从第 2 行开始...
我的报告设计器看起来像:
如您所见,header 列位于设计器的顶部,下面列出了字段。当然,Title和Image在该区域之上,与数据结果查看区域无关。
我的初始代码如下所示:
我可以 post 更多代码。但是,这是唯一特定于 "Local Drivers Report" 导出的部分。
public ActionResult Export(string id)
{
var format = !string.IsNullOrEmpty(id) ? id : SsrsExportFormat.Image.ToString();
var localDrivers = from x in LocalDriverInfo
select new
{
Title = x.Title.TranslatedName,
x.Driver.ConfirmedWith,
x.Driver.CurrentState,
x.Driver.Description,
x.Driver.DesiredState,
x.Driver.LocalDriverId,
x.Driver.LocalDriverTitleId
};
var lsDs = new List<ReportDataSource> { ReportGenerator.GetDataSource(localDrivers, "LocalDrivers"), ReportGenerator.GetDataSource(GetReportResource(), "Resource") };
var lsDsResult = lsDs.ToList();
var message = string.Format("Controller: LocalDrivers, Action: Export(id), "
+ "Parameters: [id: {0}, lsDs count: {1}, format: {2}]"
, id, lsDsResult.Count, format);
TraceHandler.AddEntry(message, TraceHandler.TraceTypes.Information);
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
return GetRenderedReport(format, "~/Reports/LocalDrivers/LocalDrivers.rdlc", lsDs, "Local Drivers", ReportGenerator.GetDeviceInfoLetterLandscape(format), null);
}
确保 table 的顶部和左侧绝对没有白色 space。任何白色 space 都会创建额外的行。
事实证明,设备信息设置是这个特定问题的答案。
设备信息 XML 应该如下所示:
DeviceInfo 在创建 'local report'.
<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>
代码看起来像:
注意最后附加的行...
var deviceInfo = new StringBuilder();
deviceInfo.Append("<DeviceInfo>");
deviceInfo.AppendFormat("<OutputFormat>{0}</OutputFormat>", format);
deviceInfo.AppendFormat("<PageWidth>{0}</PageWidth>", pageWidth);
deviceInfo.AppendFormat("<PageHeight>{0}</PageHeight>", pageHeight);
deviceInfo.AppendFormat("<MarginTop>{0}</MarginTop>", marginTop);
deviceInfo.AppendFormat("<MarginLeft>{0}</MarginLeft>", marginLeft);
deviceInfo.AppendFormat("<MarginRight>{0}</MarginRight>", marginRight);
deviceInfo.AppendFormat("<MarginBottom>{0}</MarginBottom>", marginBottom);
deviceInfo.AppendFormat("<SimplePageHeaders>{0}</SimplePageHeaders>", isSimplePageHeaders);
deviceInfo.Append("</DeviceInfo>");