Completed
Last Updated: 30 Mar 2017 14:21 by ADMIN
ADMIN
Dinko | Tech Support Engineer
Created on: 27 Dec 2016 11:46
Category: SpreadStreamProcessing
Type: Bug Report
1
SpreadStreamProcessing: Single cell value containing comma or new line is exported to CSV as multiple values because commas ',' and quotes '"' are not escaped
When a cell value contains commas or new lines, they are not escaped on export to CSV and single value is exported as multiple values.

Workaround: Escape the value manually. For example, use the following extension method to set string cell values:
internal static class CellExporterExtensions
{
    public static void SetValue(this ICellExporter cell, string value, SpreadDocumentFormat format)
    {
        if (format == SpreadDocumentFormat.Csv)
        {
            if (value.Contains(","))
            {
                // escape all quotes with double quotes
                value = value.Replace("\"", "\"\"");

            }

            // enclose all values within quotes
            value = string.Format("\"{0}\"", value);
        }

        cell.SetValue(value);
    }
}

Available in LIB version: 2017.1.403
0 comments