在实际工作中,当需要进行大批量查询和生成报表的时候,可以使用我写的类。

特点:

  • 无需报表设计器、无需为报表设置数据集
  • 只需要传入查询结果就可以全自动生成报表,传入的对象为Dynamic(目前支持DataTable和IEnumable<T>的传入参数)
  • 文字、数据表可以无限添加
  • 支持图表 ( 2014-5-28 v0.4 增加参数类,完成图表显示功能)
  • 支持数据分组(2014-5-19 v0.3 添加表格内分组)

我没有采用使用操纵微软报表Schema的方法,而是用了拼接字符串:(

将来想到的扩展功能有:

  • 支持子报表

更新日志:

2014-5-15 更新,将匿名类转换成DataTable,然后去除0和0.00%等字段。

* 2014-5-19 v0.3 添加表格内分组
 * 2014-5-28 v0.4 增加参数类,开始做图表显示功能

源码:

接口:

using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using Microsoft.Reporting.WebForms; public interface IDynamicReport
{
void SetReport(ReportViewer reportViewer);
void AddData<T>(IEnumerable<T> data);
void AddData(DataTable dataTable);
void ShowReport();
void LoadReport(string reportPath);
void SetColoumStyle(List<ReportColoumStyle> coloumStyle);
void AddText(string title);
}

辅助类和枚举:

    public class ReportColoumStyle
{
public string ColoumName { get; set; }
public float ColoumWidth { get; set; }
public TextAlign TextAlign { get; set; } public ReportColoumStyle()
{
ColoumWidth = DynamicReport.ColoumWidth;
}
} public enum TextAlign
{
Left,
Center,
Right
} public enum ReportType
{
Tables,
Chart,
Finally
} internal enum DataType
{
DataTable,
Enumerable
} internal class ReportItemPattern
{
public string DataSetName { get; set; }
public string DataSetString { get; set; }
public string TablixString { get; set; }
public dynamic Data { get; set; } public string DataSetPattern
{
get
{
return " <DataSet Name=\"@DataSetNameData\">" +
" <Fields>@Fields</Fields>" +
" <Query>" +
" <DataSourceName>DummyDataSource</DataSourceName>" +
" <CommandText />" +
" </Query>" +
" </DataSet>";
}
} public string TablixPattern
{
get
{
return " <Tablix Name=\"Tablix@DataSetName\">" +
" <TablixBody>" +
" <TablixColumns>@TablixColumns</TablixColumns>" +
" <TablixRows>" +
" <TablixRow>" +
" <Height>0.23622in</Height>" +
" <TablixCells>@TablixHeader</TablixCells>" +
" </TablixRow>" +
" <TablixRow>" +
" <Height>0.23622in</Height>" +
" <TablixCells>@TablixCells</TablixCells>" +
" </TablixRow>" +
" </TablixRows>" +
" </TablixBody>" +
" <TablixColumnHierarchy>" +
" <TablixMembers>@TablixMember</TablixMembers>" +
" </TablixColumnHierarchy>" +
" <TablixRowHierarchy>" +
" <TablixMembers>" +
" <TablixMember>" +
" <KeepWithGroup>After</KeepWithGroup>" +
" </TablixMember>" +
" <TablixMember>" +
" <Group Name=\"详细信息@DataSetName\" />" +
" </TablixMember>" +
" </TablixMembers>" +
" </TablixRowHierarchy>" +
" <DataSetName>@DataSetNameData</DataSetName>" +
" <Top>@TopPositioncm</Top>" +
" <Left>@LeftPostioncm</Left>" +
" <Height>1.2cm</Height>" +
" <Width>14.35207cm</Width>" +
" <Style>" +
" <Border>" +
" <Style>None</Style>" +
" </Border>" +
" </Style>" +
"</Tablix>";
}
}
} internal static class DynamicReportExtension
{
public static dynamic RemoveZeroData(this object data)
{
if (data is DataTable)
{
return ((DataTable)data).ChangeEachColumnTypeToString();
}
else if (data is IEnumerable)
{
var _data = ((IEnumerable) data).Cast<object>();
return _data.CopyToDataTable().RemoveZeroData();
}
return data;
} public static DataTable ChangeEachColumnTypeToString(this DataTable dt)
{
DataTable tempdt = new DataTable();
foreach (DataColumn dc in dt.Columns)
{
DataColumn tempdc = new DataColumn(); tempdc.ColumnName = dc.ColumnName;
tempdc.DataType = typeof (String);
tempdt.Columns.Add(tempdc);
}
int coloumCount = dt.Columns.Count;
foreach (DataRow dr in dt.Rows)
{
var newrow = tempdt.NewRow(); for (int i = ; i < coloumCount; i ++)
{
var value = dr[i].ToString();
switch (value)
{
case "":
case "0.00%":
newrow[i] = "-";
break;
default:
newrow[i] = value;
break;
} }
tempdt.Rows.Add(newrow);
}
return tempdt;
}
} internal static class DataSetLinqOperators
{
public static DataTable CopyToDataTable<T>(this IEnumerable<T> source)
{
return new ObjectShredder<T>().Shred(source, null, null);
} public static DataTable CopyToDataTable<T>(this IEnumerable<T> source,
DataTable table, LoadOption? options)
{
return new ObjectShredder<T>().Shred(source, table, options);
} } internal class ObjectShredder<T>
{
private FieldInfo[] _fi;
private PropertyInfo[] _pi;
private Dictionary<string, int> _ordinalMap;
private Type _type; public ObjectShredder()
{
_type = typeof (T);
_fi = _type.GetFields();
_pi = _type.GetProperties();
_ordinalMap = new Dictionary<string, int>();
} public DataTable Shred(IEnumerable<T> source, DataTable table, LoadOption ? options)
{
if (typeof (T).IsPrimitive)
{
return ShredPrimitive(source, table, options);
} if (table == null)
{
table = new DataTable(typeof (T).Name);
} // now see if need to extend datatable base on the type T + build ordinal map
table = ExtendTable(table, typeof (T)); table.BeginLoadData();
using (IEnumerator<T> e = source.GetEnumerator())
{
while (e.MoveNext())
{
if (options != null)
{
table.LoadDataRow(ShredObject(table, e.Current), (LoadOption) options);
}
else
{
table.LoadDataRow(ShredObject(table, e.Current), true);
}
}
}
table.EndLoadData();
return table;
} public DataTable ShredPrimitive(IEnumerable<T> source, DataTable table, LoadOption ? options)
{
if (table == null)
{
table = new DataTable(typeof (T).Name);
} if (!table.Columns.Contains("Value"))
{
table.Columns.Add("Value", typeof (T));
} table.BeginLoadData();
using (IEnumerator<T> e = source.GetEnumerator())
{
Object[] values = new object[table.Columns.Count];
while (e.MoveNext())
{
values[table.Columns["Value"].Ordinal] = e.Current; if (options != null)
{
table.LoadDataRow(values, (LoadOption) options);
}
else
{
table.LoadDataRow(values, true);
}
}
}
table.EndLoadData();
return table;
} public DataTable ExtendTable(DataTable table, Type type)
{
// value is type derived T, may need to extend table.
foreach (FieldInfo f in type.GetFields())
{
if (!_ordinalMap.ContainsKey(f.Name))
{
DataColumn dc = table.Columns.Contains(f.Name) ?
table.Columns[f.Name]
:
table.Columns.Add(f.Name, f.FieldType);
_ordinalMap.Add(f.Name, dc.Ordinal);
}
}
foreach (PropertyInfo p in type.GetProperties())
{
if (!_ordinalMap.ContainsKey(p.Name))
{
DataColumn dc = table.Columns.Contains(p.Name) ?
table.Columns[p.Name]
:
table.Columns.Add(p.Name, p.PropertyType);
_ordinalMap.Add(p.Name, dc.Ordinal);
}
}
return table;
} public object[] ShredObject(DataTable table, T instance)
{ FieldInfo[] fi = _fi;
PropertyInfo[] pi = _pi; if (instance.GetType() != typeof (T))
{
ExtendTable(table, instance.GetType());
fi = instance.GetType().GetFields();
pi = instance.GetType().GetProperties();
} Object[] values = new object[table.Columns.Count];
foreach (FieldInfo f in fi)
{
values[_ordinalMap[f.Name]] = f.GetValue(instance);
} foreach (PropertyInfo p in pi)
{
values[_ordinalMap[p.Name]] = p.GetValue(instance, null);
}
return values;
}
}

核心类:

    public class DynamicReport : IDynamicReport
{
#region 空白文档 /// <summary>
/// 空白文档的xml文件
/// </summary>
protected string _docTemplate =
"<?xml version=\"1.0\" encoding=\"utf-8\"?><Report xmlns:rd=\"http://schemas.microsoft.com/SQLServer/reporting/reportdesigner\" xmlns=\"http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition\">" +
"<DataSources>" +
" <DataSource Name=\"DummyDataSource\">" +
" <ConnectionProperties>" +
" <DataProvider>SQL</DataProvider>" +
" <ConnectString />" +
" </ConnectionProperties>" +
" <rd:DataSourceID>3eecdab9-6b4b-4836-ad62-95e4aee65ea8</rd:DataSourceID>" +
" </DataSource>" +
"</DataSources>" +
"<DataSets>@DataSets</DataSets>" +
"<Body>" +
"<ReportItems>@Title@Tablix" +
"</ReportItems>" +
"<Style />" +
"<Height>8cm</Height>" +
"</Body>" +
"<Width>17cm</Width>" +
"<Page>" +
"<PageHeight>29.7cm</PageHeight>" +
"<PageWidth>21cm</PageWidth>" +
"<LeftMargin>1.8cm</LeftMargin>" +
"<RightMargin>1.8cm</RightMargin>" +
"<TopMargin>1.8cm</TopMargin>" +
"<BottomMargin>1.8cm</BottomMargin>" +
"<ColumnSpacing>0.13cm</ColumnSpacing>" +
"<Style />" +
"</Page>" +
"<rd:ReportID>809f16cf-ea78-4469-bf43-965c4afe69d0</rd:ReportID>" +
"<rd:ReportUnitType>Cm</rd:ReportUnitType>" +
"</Report>"; protected string TitlePattern =
" <Textbox Name=\"Textbo@TextboxName\"> "
+ @"<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>@Title</Value>
<Style>@FontStyle</Style>
</TextRun>
</TextRuns>
<Style>@Style</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbo@TextboxName</rd:DefaultName>
<Top>@TopPositioncm</Top>
<Left>1cm</Left>
<Height>0.83813cm</Height>
<Width>14.35207cm</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>"; #endregion private ReportViewer _report;
private List<ReportColoumStyle> _coloumStyle = new List<ReportColoumStyle>();
private List<ReportItemPattern> _reportItemPatterns = new List<ReportItemPattern>();
private List<string> _reportTitlePatterns = new List<string>();
private List<ReportItemPattern> _reportHeadPatterns = new List<ReportItemPattern>();
internal const float ColoumWidth = 1.6F; //行宽
public ReportType ReportType { get; set; } public DynamicReport()
{ } /// <summary>
/// 从现有报表中加载报表并进行修改
/// </summary>
/// <param name="url"></param>
public void LoadReport(string url)
{
try
{
_docTemplate = File.ReadAllText(url);
}
catch (Exception ex)
{ }
} public void SetReport(ReportViewer reportViewer)
{
this._report = reportViewer;
} public void SetColoumStyle(List<ReportColoumStyle> coloumStyle)
{
this._coloumStyle = coloumStyle;
} public void AddText(string text)
{
if (!string.IsNullOrEmpty(text))
{
var pos = CaculatePlacePostion();
var titlePattern = TitlePattern
.Replace("@Title", text)
.Replace("@TopPosition", pos.ToString())
.Replace("@TextboxName", _reportTitlePatterns.Count.ToString())
.Replace("@FontStyle", "<FontFamily>微软雅黑</FontFamily><FontSize>12pt</FontSize>")
.Replace("@Style", "<TextAlign>Center</TextAlign>");
_reportTitlePatterns.Add(titlePattern);
}
} public void AddText(string text, int chapterGrade)
{
if (!string.IsNullOrEmpty(text))
{
var pos = CaculatePlacePostion();
var titlePattern = TitlePattern
.Replace("@Title", text)
.Replace("@TopPosition", pos.ToString())
.Replace("@TextboxName", _reportTitlePatterns.Count.ToString());
switch (chapterGrade)
{
case :
titlePattern = titlePattern.Replace("@FontStyle",
"<FontFamily>宋体</FontFamily><FontSize>18pt</FontSize><Color>#000000</Color>")
.Replace("@Style", "<TextAlign>Center</TextAlign>");
break;
case :
titlePattern = titlePattern.Replace("@FontStyle",
"<FontFamily>黑体</FontFamily><FontSize>14pt</FontSize><Color>#000000</Color>")
.Replace("@Style", "<TextAlign>Left</TextAlign>");
break;
case :
titlePattern = titlePattern.Replace("@FontStyle",
"<FontFamily>宋体</FontFamily><FontSize>12pt</FontSize><FontWeight>Bold</FontWeight>")
.Replace("@Style", "<TextAlign>Left</TextAlign>");
break;
default:
case :
titlePattern = titlePattern.Replace("@FontStyle",
"<FontFamily>宋体</FontFamily><FontSize>12pt</FontSize>")
.Replace("@Style", "<LineHeight>22pt</LineHeight>");
break;
}
_reportTitlePatterns.Add(titlePattern);
}
} public void AddData<T>(IEnumerable<T> data)
{
if (data.Count() != )
{
var properites = typeof (T).GetProperties(); //得到实体类属性的集合
AddReportItemPattern(properites.Select(p => p.Name).ToArray(), data);
}
} public void AddData(DataTable dataTable)
{
if (dataTable != null)
{
var coloumNames = new List<string>();
foreach (DataColumn dataColumn in dataTable.Columns)
{
var protertyName = dataColumn.ColumnName;
coloumNames.Add(protertyName);
}
AddReportItemPattern(coloumNames.ToArray(), dataTable);
}
} /// <summary>
/// 计算开始摆放的位置
/// </summary>
/// <returns></returns>
protected float CaculatePlacePostion()
{
//每个标题的高度
float titleCount = _reportTitlePatterns.Count*1f;
//每个数据表的高度
float itemCount = _reportItemPatterns.Count*2f;
// 每个空表头的高度
float emptyItemCount = _reportHeadPatterns.Count*0.5f;
switch (ReportType)
{
case ReportType.Tables:
return titleCount + itemCount + emptyItemCount + 0.5f;
case ReportType.Chart:
case ReportType.Finally:
return titleCount + itemCount + emptyItemCount + 25.7f;
}
return 0f;
} /// <summary>
/// 增加一个报表
/// </summary>
/// <param name="coloumNames"></param>
/// <param name="data"></param>
/// <param name="dataType"></param>
protected void AddReportItemPattern(string[] coloumNames, dynamic data)
{
var fields = new StringBuilder();
var coloums = new StringBuilder();
var tablixHearders = new StringBuilder();
var tablixCells = new StringBuilder();
var tablixMembers = new StringBuilder();
var currentNamePrefix = _reportItemPatterns.Count + _reportHeadPatterns.Count + ;
var tableWidth = 0F;
var dataRows = GetDataRowsCount(data); //数据行数 foreach (var coloumName in coloumNames)
{
var coloumWidth = ColoumWidth;
var textAlign = TextAlign.Right;
var reportColoumStyle = _coloumStyle.FirstOrDefault(r => r.ColoumName == coloumName);
if (reportColoumStyle != null)
{
textAlign = reportColoumStyle.TextAlign;
coloumWidth = reportColoumStyle.ColoumWidth;
}
tableWidth += coloumWidth; var bottomBorder = string.Empty; //每个单元格底部border
if (dataRows == )
{
bottomBorder = "<BottomBorder><Style>None</Style></BottomBorder>";
}
var coloumValue = coloumName;
//例外,如果coloumName包含Coloum之类的字段,则将value设成空
if (coloumName.IndexOf("Column", System.StringComparison.Ordinal) > -)
{
coloumValue = " ";
} fields.AppendFormat(
"<Field Name=\"{0}\"><DataField>{0}</DataField><rd:TypeName>System.String</rd:TypeName></Field>",
coloumName);
coloums.AppendFormat("<TablixColumn><Width>{0}cm</Width></TablixColumn>", coloumWidth);
tablixHearders.AppendFormat("<TablixCell><CellContents>" +
"<Textbox Name=\"Textbox{0}{1}\"><CanGrow>true</CanGrow><KeepTogether>true</KeepTogether><Paragraphs><Paragraph>" +
"<TextRuns><TextRun><Value>{2}</Value><Style /></TextRun></TextRuns><Style><TextAlign>Center</TextAlign></Style></Paragraph></Paragraphs>" +
"<rd:DefaultName>Textbox{0}{1}</rd:DefaultName><Style><Border><Color>LightGrey</Color><Style>Solid</Style></Border>{3}" +
"<PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight><PaddingTop>2pt</PaddingTop><PaddingBottom>2pt</PaddingBottom></Style></Textbox></CellContents></TablixCell>",
coloumName, currentNamePrefix, coloumValue, bottomBorder);
tablixCells.AppendFormat(
"<TablixCell><CellContents><Textbox Name=\"{0}{1}1\"><CanGrow>true</CanGrow><KeepTogether>true</KeepTogether>" +
"<Paragraphs><Paragraph><TextRuns><TextRun><Value>=Fields!{0}.Value</Value><Style /></TextRun></TextRuns><Style><TextAlign>{2}</TextAlign></Style></Paragraph></Paragraphs>" +
"<rd:DefaultName>{0}{1}1</rd:DefaultName><Style><Border><Color>LightGrey</Color><Style>Solid</Style></Border>" +
"<PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight><PaddingTop>2pt</PaddingTop><PaddingBottom>2pt</PaddingBottom></Style></Textbox></CellContents></TablixCell>",
coloumName, currentNamePrefix, textAlign); tablixMembers.AppendFormat("<TablixMember />");
} //计算表格应该离左边多少距离
var leftPosition = 0F;
if (tableWidth < )
{
leftPosition = (17F - tableWidth)/;
} var dataSetName = string.Format("Data{0}", _reportItemPatterns.Count + _reportHeadPatterns.Count + );
var reportItemPattern = new ReportItemPattern();
reportItemPattern.Data = DynamicReportExtension.RemoveZeroData(data);
reportItemPattern.DataSetName = dataSetName;
reportItemPattern.DataSetString =
reportItemPattern.DataSetPattern
.Replace("@DataSetName", dataSetName)
.Replace("@Fields", fields.ToString());
reportItemPattern.TablixString =
reportItemPattern.TablixPattern
.Replace("@DataSetName", dataSetName)
.Replace("@TablixColumns", coloums.ToString())
.Replace("@TablixHeader", tablixHearders.ToString())
.Replace("@TablixCells", tablixCells.ToString())
.Replace("@TablixMember", tablixMembers.ToString())
.Replace("@TopPosition", CaculatePlacePostion().ToString())
.Replace("@LeftPostion", leftPosition.ToString()); //读取行数,如果是空行就加到新的
if (dataRows == )
{
_reportHeadPatterns.Add(reportItemPattern);
}
else
{
_reportItemPatterns.Add(reportItemPattern);
}
} /// <summary>
/// 得到某种类型数据的数量
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private int GetDataRowsCount(dynamic data)
{
if (data is DataTable)
{
return ((DataTable) data).Rows.Count;
}
else if (data is IEnumerable)
{
return Enumerable.Count(data);
}
else return ;
} /// <summary>
/// 最终显示报表
/// </summary>
public void ShowReport()
{
//将每一个patter转换
if (_reportItemPatterns.Count > || _reportTitlePatterns.Count > )
{
var dataSetsString = new StringBuilder();
var tablixString = new StringBuilder(); foreach (var reportItemPattern in _reportItemPatterns)
{
dataSetsString.Append(reportItemPattern.DataSetString);
tablixString.Append(reportItemPattern.TablixString);
}
foreach (var reportItemPattern in _reportHeadPatterns)
{
dataSetsString.Append(reportItemPattern.DataSetString);
tablixString.Append(reportItemPattern.TablixString);
} var reportTitleString = new StringBuilder();
foreach (var reportTitlePattern in _reportTitlePatterns)
{
reportTitleString.Append(reportTitlePattern);
} //把文档中的文字替换掉
switch (ReportType)
{
case ReportType.Tables:
_docTemplate = _docTemplate.Replace("@DataSets", dataSetsString.ToString())
.Replace("@Tablix", tablixString.ToString())
.Replace("@Title", reportTitleString.ToString());
break;
case ReportType.Chart:
break;
case ReportType.Finally:
//替换datasetstring
var pos = _docTemplate.IndexOf("<Body>", StringComparison.Ordinal);
_docTemplate = _docTemplate.Insert(pos,
string.Format(
"<DataSources><DataSource Name=\"DummyDataSource\"><ConnectionProperties><DataProvider>SQL</DataProvider><ConnectString /></ConnectionProperties><rd:DataSourceID>3eecdab9-6b4b-4836-ad62-95e4aee65ea8</rd:DataSourceID></DataSource></DataSources><DataSets>{0}</DataSets>",
dataSetsString));
//替换Tablix
pos = _docTemplate.IndexOf("<ReportItems>", StringComparison.Ordinal);
_docTemplate = _docTemplate.Insert(pos + , tablixString.ToString());
//替换title
_docTemplate = _docTemplate.Insert(pos + , reportTitleString.ToString());
break;
} var doc = new XmlDocument();
doc.LoadXml(_docTemplate);
Stream stream = GetRdlcStream(doc); //加载报表定义
_report.LocalReport.LoadReportDefinition(stream);
_report.LocalReport.DataSources.Clear();
foreach (var reportItemPattern in _reportItemPatterns)
{
_report.LocalReport.DataSources
.Add(new ReportDataSource(reportItemPattern.DataSetName + "Data",
reportItemPattern.Data));
}
foreach (var reportItemPattern in _reportHeadPatterns)
{
_report.LocalReport.DataSources
.Add(new ReportDataSource(reportItemPattern.DataSetName + "Data",
reportItemPattern.Data));
} _report.LocalReport.Refresh();
}
} /// <summary>
/// 序列化到内存流
/// </summary>
/// <returns></returns>
protected Stream GetRdlcStream(XmlDocument xmlDoc)
{
Stream ms = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(typeof (XmlDocument));
serializer.Serialize(ms, xmlDoc); ms.Position = ;
return ms;
}
}

调用方法一(使用内置的空报表模板):

                //new一个报表类对象
var dynamicReport = new DynamicReport {ReportType = ReportType.Tables};
//设置报表为本地报表
dynamicReport.SetReport(this.ReportViewer1);
//设置列宽度和对齐方式(可选)
dynamicReport.SetColoumStyle(new List<ReportColoumStyle>()
{
new ReportColoumStyle(){ColoumName = "专业名称", ColoumWidth = 4F},
new ReportColoumStyle() {ColoumName = "学院", ColoumWidth = 3.5F},
new ReportColoumStyle(){ColoumName = "就业去向", ColoumWidth = 4F},
});
//加入标题
dynamicReport.AddText(module.ModuleName);
//加入数据
dynamicReport.AddData(data);
//设置导出报表的名称
ReportViewer1.LocalReport.DisplayName = module.ModuleName;
//处理报表数据并显示
dynamicReport.ShowReport();

调用方法二(载入已有的报表,并且添加相关数据):

                //new一个报表类对象
var dynamicReport = new DynamicReport ();
dynamicReport.ReportType = ReportType.Finally;
//读取报表模板(模板内不能有其他数据源等)
dynamicReport.LoadReport(Server.MapPath("~/ChapterReport/ReportView.rdlc"));
//设置报表为本地报表
dynamicReport.SetReport(this.ReportViewer1);
//设置列宽度和对齐方式(可选)
dynamicReport.SetColoumStyle(new List<ReportColoumStyle>()
{
new ReportColoumStyle(){ColoumName = "专业名称", ColoumWidth = 4F},
new ReportColoumStyle() {ColoumName = "学院", ColoumWidth = 3.5F},
new ReportColoumStyle(){ColoumName = "就业去向", ColoumWidth = 4F},
});
//加入标题
dynamicReport.AddText(module.ModuleName);
//加入数据
dynamicReport.AddData(data); //加入其它标题
dynamicReport.AddTitle("其它文字", );
//加入其它数据
dynamicReport.AddData(data2); ................ //设置导出报表的名称
ReportViewer1.LocalReport.DisplayName = "......";
//处理报表数据并显示
dynamicReport.ShowReport();

分享一个动态生成RDLC报表的类的更多相关文章

  1. 动态生成RDLC报表

    前段时间,做了RDLC报表,主要是三块功能: 1.从DataGrid提取(包括最新的增删改)的数据,自动生成对应的RDLC报表文件(以流的形式驻存在内存中),用ReportViewer类来展示.打印. ...

  2. delphi中将一个ADOQuery查询的数据结果传递给一个动态生成的ADOQuery

    delphi中将一个ADOQuery查询的数据结果传递给一个动态生成的ADOQuery 2010-03-10 17:35 方法一: beginADOQuery:=TADOQuery.Create(Ap ...

  3. 讨论一下hibernate如何动态注册一个动态生成的实体类

    如何动态生成实体类请参考这篇博文:http://www.cnblogs.com/anai/p/4269858.html 下面说说得到实体类后,如何能使用hibernate的接口来进行数据访问. 我们都 ...

  4. 根据html页面模板动态生成html页面(c#类)

    本文转载自:http://www.cnblogs.com/yuanbao/archive/2008/01/06/1027985.html点击打开链接 一直以为动态生成静态页面不好做,昨天在网上找了下, ...

  5. 分享一个在线生成微信跳转链接实现微信内跳转浏览器打开URL的工具

    前言 现如今微信对第三方推广链接的审核是越来越严格了,域名在微信中分享转发经常会被拦截,一旦被拦截用户就只能复制链接手动打开浏览器粘贴才能访问,要不然就是换个域名再推,周而复始.无论是哪一种情况都会面 ...

  6. 分享一个在线生成站点地图SiteMap制作工具

    站点地图SiteMap的好处是很大的,对Seo很有好处,能够更方便.迅速的让搜索引擎收录.WordPress 有不少生成Google Sitemap 的工具,但是有些只是针对WordPress的系统的 ...

  7. 分享一个关于jackson的Json工具类

    直接贴代码: import org.codehaus.jackson.map.DeserializationConfig.Feature; import org.codehaus.jackson.ma ...

  8. [转]简单的动态修改RDLC报表页边距和列宽的方法

    本文转自:http://star704983.blog.163.com/blog/static/136661264201161604413204/ 1.修改页边距 XmlDocument XMLDoc ...

  9. 分享一个js生成二维码的库

    二维码用js生成会比用服务器生成方便很多,只要把window.location.href的值传入,即可生成对应的二维码..最主要是,这个库可以兼容ie6~ie9哦... 具体使用,请看官网:http: ...

随机推荐

  1. Sublime Text 2配置文件详解

    Sublime Text 2是那种让人会一眼就爱上的编辑器,不仅GUI让人眼前一亮,功能更是没的说,拓展性目前来说也完全够用了,网上介绍软件的文章和推荐插件的文章也不少,而且很不错,大家可以去找找自己 ...

  2. *HDU 2108 计算几何

    Shape of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. log4j.properties 使用

    一.参数意义说明 输出级别的种类 ERROR.WARN.INFO.DEBUG ERROR 为严重错误 主要是程序的错误 WARN 为一般警告,比如session丢失 INFO 为一般要显示的信息,比如 ...

  4. 读取config配置

    在搭建自动化测试框架时,经常会使用config.properties文件存储配置,文件内容格式如下: 读取config.properties文件代码如下: public class Putils { ...

  5. 阿里云服务器Linux CentOS安装配置(六)resin多端口配置、安装、部署

    阿里云服务器Linux CentOS安装配置(六)resin多端口配置.安装.部署 1.下载resin包 http://125.39.66.162/files/2183000003E08525/cau ...

  6. OpenGL函数思考-glLoadIdentity

    函数原型: void glLoadIdentity(void) 函数说明: OpenGL为我们提供了一个非常简单的恢复初始坐标系的手段,那就是调用glLoadIdentity()命令.该命令是一个无参 ...

  7. hadoop2.7下载mirror

    http://mirror.bit.edu.cn/apache/hadoop/common/

  8. [dpdk] 熟悉SDK与初步使用 (二)(skeleton源码分析)

    接续前节:[dpdk] 熟悉SDK与初步使用 (一)(qemu搭建实验环境) 程序逻辑: 运行参数: 关键API: 入口函数: int rte_eal_init(int argc, char **ar ...

  9. Arduino.h

    #ifndef Arduino_h #define Arduino_h #include <stdlib.h> #include <stdbool.h> #include &l ...

  10. scala中的Actor

    1.介绍 2.简单示例 3.第二个程序 4.通信程序 package day01 import scala.actors.Actor case class Message(content: Strin ...