Skip to content

Chage row in excel using C#

rachayita jaiswal

Asked Aug 13, 2013, 12:14 AM EDT1 answer
Share
LinkedInX
Hi, i am inserting data in excel sheet statically from design page to excel without using any database,now first time its is inserted .
if i ll again insert data,it will be overwrite.
i want that it should not overwrite, it should come in next row.
How i ll do this?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi Rachayita,

    Please hare how you're writing into excel sheet for clarification. Also, below is the pattern on writing excel rows, you may want to follow:
    ------------------------------------------

     for (int i = 0; i <= (dt.Rows.Count - 1); i++)
                {
                    for (int j = 0; j <= (dt.Columns.Count - 1); j++)
                    {
                        NewWorkSheet.Cells[i + 2, j + 1] = dt.Rows[i][j].ToString();
                    }
                }

    Here, worksheet.Cells[RowIndex,ColumnIndex] takes two parameters as explained, row index and column index.

    Hope it helps :)
    0