how to prompt save As Box in Excel Interlop c# MVC 4 -


i want export excel sheet using excel interloop...

i have datatable convert excel sheet...

now there way save file using save dialogue box in mvc 4

here code

 public string datatabletoexcel(datatable dt, string htmlheading, string key)          {              try              {                      microsoft.office.interop.excel.application excel;                  microsoft.office.interop.excel.workbook excelworkbook;                  microsoft.office.interop.excel.worksheet excelsheet;                  microsoft.office.interop.excel.range excelcellrange;                            excel = new microsoft.office.interop.excel.application();                    excel.visible = false;                  excel.displayalerts = false;                  excelworkbook = excel.workbooks.add(type.missing);                  excelsheet = (microsoft.office.interop.excel.worksheet)excelworkbook.activesheet;                  excelsheet.name = "sheet1";                    dataset new_ds = new dataset();                    datatable dtcopy = dt.copy();                  new_ds.tables.add(dtcopy);                  foreach (datatable table in new_ds.tables)                  {                        (int = 1; < table.columns.count + 1; i++)                      {                          excelsheet.cells[1, i] = table.columns[i - 1].columnname;                      }                        (int j = 0; j < table.rows.count; j++)                      {                          (int k = 0; k < table.columns.count; k++)                          {                              excelsheet.cells[j + 2, k + 1] = table.rows[j].itemarray[k].tostring();                          }                      }                  }           /////   how can export excel in save box ???                                                                  }

you cannot prompt dialog box user because on server side. can load file in stream , send client. , client's browser decide save file.

that said, have aware interop running ont server side not recommended microsoft (see : kb microsoft problems using server-side automation of office)


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -