I need to save table to CSV file. Each cell of table could contains strings with characters like: " , ; ' and new lines.
How to convert those strings to valid CSV fields that could be opened in Excel?
A CSV file must contain every column for all attributes of its object type. If the attribute value is not required, a column must exist with the attribute name and a comma for any blank attribute values. If a column is defined as optional, it means that the column is required to exist, but the value can be blank.
To preserve all the digits in text-formatted numbers, you have to import the downloaded CSV file as raw data into a new Excel spreadsheet, set the column datatypes as needed, and then save the new file as an Excel workbook. Excel (XLSX) files will preserve these formats, CSV files won't.
It should be as simple as this:
csvCell = "\"" + cell.Replace("\"", "\"\"") + "\"";
This wraps the cell text in "double quotes" and escapes "double quotes" inside the cell with double "double quotes".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With