利用ASP.NET 导出excel(2007版)
2012-05-25 15:16
417 查看
http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm
// In this example, I have a defined a List of my Employee objects.
class Employee;
List<Employee> listOfEmployees = new List<Employee>();
...
// The following code gets run when I click on my "Export to Excel" button.
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
string filename = "\\\\MikesServer\\ExcelFiles\\Employees.xlsx";
if (CreateExcelFile.CreateExcelDocument(listOfEmployees, filename))
{
// We successfully managed to export to an Excel file.
// Now, get the ASP.Net application to open this Excel file, ready for the user to view.
Response.ClearContent();
FileStream fs1 = new FileStream(filename, FileMode.Open, FileAccess.Read);
byte[] data1 = new byte[fs1.Length];
fs1.Read(data1, 0, data1.Length);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
Response.BinaryWrite(data1);
Response.End();
}
}
// In this example, I have a defined a List of my Employee objects.
class Employee;
List<Employee> listOfEmployees = new List<Employee>();
...
// The following code gets run when I click on my "Export to Excel" button.
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
string filename = "\\\\MikesServer\\ExcelFiles\\Employees.xlsx";
if (CreateExcelFile.CreateExcelDocument(listOfEmployees, filename))
{
// We successfully managed to export to an Excel file.
// Now, get the ASP.Net application to open this Excel file, ready for the user to view.
Response.ClearContent();
FileStream fs1 = new FileStream(filename, FileMode.Open, FileAccess.Read);
byte[] data1 = new byte[fs1.Length];
fs1.Read(data1, 0, data1.Length);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
Response.BinaryWrite(data1);
Response.End();
}
}
相关文章推荐
- ASP.NET 利用 Microsoft.Office.Interop.Excel 版本导出Excel数据
- Asp.net开发经验-利用Aspose.Words按模板导出Word(注:Excel可以使用Aspose.Excel)
- asp.net 利用NPOI导出Excel通用类的方法
- ASP.Net MVC利用NPOI导入导出Excel - RuleLu
- Asp.net中利用NPOI做Excel导出功能
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- ASP.NET利用GridView导出EXCEL
- asp.net中利用NPOI导出数据到excel中
- OpenXML: Asp.net利用OpenXML 导出Excel.
- ASP.NET导出Excel(利用NPOI和EPPlus库,无需安装Office)
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- ASP.NET,Web界面利用Button来实现将telerik:RadGrid表格内数据导出Excel
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- asp.net 利用NPOI导出Excel通用类
- OpenXML: Asp.net利用OpenXML 导出Excel.
- ASP.Net MVC利用NPOI导入导出Excel
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- asp.net中DataGrid利用RenderControl导出Excel的问题
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)