什么是存储在一个Excel文件的XML数据的最佳方式 [英] What is the best way to store XML data in an Excel file

查看:305
本文介绍了什么是存储在一个Excel文件的XML数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方法来存储在一个Excel文件的XML数据。
中的数据应被完全隐藏给用户,它不应该是在细胞或评论,甚至隐藏。
也,数据应当用户打开,然后保存用Excel文件保留。
我不是在寻找一种方式来映射细胞外部XML数据。 XML数据应该是XLSX文件中。

I am looking for a way to store XML data in an Excel file. The data should be completely hidden to the user, it should not be in a cell or comment, even hidden. Also, the data should be preserved when the user opens and then saves the file with Excel. I am not looking for a way to map cells to external XML data. The XML data should be inside the xlsx file.

中的数据将使用C#输入工具中,而不是Excel的本身。

The data will be entered using a C# tool, not Excel itself.

推荐答案

我有同样的问题,这里是我的代码来处理它,使用的微软的自定义XML部件。 (您可能会发现在代码中我的意见做必要的解释)。

I had the same issue and here is my code to deal with it, using Microsoft's Custom XML Parts. (You may find all the necessary explanations in my comments in the code).

//Deletes all the previously added parts and adds a new part 
//containing the string argument which has to be in XML format. 


public void addCustomXMLPart(string test)
{
    IEnumerator e = Xlworkbook.CustomXMLParts.GetEnumerator();
    e.Reset();
    CustomXMLPart p;
    //The !p.BuiltIn is because before our customXMLPart there are some
    // Excel BuiltIns of them and if we try to delete them we will get an exception.
    while (e.MoveNext())
    {
        p = (CustomXMLPart)e.Current;
        if (p != null && !p.BuiltIn) 
            p.Delete();
    }
    Xlworkbook.CustomXMLParts.Add(test, Type.Missing);
}



关于 xlworkbook 上述使用的对象:

using Excel = Microsoft.Office.Interop.Excel;

Excel.Workbook XlWorkbook = (Excel.Workbook)
  (Excel.Application)Marshal.GetActiveObject("Excel.Application")).ActiveWorkbook;

这篇关于什么是存储在一个Excel文件的XML数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆