Save Info of Datagridview
How can I save the infor of the datagridView in an excel template?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bechir BejaouiRank #144 · 15.9K reputationPosted Jul 26, 2008, 9:30 AM EDT
add a reference for a COM component called "Microsoft Excel 9.0 object library".
you can also import the excel library to using tlbimp.exe tool to import the excel 9.0 library
then
Application oExcel = new Application();
workbook oWorkbook = (workbook)oExcel.Worlbooks.add();
Sheet oSheet = (Sheet)oWorkbook.ActiveSheet;
int i=0,j=0;
foreach(DatagridviewRow row in yourdatagridview)
{
foreach(DatagridviewColumn column in yourdatagridview)
{
oSheet.cells[i,j] = yourdatagridview[i,j].value;
i+=1;
}
j=+1;
}
Arnold Petrona156 reputationPosted Sep 17, 2008, 1:08 PM EDT
Ok, question about your code for understanding it :
Application oExcel = new Application();
workbook oWorkbook = (workbook)oExcel.Worlbooks.add();
Sheet oSheet = (Sheet)oWorkbook.ActiveSheet;
int i=0,j=0;
foreach(DatagridviewRow row in yourdatagridview)
{
foreach(DatagridviewColumn column in yourdatagridview)
{
oSheet.cells[i,j] = yourdatagridview[i,j].value;
i+=1;
}
j=+1;
}
Where the word Workbook and Sheet come from?