c# - How can i export multiple dataset to an excel sheet -


hi export data dataset excel sheet. dataset consists of 2 tables how can write multiple dataset values in single excel sheet

before u have create
1.using excel = microsoft.office.interop.excel;//in header,and add correct refference
2.excel.application excelhandle1 = prepareforexport(ds); //add handle in calling function excelhandle1.visible = true;

 public excel.application prepareforexport(system.data.dataset ds,string[] sheet)     {             object missing = system.reflection.missing.value;             excel.application excel = new excel.application();             excel.workbook workbook = excel.workbooks.add(missing);              datatable dt1 = new datatable();             dt1 = ds.tables[0];             datatable dt2 = new datatable();             dt2 = ds.tables[1];               excel.worksheet newworksheet;             newworksheet = (excel.worksheet)excel.worksheets.add(missing, missing, missing, missing);             newworksheet.name ="name of data sheet";  //  first datatable dt1..              int icol1 = 0;             foreach (datacolumn c in dt1.columns)             {                 icol1++;                 excel.cells[1, icol1] = c.columnname;             }              int irow1 = 0;             foreach (datarow r in dt1.rows)             {                 irow1++;                  (int = 1; < dt1.columns.count + 1; i++)                 {                      if (irow1 == 1)                     {                         // add header first time through                          excel.cells[irow1, i] = dt1.columns[i - 1].columnname;                     }                      excel.cells[irow1 + 1, i] = r[i - 1].tostring();                 }              }     //   second datatable dt2..              int icol2 = 0;             foreach (datacolumn c in dt2.columns)             {                 icol2++;                 excel.cells[1, icol] = c.columnname;             }               int irow2 = 0;             foreach (datarow r in dt2.rows)             {                 irow2++;                  (int = 1; < dt2.columns.count + 1; i++)                 {                      if (irow2 == 1)                     {                         // add header first time through                          excel.cells[irow2, i] = dt2.columns[i - 1].columnname;                     }                      excel.cells[irow2 + 1, i] = r[i - 1].tostring();                 }              }             return excel;     } 

i using code


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -