Excel-DNA 将自定义数据保存到工作表中(不是单元格)
Excel-DNA save custom data into worksheet (not cells)
我希望有一种方法可以将自定义数据从 Excel-DNA 插件保存到工作簿中..
用户将从自定义 Excel-DNA 表单中输入的内容。
我知道这可以保存到单元格中,但我不希望用户看到或更改数据..
是否有可能将自定义 XML 文件附加到工作簿或添加隐藏工作表的方法?
詹姆斯
您可以使用 Workbook.CustomXMLParts 执行此操作:请参阅
Custom XML Parts Overview
对于那些感兴趣的人,以下内容来自 Excel-DNA 功能区按钮:
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文件,第二次取回。您可以保存工作簿并重新打开以确认它仍然存在..
詹姆斯
我希望有一种方法可以将自定义数据从 Excel-DNA 插件保存到工作簿中..
用户将从自定义 Excel-DNA 表单中输入的内容。
我知道这可以保存到单元格中,但我不希望用户看到或更改数据..
是否有可能将自定义 XML 文件附加到工作簿或添加隐藏工作表的方法?
詹姆斯
您可以使用 Workbook.CustomXMLParts 执行此操作:请参阅
Custom XML Parts Overview
对于那些感兴趣的人,以下内容来自 Excel-DNA 功能区按钮:
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文件,第二次取回。您可以保存工作簿并重新打开以确认它仍然存在..
詹姆斯