Question

I have found several threads on people wishing to REMOVE quotes from their CSV file, but not adding them. And the ones I have found about adding quotes have not helped my case.

I'm using Microsoft.Office.Interop.Excel and am creating a CSV file that will be read by a program that oddly enough requires each field to be in double quotes. However when I write to a cell using, for example:

xlSheet.Cells[1,1] = "\"" + id + "\"";

my output is """id"""

Is there any fix for this? My client also wishes to be able to open the file in Excel, hence my use of Microsoft.Office.Interop

Was it helpful?

Solution

You dont really have to write to the file using Microsoft.Office.Interop.Excel instead just write to a file using a StreamWriter with the name of the file as Your_File.csv. And still u can open this CSV file using Excel. Remember to use proper delimiters in the CSV file. Hope this helps.

OTHER TIPS

Excel may be interpreting your "id" value as a literal string rather than a number, then adding additional quotes to it when it converts it to CSV.

Rather than adding quotes, store the value as a string instead of a number:

xlSheet.Cells[1,1] = id.ToString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top