WorkbookPart.Workbook.Save() adds x:

Proposed Answer WorkbookPart.Workbook.Save() adds x:

  • mardi 22 mai 2012 15:58
     
      A du code

    I have a slight problem with my application, which is supposed to add definedNames to a spreadsheet. Here's the Code that does the work:

    DefinedNames definedNames = myDocument.WorkbookPart.Workbook.DefinedNames;
     
                    if (!classified)
                    {
                        if (definedNames == null)
                        {
                            //instead of this comment a bunch of DefinedNames are created an appended to definedNames here
                            myDocument.WorkbookPart.Workbook.Append(definedNames);
                        }
                        else
                        {
                            //here i append some definedNames as well
                            myDocument.WorkbookPart.Workbook.DefinedNames.Append(definedName4);
                        }
     
                    }
                    else
                    {
                        foreach (DefinedName dv in definedNames)
                        {
                            //some definedName appending
                        }
                    }
                    myDocument.WorkbookPart.Workbook.Save();

    Before running this code the woorkbook.xml file looks like this

    <?xml version="1.0" encoding="UTF-8" standalone="true"?> -<workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <fileVersion rupBuild="9302" lowestEdited="4" lastEdited="5" appName="xl"/> <workbookPr defaultThemeVersion="124226" filterPrivacy="1"/> -<bookViews> <workbookView activeTab="1" firstSheet="1" windowHeight="8010" windowWidth="14805" yWindow="105" xWindow="240"/> </bookViews> -<sheets> <sheet r:id="rId2" sheetId="1" name="Tabelle1"/>
    <sheet r:id="rId3" sheetId="2" name="Tabelle2"/>
    <sheet r:id="rId4" sheetId="3" name="Tabelle3"/> </sheets> -<definedNames> <definedName>... </definedName> </definedNames><calcPr calcId="122211"/></workbook>

    and afterwards it looks like this:

    <?xml version="1.0" encoding="UTF-8" standalone="true"?> -<x:workbook xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <x:fileVersion rupBuild="9302" lowestEdited="4" lastEdited="5" appName="xl"/><x:workbookPr defaultThemeVersion="124226" filterPrivacy="1"/> -<x:bookViews> <x:workbookView activeTab="1" firstSheet="1" windowHeight="8010" windowWidth="14805" yWindow="105" xWindow="240"/> </x:bookViews> -<x:sheets> <x:sheet r:id="rId2" sheetId="1" name="Tabelle1"/> <x:sheet r:id="rId3" sheetId="2" name="Tabelle2"/> <x:sheet r:id="rId4" sheetId="3" name="Tabelle3"/> </x:sheets> -<x:definedNames> <x:definedName>....</x:definedName> </x:definedNames><x:calcPr calcId="122211"/></x:workbook>

    Another programm is supposed to read those defined names afterwards. But those darn x prevent it from doing so. And those x appear even if no action is performed on the worksheet and only the save() method is called. Is there any way i can prevent save() from adding those x?

    Any Help is apprecheated :)

    Cheers


Toutes les réponses

  • mardi 22 mai 2012 23:08
     
     

    Hi MrTompkins,

    I can't see any different between two xml content which you shown tome. And in you snippet I can't see the place which defined the variable "definedName4". You need clarify it more clearly.

    Best Regards,

    T.X.

  • jeudi 24 mai 2012 13:16
     
     

    Hi T.X.,

    I deleted the parts in the code where definedNames are added, because it doesn't really matter in this case.

    What I'm curious about, is why after save() is called (even if no action is performed on the file), the nodes in the xml-file look like this:

    <x:definedNames> (<x:sheets>, <x:bookViews>,...) instead of this:

    <definedNames> (<sheets>, <bookViews>,....)

    Can anyone tell me what those xs are, why they are added and how i can prevent them from being added?

  • vendredi 3 août 2012 11:39
     
     

    Hi MrTompkins,

    I have the same problem.

    OpenXML creates x: tags, but my third party application does not handle them.

    Did you find a solution in the meantime?

    Regards,

    mr.csharp

  • lundi 6 août 2012 07:55
    Propriétaire
     
     Réponse proposée

    Hello MrTompkins,

    "x" is a prefix of Open XML SpreadsheetML namespace, http://schemas.openxmlformats.org/spreadsheetml/2006/main. Excel can write out a spreadsheet part without the "x:" prefix by setting the namespace as a root namespace of a spreadsheet part. However, Open XML SDK can't set an Open XML namespace as a root of Open XML part, so that use of the SpreadsheetML namespace has to be declared with "x:" prefix at each child tag.

    Accordinly, "x:" can't be suppressed when Excel file is saved/modified by Open XML SDK 2.x. We understand that this limitation affects some Open XML applications in the market, and investigate the resolution for the future major release.

    Regards,
    Kazunori