Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
           Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
           Microsoft.Office.Interop.Excel._Worksheet worksheet1 = null;
           Microsoft.Office.Interop.Excel._Worksheet worksheet2 = null;
           app.Visible = true;
           worksheet1 = workbook.Sheets["Sheet1"];
           worksheet1 = workbook.ActiveSheet;
           for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
           {
               worksheet1.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
           }
           for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
           {
               for (int j = 0; j < dataGridView1.Columns.Count; j++)
               {
                   if (dataGridView1.Rows[i].Cells[j].Value != null)
                   {
                       worksheet1.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
                   }
                   else
                   {
                       worksheet1.Cells[i + 2, j + 1] = "";
                   }
               }
           }


i got this code from the internet by google and i want ti add a data in list i have to the same excel file can any one help please
if the data i want to add is list<string> aa and list<int> bb ;
Posted

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