A good way to export a datagridview to excel table

The original code is in the url here. And I have change some of the code to get it run.

And I'm suprised by the way the guy using the LINQ.

And I'm thinking of learning more about LINQ someday.

            var lines = new List<string>();
            var valueLines = this.changeTable.AsEnumerable()
                   .Select(row => string.Join(",", row.ItemArray.AsEnumerable().Select(obj => obj.ToString()).ToArray()));
            lines.AddRange(valueLines);
            File.WriteAllLines(sfd.FileName, lines.ToArray());

 

posted on 2013-06-14 01:15  很遗憾我不是  阅读(214)  评论(0编辑  收藏  举报