1

I have DataContext in my windows phone application.

I want to generate a excel spreadsheet or csv file from the dataset.

Is it possible to create a csv or excel spreadsheet from the Windows Phone application ?

WP_Insane
  • 117
  • 1
  • 1
  • 8

1 Answers1

1

A CSV file is simply a text file with fields separated by commas. They can store arbitrary data. You can either use a library to catch edge cases or simply write your values into a text file separated by commas if you want something quick and dirty.

A typical CSV file would look like this:

"Name","Age","Gender"
"Jenny",21,"Female"
"Bloggs, Fred",25,"Male"

Note, that strings are often stored in double-quotes and this is to help with things like "Bloggs, Fred" that contains a comma. This is where using a library comes in handy but you can hand crank yourself if you want.

Re Excel - assuming your CSV was well formed it would open it just fine. That doesn't mean it is an Excel file but just a file that Excel understands. Writing Excel files (depending on version of Excel) is more complicated but possible.

Belogix
  • 8,129
  • 1
  • 27
  • 32
  • Oh. Thank you so much. So I can create the txt file with comma, and should it with .csv extension. Is it right ? – WP_Insane Jul 02 '14 at 04:57
  • For a fairly easy to use example http://stackoverflow.com/questions/2422212/simple-c-sharp-csv-excel-export-class or for an all singing all dancing http://www.codeproject.com/Articles/685310/Simple-and-fast-CSV-library-in-Csharp and of course MANY, MANY other libraries out there. – Belogix Jul 02 '14 at 08:23
  • great that's for win-forms or wpf. any tutorial for windows phone for creating excel spreadsheets ? – WP_Insane Jul 02 '14 at 10:56
  • Phone is exactly the same, don't worry what the examples are written in. You just write to a file (i.e. `TextWriter`) and write lines using commas to separate your fields. You don't need any special software to do it and phone is no different. – Belogix Jul 02 '14 at 12:09