[英]How to copy Given no of cells from a perticular row in Excel using C#
As per my requirement, I am getting Row Number and Maximum column count. 根据我的要求,我正在获取行号和最大列数。 Now I have to copy (column count)Columns of Row(RowNumber) to a different sheet.
现在,我必须将Row(RowNumber)的(列数)列复制到另一张工作表。
For Example. 例如。 RowNo = 2 and ColumnCount = 5 Now I have to copy first 5 cells of Row 2.
RowNo = 2和ColumnCount = 5现在,我必须复制第2行的前5个单元格。
PS: Range("A2:E2") is not an option PS:Range(“ A2:E2”)不是一个选项
if you wanna get the value of your sheet one by one, you can try this (based on your example row=2 and colCount=5) 如果您想一张一张地获取工作表的价值,可以尝试一下(基于示例row = 2和colCount = 5)
dynamic activeRow = activeSheet.UsedRange.Rows[2, Type.Missing].Columns.Value2;
var firstCell = activeRow[1, 1].ToString();
var secondCell = activeRow[1, 2].ToString();
var thirdCell = activeRow[1, 3].ToString();
var forthCell = activeRow[1, 4].ToString();
var fifthCell = activeRow[1, 5].ToString();
and you can insert these value in a sheet like this: 您可以将这些值插入像这样的工作表中:
sheet.Cells[row, col] = value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.