在JQuery对话框按钮中导出到excel功能 - MVC 4

时间:2014-03-31 17:04:20

标签: asp.net-mvc-4

我有一个Jquery拨号盒,其中包含4个按钮。导出到excel就是其中之一。 我正在尝试将我的网格数据导出为ex​​cel。如果您有任何类似的例子,请告诉我。

请告诉我,如何在jquery对话框按钮单击时编写并调用导出到excel。

1 个答案:

答案 0 :(得分:0)

要写一些东西到excel文件:

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
object misValue = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Workbook workBook = excelApp.Workbooks.Add(misValue);
Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets.get_Item(1);
Microsoft.Office.Interop.Excel.Range range;

//top of document
workSheet.Cells[1, 1] = string.Format("{0:dd.MM.yyyy}", DateTime.Now);
workSheet.Cells[1, 6] = "Something1";
workSheet.Cells[2, 3] = "Something2";
workSheet.Cells[4, 3] = "Something3";
workSheet.Cells[6, 3] = "Something4";

// test content
for (int i = 0; i < 10; i++)
{
   workSheet.Cells[i + 9, 1] = (i + 1).ToString(); 
   workSheet.Cells[i + 9, 2] = i.ToString();
   workSheet.Cells[i + 9, 3] = Math.Round(2.555, 2);
   workSheet.Cells[i + 9, 4] = "Hi"; 
   workSheet.Cells[i + 9, 5] = i.ToString();
   workSheet.Cells[i + 9, 6] = i.ToString();         
}

//show document
excelApp.Visible = true;

当&#34;出口到excell&#34;点击按钮,调用包含上述代码的操作。