另外又试了一种情况,spread编辑器中导入之前保存的excel文件(包含公式),这时能结果正确,运行程序,结果也正确,但这时执行我的增加公式的代码,结果就不正确了,我的代码如下
private void buttonItem9_Click(object sender, EventArgs e)
{
SheetView sv = fpSpread1.Sheets["洞身衬砌表"];
if (sv == null)
return;
int activeRows = sv.NonEmptyRowCount;
if (activeRows > 2)
{
for (int i = 0; i < activeRows - 2; i++)
{
SubsetLinFormula(i + 2);
}
}
}
private void SubsetLinFormula(int row)
{
SheetView sv_洞身衬砌表 = fpSpread1.Sheets["洞身衬砌表"];
if (sv_洞身衬砌表 == null)
return;
if (row < 2)
return;
sv_洞身衬砌表.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
// sv_洞身衬砌表.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
//各行公式都是一样的,以下按列顺序
sv_洞身衬砌表.Cells[row, 0].Value = (row - 1).ToString();//序号
//先设表头公式
sv_洞身衬砌表.Cells[row, 26].Formula = "RC6&RC7&RC8&RC5&RC9";
//支护参数列
sv_洞身衬砌表.Cells[row, 25].Formula = "if(RC13=0,\"\",rc13)&if(RC16=0,\"\",\"+\"&RC16)";//施工方法(2),用于绘图
//衬砌类型、加宽等无公式
int n = 2;
for (int m = 9; m < 25; m++)
{
string FormlaString = "IF(ISERROR(VLOOKUP(RC27,词典!R3C1:R300C17," + n.ToString() + ",0)),\"词典里没有\",VLOOKUP(RC27,词典!R3C1:R300C17," + n.ToString() + ",0))";
sv_洞身衬砌表.Cells[row, m].Formula = FormlaString;
n++;
}
} |