Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everybody

I have grid which contains Producnames , quantity and price i want to insert all informations in xls file.

On rows range is B27(productName) M27 (quantity) and O27

all range is B27 - B45

I i can insert them in my file but problem is that in my grid i possible to be 10 products i dont know how export them to xls. how can i make that i think i need arraylist

Please Advice me something.

Thanks.
Posted

1 solution

Correct me if I am wrong, you want to copy data in your grid to a excel in column B, M and O from rows 27 onwards.

If you have a data source for the grid, you can loop through it and write to the excel. Here something that can help you to begin with assuming you have a data table as the data source of the datagridview.
for(int rowIndex = 0; rowIndex < rowCount; rowIndex++)
{
    for(int colIndex = 0; colIndex < colCount; colCount++)
    {
        sheetObject.get_Range("cellPositionHere",Reflection.MissingValue).Value = dataSource[rowIndex][ColIndex].ToString();
    }
}


Take a look at this[^] article for more help. Writing data through arrays is certainly much faster than writing cell by cell. But this depends on the data source you are using. If the converting data source to array takes more effort than writing data cell by cell, you can ignore that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900