简体   繁体   English

Excel将字段添加到Xml映射

[英]Excel Add A Field To An Xml Map

I've a XML map on an Excel 2010 worksheet, that I refresh from the contents of an XML file on a regular basis. 我在Excel 2010工作表上有一个XML映射,我会定期刷新XML文件的内容。 I recently added a new field to the XML data and wish this to show up on my XML map. 我最近为XML数据添加了一个新字段,并希望它显示在我的XML映射上。

I simply want to be able to add the new field however it appears although ill have to import the whole structure again, I dont want to do this as it will require redeveloping alot of custom formating. 我只是希望能够添加新字段,但它看起来虽然不得不再次导入整个结构,我不想这样做,因为它将需要重新开发很多自定义格式。

Any help appreciated. 任何帮助赞赏。

Unfortunately there is no easy "refresh" method for schema in the XML object model in Excel at the moment. 遗憾的是,目前Excel中的XML对象模型中没有简单的“刷新”方法。 The XML Toolbox for Excel 2003 used to be able to do this, but I am not sure if this still runs in Excel 2010 (worth a try). XML Toolbox for Excel 2003曾经能够做到这一点,但我不确定它是否仍然在Excel 2010中运行(值得一试)。 Alternative to this is to write your own VBA code which would import your "new" schema into a new map, and then look at the existing element maps for the "old" schema and then remap these to the "new" schema, finally deleting the "old" one. 替代方法是编写自己的VBA代码,将“新”模式导入新映射,然后查看“旧”模式的现有元素映射,然后将这些映射重新映射到“新”模式,最后删除“老”的。 Sounds a bit hairy I know, but if your schema doesn't change significantly then it could be the answer. 我知道听起来有点毛茸茸,但如果你的架构没有明显变化,那么它可能就是答案。

There is a less graceful method than this, which involves changing the schema in the workbook's underlying XML directly. 有一个不太优雅的方法,这涉及直接更改工作簿的基础XML中的模式。 If have a look inside the workbook structure under the xl folder, you will see that there is a file named xmlMaps.xml and inside this file will be a copy of your schema - you can then edit this directly (add new elements etc.) and the new fields will then show up for use in your workbook when you open it again in Excel, leaving your original cell formatting unchanged. 如果查看xl文件夹下的工作簿结构,您将看到有一个名为xmlMaps.xml的文件,并且该文件中将包含您的模式的副本 - 您可以直接编辑它(添加新元素等)然后,当您在Excel中再次打开它时,新字段将显示在工作簿中使用,保持原始单元格格式不变。

我将xlsx解压缩为zip并能够手动进行更改,而无需按照此站点上的说明再次删除和添加映射: http//davidovitz.blogspot.com/2010/05/howto-refresh-xml -schema功能于excel.html

This isn't exactly what the OP asked for, but it worked in my case, so I am adding it as a probable solution (using Office 2013) 这不是OP要求的,但它在我的情况下有效,所以我将其添加为可能的解决方案(使用Office 2013)

  1. Right click in your ribbon and Enable Developer Tools 右键单击功能区并启用开发人员工具

在此输入图像描述

  1. Go to the new Developer Tools section on your ribbon and click Source 转到功能区上的新“开发人员工具”部分,然后单击“ 源”

在此输入图像描述

  1. This will open a righthand side flyout. 这将打开一个右侧弹出。 Elements in bold are currently mapped to your columns. 粗体元素当前映射到您的列。 Note where things map to by clicking on them. 注意事物通过点击它们映射到哪里。 In my case it was pretty straightforward with the first element mapping to column A, etc. Then right click on anything in bold and unmap it. 在我的情况下,第一个元素映射到A列等是非常简单的。然后右键单击任何粗体并取消映射。

在此输入图像描述

  1. Click the XML Maps button at bottom of flyout 单击弹出窗口底部的“ XML地图”按钮

  2. Click Add and navigate to a file or enter a URL 单击“ 添加”并导航到文件或输入URL

在此输入图像描述

  1. Remove the old mapping if you want 如果需要,删除旧映射

  2. Highlight all your new elements and right click to assign a new mapping. 突出显示所有新元素,然后右键单击以指定新映射。 Use the notes you jotted down earlier to do this. 使用您之前记下的笔记来执行此操作。 Again, my case was very straightforward since columns were merely appended to the end. 同样,我的情况非常简单,因为列只是附加到末尾。 If you have columns added in the middle, you would want to remap them to the end of your table. 如果您在中间添加了列,则需要将它们重新映射到表的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM