本文介绍了将Excel粘贴到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个函数来捕获用户从excel粘贴的值。我只能得到第一排,但是如何获得第二排及以后?
这是我的代码:
i need to create a function that will capture the values which user pasted from excel. i only able to get the first row, however how to get the second row and onward?
this is my code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
string rowA, rowB, rowC;
string str = this.TextBox1.Text;
string[] tokens = str.Split('\t');
string retVal = tokens[0] + " " + tokens[1];
rowA = retVal; //result for first row
rowB = ""; //result for second row
rowC = ""; //result for third row
}
示例来自excel的数据用户粘贴:
sample Data user paste from excel:
User ID Column1 Column2 Column3 Column4
1 100 120 110 80
2 80 90 95 115
预期结果:
rowA = 210 (仅限Column1 + Column3,001)
rowB = 185(仅限Column2 + Column3,002)
如果你注意到,rowA和rowB的计算不同,公式已经预定义了
请帮帮我,谢谢:)
Expected result:
rowA = 210 (Column1 + Column3, 001 only)
rowB = 185 (Column2 + Column3, 002 only)
if u notice, the calculation for rowA and rowB is different, the formula is already predefined
please help me, thanks :)
推荐答案
string[] rows = TextBox1.Text.Split (new string[]{System.Environment.NewLine}, StringSplitOptions.None );
string[] row1 = rows[1].Split();
var rowA = int.Parse(row1[1]) +int.Parse(row1[3]);
string[] row2 = rows[2].Split();
var rowB = int.Parse(row2[2]) +int.Parse(row2[3]);
rowA = tokens[0]; //result for first row
rowB = tokens[1]; //result for second row
rowC = tokens[2]; //result for third row
这篇关于将Excel粘贴到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!