0

我有 52 个项目存储在 RichTextBox 中,每行一个项目。所以我有52行。

我需要将 RichTextBox 中每一行的值写入 Excel 范围 C17:C42 & H17:H42

我使用一种代码在精确单元格中写入数组:

//for the first 26 data
range = objSheet.get_Range("C17:C42", Missing.Value);
object[,] numbers1 = new object[26, 1];
for (int i = 0; i <= 25; i++)
{
   numbers1[i, 0] = //here i want a read each line in richtextbox; 
}
range.Value2 = numbers1;

下面是我如何阅读 RichTextBox 的每一行:

    string s = richTextBoxReceive.Text;
    var k = Regex.Split(s, "\\n", RegexOptions.Multiline);

    foreach (string str in k)
    {
        //do what you want
        MessageBox.Show(str);
    }

我如何结合这些?

4

2 回答 2

0

我认为它会工作......

void insert( List<string> value)
{
    //for the first 26 data
    range = objSheet.get_Range("C17:C42", Missing.Value);
    object[,] numbers1 = new object[26, 1];
    for (int i = 0; i <= 25; i++)
    {
        //value contains the data
        numbers1[i, 0] = value[i];
    }
     range.Value2 = numbers1;
}


//Get value from richtextbox
string s = richTextBoxReceive.Text;
var k = Regex.Split(s, "\\n", RegexOptions.Multiline);
List<string> allvalue=new List<string>();

foreach (string str in k)
{
    allvalue.Add(str);
}
//call insert method to insert data into excell
insert(allvalue);
于 2012-06-10T07:35:32.320 回答
0

好的,我已经自己解决了这个问题。我使用了一个数组并每行读取richtextbox。

range = objSheet.get_Range("C17:C42", Missing.Value);
object[,] numbers3 = new object[26,1];
for (int i = 0; i<= richTextBoxReceive.Lines.Length; i++)
{
    for (int j = 0; j <= 25; j++)
    {
        numbers3[j, 0] = richTextBoxReceive.Lines[j + 1];
    }
}
于 2012-06-10T15:09:08.367 回答