- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试从 Excel 中获取范围,其中指定了多个区域,基本上我已经...
整数开始列
int EndColumn
int[] ColumnsToSkip
当您将这些组合在一起时,可能会产生一个具有不连续区域的范围。不幸的是,我无法完全弄清楚获得这个的电话...MSDN 不是很有用...
工作表;
sheet.get_Range( what goes in here??? );
有人提供帮助吗?干杯。
最佳答案
一个非常简单的解决方案是以逗号分隔的形式指定不同的区域:
sheet.get_Range( "A1:B1,E1:G1");
对于编程范围组合,还有 ExcelApplication 对象的 Union
和 Intersection
方法。由于许多可选参数,这些在 C# 中使用起来有点笨拙。看这里
例如。
编辑:一些额外的提示:
在您的情况下,您首先应该转换“ColumnsToKeep”中的“ColumnsToSkip”,因为这是任何类型的单元联合所需要的。这是一个 Linq 解决方案:
int[] ColumnsToKeep = Enumerable.Range(StartColumn, EndColumn -StartColumn + 1)
.Except(ColumnsToSkip)
.ToArray();
然后,您可以按照此示例创建一些内容:
Excel.Range totalRange = null;
foreach(int col in ColumnsToKeep)
{
totalRange = Union(excelApp,totalRange,(Excel.Range)sh.Cells[row, col]);
}
其中定义了“Union”,例如,像这样:
static Excel.Range Union(Excel.Application app, Excel.Range r1, Excel.Range r2)
{
if (r1 == null && r2 == null)
return null;
if (r1 == null)
return r2;
if (r2 == null)
return r1;
return app.Union(r1, r2,
null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null);
}
关于c# - 具有多个区域的 Excel Get_Range,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6155182/
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.get_range.aspx它说使用 Ra
我正在尝试从 Excel 中获取范围,其中指定了多个区域,基本上我已经... 整数开始列 int EndColumn int[] ColumnsToSkip 当您将这些组合在一起时,可能会产生一个具有
我正在使用 C# 来操作 Excel 工作表。以下两段代码应该工作相同,但一段有效,另一段抛出异常。我想知道为什么。 这个有效: oRange = (Excel.Range)oSheet.get_Ra
我有以下一段 VSTO 代码,它的行为很奇怪。 string s = "E6:N6,E8:N12,E14:N16,E18:N20,E23:N26,E28:N31,E33:N33,E35:N35,E37
我正在尝试在 Excel C# 中访问另一个范围内的范围,并出现意外行为。在第一个范围内,Cell[1,1].Value 给出了该范围内第一个单元格的值,如预期的那样。但是,在“子范围”中,Cell[
在用 C# 编写的 Excel VSTO 项目中,我需要从单元格的字符串列表中获取 Range 对象。 这是问题的简化版本: string strRange = "A1:A2,A5"; Excel.R
我认为一切都在问题之中。我正在寻找 Pycassa ColumnFamily.get_range() 的 Lazyboy 等效项 - 具有诸如 column_start、column_finish 和
尝试通过逐行引用替换 Cells(RowIndex,ColumnIndex).Value() 调用以提高性能,我在引用结果时永久失败。 以 Excel Interop - Efficiency and
我构建了一个引用 COM 互操作 DLL 的程序集。如果我通过在引用的属性 (VS2010) 中将嵌入互操作类型设置为 True 来嵌入 COM 互操作类型,则在运行时会出现错误“对象不包含 get_
我正在阅读 Python 速成类(class)这本书,但我一直停留在书中给出的示例上。我什至复制-粘贴了书中的脚本,但仍然出现错误。 名为 car.py 的文件 """A class that can
我是一名优秀的程序员,十分优秀!