VSTO:将元数据附加到Excel中的单元格? [英] VSTO: Attach meta-data to a cell in Excel?

查看:116
本文介绍了VSTO:将元数据附加到Excel中的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VSTO创建一个Excel加载项。此附件从sql-server检索并显示大量数据。这很好,但是后来我打算访问excel中的一些数据,并以某种方式修改它。我的问题是我需要一种分类要修改的单元格的方法。有没有办法向单元格添加元数据,以确定它是否应该被修改的单元格?例如。向该单元添加一个属性,例如editable_cell,并执行像Excel.FindCellsWithAttribute(editable_cell)之类的东西,以找到被追踪的单元格?

I'm using VSTO to create an Excel Add-on. This add-on retrieves and display alot of data from a sql-server. This works great, but later on I plan to access some of the data inside excel and modify it in some ways. My problem is that I need a way of classify cells that I want to modify. Is there any way to add meta-data to a cell to know if it is a cell that should be modified? E.g. add a attribute to the cell, e.g. "editable_cell", and do something like Excel.FindCellsWithAttribute("editable_cell") to find the sought after cells?

谢谢!
/ Gustav

Thanks! /Gustav

推荐答案

有几种方法可以做到这一点。我不知道你的具体要求,所以我将简要介绍一些解决方案。

There are several way to do this. I do not know your specific requirements, so I will briefly outline some solutions.


  • 创建一个命名范围,但是如果不这样做,添加/删除数据可能会影响定义的命名范围。有时,最好定义一个名为range的单个单元作为书签,然后选择范围将会获得所有数据。

  • Create a Named Range, but adding/removing data can affect the defined Named Range if you don't do it right. Sometimes, it is better to define a single cell named range to act as a bookmark then "select range" will get you all the data.

创建样式。将此样式应用于您要查找的每个数据单元格。定义一个方法,返回一个范围基础,单元格具有指定的样式。

Create a Style. Apply this style to each data cell you wish to "find". Define a method that returns a Range base on which cells have the specified style.

创建一个 PivotCache 目的。该对象具有更新自身的能力,并减少文件大小,特别是如果缓存在工作簿中重复使用。它也是解决工作表中行数限制的一种方法。

Create a PivotCache Object. This object has the ability to update itself, and reduces the file size, especially if the cache is used repeatedly in a workbook. It is also one way to work around the limitation in the number of rows in a worksheet.

创建列表。这有很多优点。您可以随意添加/删除数据。添加/删除列。将列表视为表格。

Create a List. This has many advantages. You can add/remove data at will. Add/remove columns. Think of a list as a table.

使用XML映射( http://msdn.microsoft.com/en-us/library/aa203737(office.11​​).aspx )为code4life

Use XML Mapping (http://msdn.microsoft.com/en-us/library/aa203737(office.11).aspx) as "code4life" mentions.

如果工作簿是XMLSS,则定义一个新的命名空间,并使用命名空间中的属性装饰单元格。然后,您可以使用XPath查询。这是非常强大的,因为您可以将任何所需的内容嵌入到工作簿中。

If the workbook is XMLSS, then define a new namespace and adorn the cells with an attribute from the namespace. You can then "query" using XPath. This is a very powerful because you can embed whatever is needed into a workbook.

每个都有其优点/缺点。我已经使用了每个解决方案多次。

Each has its advantages/disadvantages. I have used each solution multiple times.

这篇关于VSTO:将元数据附加到Excel中的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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