通过 “Sheet1!A1” 方式获取单元格公式
问题描述:如题问题解答:创建中转 WorkSheet 分析输入信息,得到 Expression 获取单元格信息。
关键代码:
public static Cell GetCells(this GcSpreadSheet spread, string formula)
{
var workbook = spread.Workbook;
var dummySheet = workbook.Sheets.FirstOrDefault((s) => s.Name == DummyWorksheetName);
if (dummySheet == null)
{
workbook.Sheets.Add(dummySheet = new Worksheet(DummyWorksheetName)
{
Visible = false
});
}
var eval = dummySheet as ICalcEvaluator;
System.Diagnostics.Debug.Assert(eval != null);
var expr = eval.Formula2Expression(formula, 0, 0);
if (expr is CalcExternalCellExpression || expr is CalcExternalRangeExpression)
{
var extExpr = expr as CalcExternalExpression;
var targetSheet = extExpr.Source as Worksheet;
if (targetSheet != null)
{
var extId = extExpr.GetId(0, 0) as CalcExternalIdentity;
var local = extId.ConvertToLocal();
return targetSheet.Cells;
}
}
//TODO: check all other expression and find by yourselves.
throw new NotImplementedException();
}
示例下载:点击下载
请问有没有winfrom示例? 如果你的需求是通过单元格地址字符串来获取到单元格对象信息的话,在新版的winfom开发包中可以直接这样写
var range=_fpSpread.AsWorkbook().ActiveSheet.Range("Sheet1!A1:C1");
页:
[1]