using System.Data.SqlClient;
using Aspose.Cells;
using System.Web;
using System.IO;
Aspose.dll需要收费,不过可以在网上找到很多破解版
public void ExportExcelWithAspose(DataTable dt)
{
string saveFileName = null;
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "xls";
saveDialog.Filter = "Excel 工作簿|*.xls";
saveDialog.ShowDialog();
saveFileName = saveDialog.FileName;
if (saveFileName.IndexOf(":") < 0) return; //被点了取消
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("无法创建Excel对象,可能您的设备未安装Excel");