问题描述:如题
问题解答:创建中转 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[local.ToString()];
- }
- }
- //TODO: check all other expression and find by yourselves.
- throw new NotImplementedException();
- }
复制代码
示例下载:点击下载
|