export to excel - Exporting WPF DataGrid to a text file in a nice looking format. Text file must be easy to read -


Is there an easy way to export a text file and a WPF DataGrid into a .csv file? I have searched something and can not see that there is a simple DataGrid method to do this. I'm getting some work using the DataGrid's item source (hardly) in my case, it's an array of strokes. I have to do something with StreamWriters and StringBuilders (details available) and basically:

  StringBuilder Destination = New StringBuilder (); Destination.Append (row.CreationDate); Destination.Append (separator); // Separator is '\ t' or ',' for the CSV file destination. Append (row.ProcId); Destination.Append (separator); Destination.Append (row.PartNumber); Destination.Append (separator);  

I do this for each straight array (in a loop). The problem is that the text file is not easy to read. The data can be of different lengths within the same column. I like to watch something: 2007-03-03 234238423823 823829923 2007-03-03 66 99 And of course, I get something: 2007-03-03 234238423823 823829923 2007-03-03 66 99

It is not surprising that I am using tab delimiter, but I hope to do better. It's definitely easy to read in DataGrid! I can certainly do some arguments for pad short value with space, but it is very dirty. I thought that there could be a better way, I also feel that this is a common problem and that has probably been resolved before (hopefully NAT classes itself).

Thank you.

I think the target is likely to be in the form of WYSIWYG. In that situation I would:

  1. Loop through all the datagreaders, and [every] one for each. Prepare a string with data displayed in each data gridale. It is easy for most datagrid column types. For DataGridTemplateColumn you will need to use binding, then convert. Toaster ().
  2. I keep track of the maximum string loops in each column as I did.

The next step depends on the export type:

  • For a CSV export, I will put all the strings [strings] in each string after the quotation marks I would like to write them by adding them to the middle coma. / Li>
  • For plain text export, I add each string [] with an empty space in each string + 1 + The maximum string length of that column and how to write them.

The reason for using real datagridos, data gridels, and datagrid column objects is that the end user sees. For example, you can skip hidden columns, apply string formatting in binding, filtering / grouping / sorting etc.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -