This is a migrated thread and some comments may be shown as answers.

Export ExcelML with unparsed character data (CDATA)

1 Answer 27 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hector Hernandez
Top achievements
Rank 1
Hector Hernandez asked on 24 Nov 2011, 11:55 AM
Hello there

I am using the following code to export a RadGridView into ExcelML format.
private void Test(object sender, System.Windows.RoutedEventArgs e)
{
    ExportFormat format = ExportFormat.ExcelML;
    string extension = "xml";
 
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = extension;
    dialog.Filter = string.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "ExcelML");
    dialog.FilterIndex = 1;
 
    if (dialog.ShowDialog() == true)
    {
        using (Stream stream = dialog.OpenFile())
        {
            GridViewExportOptions exportOptions = new GridViewExportOptions();
            exportOptions.Format = format;
            exportOptions.ShowColumnHeaders = true;
            exportOptions.Culture = new System.Globalization.CultureInfo("en-US");
            exportOptions.Encoding = System.Text.Encoding.UTF8;
 
            Grid.Export(stream, exportOptions);
        }
    }
}

This code is generating a nice ExcelML format. But here is my issue.
Some of the columns inside my RadGridView contain illegal XML characters. These get exported "as they are" into the xml which in turn makes the Excel parser to fail in execution.

This could be fixed if I could set the value of the column in export to something like
<![CDATA[ value of my column ]]>
In this way if the value of my column contains characters such as < > or & those wont be parsed by EXCEL.

Is there a way of adding these specs to the column to export?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Hector Hernandez
Top achievements
Rank 1
answered on 24 Nov 2011, 12:12 PM
I have been trying and found this approach ... it is working so far
if (e.Element == ExportElement.Cell)
{
    e.Value = string.Format("<![CDATA[{0}]]>", e.Value);
}

Is there any other approach? like setting this through xaml? or in the GridViewExportOptions object?

Anything?
Tags
GridView
Asked by
Hector Hernandez
Top achievements
Rank 1
Answers by
Hector Hernandez
Top achievements
Rank 1
Share this question
or