开发者

How to create a csv Excel file from content in a gridview in WPF?

开发者 https://www.devze.com 2022-12-24 06:34 出处:网络
I would like to export to a csv file the content of a gridview in WPF. Which is the best and efficient way to do开发者_开发问答 it?Use the FileHelpers component to generate a CSV or simply use a Strin

I would like to export to a csv file the content of a gridview in WPF. Which is the best and efficient way to do开发者_开发问答 it?


Use the FileHelpers component to generate a CSV or simply use a StringBuilder instance to iterate through the contents of the columns in the WPF gridview, in similar pseudocode it would be like this.

StringBuilder sb = new StringBuilder();
foreach row in grid
   foreach col in grid
      sb.Append(col + ", ");
   end foreach
   sb.Append(Environment.NewLine);
end foreach

// Write out the StringBuilder instance to File

The above pseudocode iterates each row and each column, tacking on a delimiter for each column by using a comma.

0

精彩评论

暂无评论...
验证码 换一张
取 消