//程序集 Aspose.Cells.dll, v5.3.1.0
using Aspose.Cells;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OperateCell
{
class Program
{
static void Main(string[] args)
{
}
public static int GetMaxColumn(Cell cell, Cells cells)
{
int i = 0;
int maxColumn = 0;
while (cell != null && cells.GetCell(cell.Row, cell.Column + i + 1) != null)
{
i++;
maxColumn = i + cell.Column;
}
return maxColumn;
}
/// <summary>
/// 利用递归通过关键字寻找要cell
/// </summary>
/// <param name="cells">开始寻找的对象cells</param>
/// <param name="keyWord">应该包含的关键字</param>
/// <param name="onContains">不应该包含的关键字</param>
/// <param name="cellBegin">开始寻找的cell</param>
/// <returns>返回需要寻找的cell</returns>
public static Cell FindCell(Cells cells, string[] keyWord, string[] noContains, Cell cellBegin)
{
//通过第一关键字定位到一个cell
Cell firstCell = cells.FindStringContains(keyWord[0], cellBegin);
if (firstCell == null)
return null;
//假设全部都包含
bool allContainKeyWord = true;
//假设全部都不包含
bool allNoConain = true;
for (int i = 1; i < keyWord.Length; i++)
{
if (!firstCell.Value.ToString().Contains(keyWord[i]))
{
//有一个不包含,那么allContainKeyWord就为false
allContainKeyWord = false;
break;
}
}
//keyword全部包含
if (allContainKeyWord)
{
for (int i = 0; i < noContains.Length; i++)
{
//判断寻找到的是否包含不应该包含的
if (firstCell.Value.ToString().Contains(noContains[i]))
{
//有一个不应该包含的,就为false
allNoConain = false;
break;
}
}
//没有不包含的
if (allNoConain)
return firstCell;
else
//继续寻找,通过firstcell寻找
return FindCell(cells, keyWord, noContains, firstCell);
}
else //如果keyword有不包含的,重新找,从firstcell开始找
return FindCell(cells, keyWord, noContains, firstCell);
}
}
}
Aspose.Cells寻找cell的方法
最新推荐文章于 2024-06-10 21:52:24 发布