Excel でアドインを作成しました。リボンのボタンをクリックして CustomXmlPart を追加しています。CustomXmlPart が追加されると、後で XML を取得するために、その GUID を別のシート (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");
}
ここで私の質問は、この xml ドキュメントを Excel 内で表示する方法です (可能な場合)。このファイルを別のシステムに移動すると、この xml にアクセスできるようになりますか、またはシステムにローカルに保存されます。xml の読み取りに使用している GUID が、他のマシンの他のオブジェクトの GUID と競合する場合はどうなりますか。CustomXmlPart はどのように機能しますか? どこに保管されていますか?