1,添加导出和打印按钮
<StackPanel OrIEntation="Horizontal" GrID.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" margin="20,0">
<@R_404_5554@ x:name="Export@R_404_5554@" Content="导出" Click="Export@R_404_5554@_Click"/>
<@R_404_5554@ x:name="Print@R_404_5554@" Content="打印" Click="Export@R_404_5554@_Click"/>
</StackPanel>
2,定义
private RadGrIDVIEw grID = new RadGrIDVIEw();
private GrIDVIEwExportoptions options = new GrIDVIEwExportoptions();
3,初始化
grID.autoGenerateColumns = false;
options.ShowColumnheaders = true;
options.Format = ExportFormat.HTML;
options.EnCoding = System.Text.EnCoding.UTF8;
4,利用Telerik的RadGrIDVIEw进行导出
public T_Bas_EnterList Model { get { return this.DataContext as T_Bas_EnterList; } }
private voID Export@R_404_5554@_Click(object sender,RoutedEventArgs e) { SavefileDialog dialog = new SavefileDialog(); dialog.DefaultExt = "doc"; dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*","doc","Word"); dialog.FilterIndex = 1; if (dialog.ShowDialog() == true) { using (Stream stream = dialog.Openfile()) { if (Model != null) { grID.ItemsSource = new List<T_Bas_EnterList>() { Model }; grID.Columns.Add(new GrIDVIEwDataColumn() { header = "企业详细信息",DataMemberBinding = new System.windows.Data.Binding("entername") }); } grID.Export(stream,options); } } } voID DataGrIDVIEw_ElementExported(object sender,GrIDVIEwElementExportedEventArgs e) { if (e.Element == ExportElement.Row) { if (Model != null) { e.Writer.Write(String.Format(@"<tr><td background-color:#CCC;"" colspan=""{0}"">", ((IEnumerable<Telerik.windows.Controls.GrIDVIEwColumn>)((RadGrIDVIEw)sender).Columns).Count())); e.Writer.Write("<h2>基本信息</h2>"); e.Writer.Write(String.Format(@"<b>污染源:</b> {0} <br />",Model.code_pollute)); e.Writer.Write(String.Format(@"<b>企业名称:</b> {0} <br />",Model.entername)); e.Writer.Write(String.Format(@"<b>企业类型:</b> {0} <br />",Model.code_enterrelation)); e.Writer.Write(String.Format(@"<b>企业类型:</b> {0} <br />",Model.code_qualification)); e.Writer.Write(String.Format(@"<b>企业类型:</b> {0} <br />",Model.code_enterrelation)); e.Writer.Write("<h2>监测数据</h2>"); MemoryStream memoryStream = new MemoryStream(); DataGrIDVIEw.Export(memoryStream,options); memoryStream.Flush(); e.Writer.Write(System.Text.EnCoding.UTF8.GetChars(memoryStream.ToArray())); e.Writer.Write("</td></tr>"); } } } 总结以上是内存溢出为你收集整理的Silverlight 利用Telerik导出到Word全部内容,希望文章能够帮你解决Silverlight 利用Telerik导出到Word所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)