none
Embedded Excel spreadsheet in Word Document - cannot update data RRS feed

  • Discussion générale

  • Hi,

    I developed an application to automatically update an embedded Excel Spreadsheet in a Word document using Open XML SDK 2.0.

    The problem is I cannot update the “Word view” of the embedded spreadsheet.

    I need double click on the embedded Excel spreadsheet to update the “Word view” in order  to have the changed values reflected correctly.

    I presume is the same situation as in the case of embedded charts in a Word document.

    I can easily update the Excel spread sheet of the embedded chart , but to reflect this update in the “Word view” of the chart I have to update also the cache of the chart (in Open XML I use chartSpace class – XML node <c:chartSpace>)

    The code to update the "Word view" of the embedded chart looks like this:

    /////////////////////

               DocumentFormat.OpenXml.Drawing.Charts.Chart chart = this.chartPart.ChartSpace.Elements<DocumentFormat.OpenXml.Drawing.Charts.Chart>().FirstOrDefault();

                try

                {

                    if (null != chart)

                    {

                        PlotArea plotArea = chart.Elements<PlotArea>().FirstOrDefault();

                        if (null != plotArea)

                        {

                            foreach (LineChart lc in plotArea.Elements<LineChart>())

                            {

                                if (lc != null)

                                {

                                    foreach (LineChartSeries lcs in lc.Elements<LineChartSeries>())

                                    {

                                        if (lcs != null)

                                        {

                                            try

                                            {

                                                SeriesText seriesTextLcs = lcs

                                                            .Elements<DocumentFormat.OpenXml.Drawing.Charts.SeriesText>()

                                                            .FirstOrDefault();

                                                if (null != seriesTextLcs)

                                                {

                                                    StringReference strRefLcs = seriesTextLcs

                                                                .Elements<DocumentFormat.OpenXml.Drawing.Charts.StringReference>()

                                                                .FirstOrDefault();

                                                    if (null != strRefLcs)

                                                    {

                                                        /*..........*/

                                                    }

                                                }

                                            }

                                            catch (Exception ex)

                                            {

                                            }

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

                finally

                {

                    try

                    {

                        if (null != this.chartPart)

                            this.chartPart.ChartSpace.Save();

                    }

                    catch (Exception ex)

                    {

                    }

                }

    /////////////////////

    So my question is: does Open XML have a similar class to update the cache of the embedded Excel spreadsheet, without manual intervention?

    Or probably there is another technique which I could use?

    Thanks in advance.


    • Modifié bio74 lundi 8 avril 2013 10:10
    • Type modifié Aurel Bera vendredi 12 avril 2013 06:37 Discussion
    dimanche 7 avril 2013 05:27

Toutes les réponses