We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cell update doesn't work after inserting a new row

Hi All,
I would like to insert hugh number of rows, in a for loop, than update the created row’s cell.

I used this code:

List collist = new List() { “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”, “AA”, “AB”, “AC”, “AD”, “AE”, “AF”, “AG”, “AH”, “AI”, “AJ”, “AK”};
Worksheet worksheet = workbook.Worksheets[“Part1_1”];
for (int i = 5; i < 106; i++)
{
worksheet.Cells.InsertRow(5);

foreach (string sCell in collist)
{
string szCC = sCell + “5”;
Console.WriteLine(szCC);
worksheet.Cells[szCC].PutValue(“asd”);
}

}

The code executed without error, but the new rows become empty.

Can you help me what is wrong?

Thank you,
Jozsef

Hi Jozsef,


Thank you for contacting Aspose support.

I am not sure about your ultimate goal, however, your current code is overwriting the row 5 again and again. If your requirement is to repeat the text “asd” for each newly inserted row then please insert the row at index 4. If this not your requirement then please explain your ultimate goal or share your desired results in spreadsheet format.

C#

Workbook workbook = new Workbook();
List<string> collist = new List<string>() { “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”, “AA”, “AB”, “AC”, “AD”, “AE”, “AF”, “AG”, “AH”, “AI”, “AJ”, “AK” };
Worksheet worksheet = workbook.Worksheets[0];
for (int i = 5; i < 106; i++)
{
worksheet.Cells.InsertRow(4);
foreach (string sCell in collist)
{
string szCC = sCell + “5”;
Console.WriteLine(szCC);
worksheet.Cells[szCC].PutValue(“asd”);
}
}
workbook.Save(“D:/output.xlsx”);

Hi Babar,
Thank you for your fast response. I assumed the insertrow is working in the same way as in Excel. So If I insert a new row into rownum 5 than the rownum 5 become the empty new, and the previous rows become 6…

We have a template xlsx file, and I can only insert the data to the sheet. I would like to add couple of new rows, without loosing the defined heading rows, and footer rows.
Thanks,
Jozsef

Hello again,
Tried in the recommended way, and I got what I was looking for.

Thank you very much, we might mark this thread as resolved :slight_smile:

Thank you,
Jozsef

Hi Jozsef,


Thank you for the confirmation. Please feel free to contact us back in case you need our further assistance with Aspose APIs.