填写.Formula的一个Excel范围使用(字符串)数组 [英] Fill the .Formula's of an Excel Range with an array (of strings)

查看:204
本文介绍了填写.Formula的一个Excel范围使用(字符串)数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我使用C#,但语言不应该的问题。)

  range.Formula =阵列;
 

不会导致错误,但功能完全一样。

  range.Value2 =阵列;
 

:公式看起来像是值。当我做<大骨节病> F2 ,<大骨节病>输入上一个单元格,公式被适当地评估。

这是我如何填写该数组:

  VAR阵列=新的字符串[行,COLS]。
//填充阵列。
为(长iRow = 0; iRow&LT;行; iRow ++)
{
  为(长ICOL = 0; ICOL&LT; COLS; ICOL ++)
  {
    //放入细胞的计数器。例如。 = A 1 + 1 + 100000
    阵列[iRow,ICOL] == A1 ++(ICOL + 1)+++(iRow + 1)*(rowStep);
  }
}
 

解决方案

工作对我来说,如果我使用对象[,] 而不是字符串[ ,]

(I'm using C#, but the language shouldn't matter.)

range.Formula = array;

does not result in an error, but behaves exactly like

range.Value2 = array;

: the Formulas appear like Values. When I do F2, Enter on a cell, the Formula gets evaluated properly.

This is how I fill the array:

var array = new string[rows, cols];
//Fill the array.
for (long iRow = 0; iRow < rows; iRow++)
{
  for (long iCol = 0; iCol < cols; iCol++)
  {
    //Put a counter in the cell.  E.g. "=A1+1+100000"
    array[iRow, iCol] = "=A1+" + (iCol+1) + "+" + (iRow+1) * (rowStep);
  }
}

解决方案

Works for me if I use object[,] instead of string[,].

这篇关于填写.Formula的一个Excel范围使用(字符串)数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆