RadControls for Silverlight 导出excel

RadControls for Silverlight 导出excel,第1张

概述As of Q1 2010 (version number 2010.1.0309+), RadGridView has a new method - Export which gives you more control over which elements are included in the exported data. It is the preferred method of exp

As of Q1 2010 (version number 2010.1.0309+),RadGrIDVIEw has a new method - Export which gives you more control over which elements are included in the exported data.

It is the preferred method of exporting data. The method expects two parameters:

1. Stream - usually the file stream which you are exporting data to.

2. GrIDVIEwExportoptions or GrIDVIEwCsvexportoptions object - use it to set the following export options:

Format - the possible formats are defined in the ExportFormat enumeration: Csv,ExcelML,HTML or Text EnCoding - the possible values are EnCoding.Unicode,EnCoding.UTF8,etc. ShowColumnheaders - determines whether to export the column headers ShowColumnFooters - determines whether to export the column footers ShowGroupFooters - determines whether to export the group footers ColumnDelimiter - determines the string that will separate the cells of the exported data. Default is comma ",". Available in GrIDVIEwCsvexportoptions only. RowDelimiter - determines the string that will separate the rows of the exported data. Default is new line. Available in GrIDVIEwCsvexportoptions only. UseSystemCultureSeparator - if set,the RadGrIDVIEw will use the system List Separator string,specifIEd in Control Panel's Regional Options,to separate cells. This property overrIDes the ColumnDelimiter property. Available in GrIDVIEwCsvexportoptions only.

The following example shows how to show a save file dialog asking the user to save the file in excel format:

copy
C#
public MainPage(){ InitializeComponent(); btnExport.Click += new RoutedEventHandler(btnExport_Click); }voID btnExport_Click(object sender,RoutedEventArgs e){ string extension = "xls"; SavefileDialog dialog = new SavefileDialog() {  DefaultExt = extension,Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*",extension,"Excel"),FilterIndex = 1 }; if (dialog.ShowDialog() == true) {  using (Stream stream = dialog.Openfile())  {   grIDVIEwExport.Export(stream,new GrIDVIEwExportoptions()    {     Format = ExportFormat.HTML,ShowColumnheaders = true,ShowColumnFooters = true,ShowGroupFooters = false,});  } }}

 

copy
VB.NET
Public Sub New() InitializeComponent() AddHandler btnExport.Click,AddressOf btnExport_ClickEnd SubPrivate Sub btnExport_Click(sender As Object,e As RoutedEventArgs) Dim extension As String = "xls" Dim dialog As New SavefileDialog() With { _  .DefaultExt = extension,_  .Filter = [String].Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*",_  .FilterIndex = 1 _ }If dialog.ShowDialog() = True Then  Using stream As Stream = dialog.Openfile()   grIDVIEwExport.Export(stream,New GrIDVIEwExportoptions() With { _    .Format = ExportFormat.HTML,_    .ShowColumnheaders = True,_    .ShowColumnFooters = True,_    .ShowGroupFooters = False _   })  End Using End IfEnd Sub

 

In addition, RadGrIDVIEw provIDes a built-in methods to get the content of your grID vIEw control in different formats:

Text - each row is exported on new line (\r\n) with values separated by tabs (\t). In order to export to this format use the ToText() method. CSV - each row is exported on new line (\r\n) with values surrounded by quotation marks and separated by commas. In order to export to this format use the ToCsv() method. HTML - the content of the RadGrIDVIEw is exported in standard HTML table. In order to export to this format use the ToHTML() method. ExcelML - the content of the RadGrIDVIEw is exported to Excel XML format. In order to export to this format use the ToExcelML() method.

Note

The export methods (ToHTML(),ToCsv(),ToText() and ToExcelML()) are implemented in the class ExportExtension as extension methods to the standard RadGrIDVIEw control. In order to see and call these methods you have to import the Telerik.windows.Controls namespace.

copy
C#
using Telerik.windows.Controls;...string HTMLExport = this.ExportGrID.ToHTML( true );

copy
VB.NET
imports Telerik.windows.Controls...Dim HTMLExport As String = Me.ExportGrID.ToHTML( True )

引用:

http://www.telerik.com/help/silverlight/gridview-export.html

总结

以上是内存溢出为你收集整理的RadControls for Silverlight 导出excel全部内容,希望文章能够帮你解决RadControls for Silverlight 导出excel所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1067528.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存