
/// <summary> /// 导出DataGrID数据到Excel @H_502_18@ /// </summary> @H_502_18@ /// <param name="withheaders">是否需要表头</param> @H_502_18@ /// <param name="grID">DataGrID</param> @H_502_18@ /// <returns>Excel内容字符串</returns> @H_502_18@ public static string ExportDataGrID(bool withheaders,DataGrID grID)@H_502_18@ {@H_502_18@ string colPath; System.Reflection.PropertyInfo propInfo;@H_502_18@ System.windows.Data.Binding binding;@H_502_18@ System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();@H_502_18@ System.Collections.IList source = (grID.ItemsSource as System.Collections.IList);@H_502_18@ if (source == null) return "";@H_502_18@ List<string> headers = new List<string>();@H_502_18@ grID.Columns.ToList().ForEach(col =>@H_502_18@ {@H_502_18@ if (col is DataGrIDBoundColumn)@H_502_18@ { headers.Add(FormatCSVFIEld(col.header.ToString())); }@H_502_18@ });@H_502_18@ strBuilder.Append(String.Join(",",headers.ToArray())).Append("/r/n");@H_502_18@ foreach (Object data in source)@H_502_18@ {@H_502_18@ List<string> csvRow = new List<string>();@H_502_18@ foreach (DataGrIDColumn col in grID.Columns)@H_502_18@ {@H_502_18@ if (col is DataGrIDBoundColumn)@H_502_18@ {@H_502_18@ binding = (col as DataGrIDBoundColumn).Binding;@H_502_18@ colPath = binding.Path.Path;@H_502_18@ propInfo = data.GetType().GetProperty(colPath);@H_502_18@ if (propInfo != null)@H_502_18@ {@H_502_18@ csvRow.Add(FormatCSVFIEld(propInfo.GetValue(data,null).ToString()));@H_502_18@ }@H_502_18@ }@H_502_18@ }@H_502_18@ strBuilder.Append(String.Join(",csvRow.ToArray())).Append("/r/n");@H_502_18@ }@H_502_18@ return strBuilder.ToString(); }
总结以上是内存溢出为你收集整理的这是一段silverlight导出Excel的代码 来自zhangfengyi全部内容,希望文章能够帮你解决这是一段silverlight导出Excel的代码 来自zhangfengyi所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)