Excel-DNA将自定义数据保存到工作表(不是单元格)

我希望有一种方法可以将自定义数据从Excel-DNA插件保存到工作簿中。

用户可以从自定义Excel-DNA表格中input内容。

我意识到这可以保存到单元格,但我不希望用户看到或更改数据..

有没有一种方法可能将自定义的XML文件附加到工作簿,或添加隐藏的工作表?

詹姆士

您可以使用Workbook.CustomXMLParts执行此操作:请参阅
自定义XML部件概述

对于那些感兴趣的,下面的工作从一个Excel-DNA丝带button:

Microsoft.Office.Interop.Excel.Application excelApp = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application; Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.ActiveWorkbook; System.Collections.IEnumerator enumerator = workbook.CustomXMLParts.SelectByNamespace("http://schemas.microsoft.com/vsto/samplestest").GetEnumerator(); enumerator.Reset(); if (!(enumerator.MoveNext())) { string xmlString1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<employees xmlns=\"http://schemas.microsoft.com/vsto/samplestest\">" + "<employee>" + "<name>Surender GGG</name>" + "<hireDate>1999-04-01</hireDate>" + "<title>Manager</title>" + "</employee>" + "</employees>"; Office.CustomXMLPart employeeXMLPart = workbook.CustomXMLParts.Add(xmlString1); } else { Office.CustomXMLPart a = (Office.CustomXMLPart)enumerator.Current; a.NamespaceManager.AddNamespace("x", "http://schemas.microsoft.com/vsto/samplestest"); MessageBox.Show(a.SelectSingleNode("/x:employees/x:employee/x:name").Text); MessageBox.Show(a.XML); } 

第一次添加xml文件,第二次检索它。 您可以保存该工作簿并重新打开以确认它仍然存在..

詹姆士