我已经在Excel中编写了一个加载项。我在功能区中的按钮单击上添加一个CustomXmlPart。添加CustomXmlPart后,我将其GUID保存在单独的表格(XML)中,以便以后检索xml。
这里是代码:
private void btnAddXML_Click(object sender, RibbonControlEventArgs e)
{
Excel.Workbook WB = Globals.ThisAddIn.Application.ActiveWorkbook;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\Users\shree\Desktop\Correct.xml");
Microsoft.Office.Core.CustomXMLPart TaggingXml = WB.CustomXMLParts.Add(xmlDoc.OuterXml);
string strXmlGUID = TaggingXml.Id;
Excel.Worksheet WS = WB.Sheets.Add(After: WB.Sheets[WB.Sheets.Count]);
WS.Name = "XML";
WS.Cells[1, 1] = strXmlGUID;
}
private void btnShowXML_Click(object sender, RibbonControlEventArgs e)
{
Excel.Workbook WB = Globals.ThisAddIn.Application.ActiveWorkbook;
Excel.Worksheet WS = WB.Sheets["XML"];
XmlDocument xmlDoc = new XmlDocument();
Microsoft.Office.Core.CustomXMLPart TaggingXml = WB.CustomXMLParts.SelectByID(WS.Cells[1, 1].Value.ToString());
StreamWriter sw = File.CreateText(@"C:\Users\shree\Desktop\New.xml");
sw.Write(TaggingXml.XML);
sw.Close();
sw.Dispose();
MessageBox.Show("Done");
}
现在我的问题是如何在excel中查看此xml文档(如果可能的话)。如果我将此文件移动到另一个系统,我将能够访问该xml或将其存储在本地系统中。如果我用来读取xml的GUID与其他计算机中其他对象的GUID发生冲突,该怎么办。 CustomXmlPart如何工作?它存储在哪里?
对于任何阅读者,您都可以。右键单击excel文件并使用压缩软件(例如winrar或zip)打开
问候