Skip to main content
 首页 » 编程设计

c#之Excel-C#: How to read the formulas from a cell

2024年02月23日16jyk

通过这种方法,我读取了一个单元格的内容:

Range range = (Range)sheet.Cells[i, j]; 
            if ((range == null) || (range.Value2 == null)) return ""; 
            return range.Value2.ToString(); 

但是我怎样才能从单元格中读取公式呢?

请您参考如下方法:

在返回的单元格上使用 .Formula 或 .FormulaR1C1 属性,例如:

return range.Formula