这是一段silverlight导出Excel的代码 来自zhangfengyi

这是一段silverlight导出Excel的代码 来自zhangfengyi,第1张

概述/// <summary> /// 导出DataGrid数据到Excel         /// </summary>         /// <param name="withHeaders">是否需要表头</param>         /// <param name="grid">DataGrid</param>         /// <returns>Excel内容字符串</return

/// <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所遇到的程序开发问题。

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

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

原文地址:https://www.54852.com/web/1030402.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存