VBA中的npoi SetCellFormula自定义公式 [英] npoi SetCellFormula custom formula in VBA
本文介绍了VBA中的npoi SetCellFormula自定义公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用Excel模板填充数据的应用程序.模板是.xlsm.在模板中,当我尝试将单元格公式设置为此函数时,我创建了一个名为SumByColor的vba函数,但出现此错误:
I have an application that fills with data an excel template .Template is .xlsm .In template I created vba function called SumByColor when i try to set a cell formula to this function i get this error :
{"Name 'SumByColor' is completely unknown in the current workbook"}
我这样设置公式:
sheet.GetRow(rowIndex).GetCell(startPos + 2).SetCellFormula(string.Format("SumByColor($AQ$7,F{0}:AI{0})",rowIndex+1));
推荐答案
在设置单元格公式之前,是否尝试将单元格类型设置为公式".对于Ex:
Have you tried setting the cell Type as Formula before setting the formula for cell. For Ex:
XSSFRow row = (XSSFRow)sheet.GetRow(i);
ICell cell = row.CreateCell(1);
cell.SetCellType(CellType.Formula);
cell.SetCellFormula("SUM(B1:B10)");
您可以阅读有关设置公式和约束的更多信息.
You can read up more on setting formula and constraints.
这篇关于VBA中的npoi SetCellFormula自定义公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文