Asp.net 导出Excel 处理科学计算法
2012-03-02 16:11
459 查看
public static void doExport(DataSet ds, string strExcelFileName) { Excel.Application excel = new Excel.Application(); int rowIndex = 1; int colIndex = 0; excel.Application.Workbooks.Add(true); System.Data.DataTable table = ds.Tables[0]; foreach(DataColumn col in table.Columns) { colIndex++; excel.Cells[1, colIndex] = col.ColumnName; } foreach(DataRow row in table.Rows) { rowIndex++; colIndex = 0; Excel.Range range; foreach(DataColumn col in table.Columns) { colIndex++; string type = col.DataType.ToString(); range = (Excel.Range) excel.Cells[rowIndex, colIndex]; switch (type) { case "System.String": range.NumberFormatLocal = "@"; break; case "System.DateTime": range.NumberFormatLocal = "yyyy-mm-dd"; range.ColumnWidth = 10; break; } excel.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString(); } } excel.Visible = false; excel.ActiveWorkbook.SaveAs (strExcelFileName, Excel.XlFileFormat.xlExcel9795, null, null, false, false, Excel.XlSaveAsAcce ssMode.xlNoChange, null, null, null, null); excel.Quit(); excel = null; GC.Collect(); }
相关文章推荐
- ASP.NET大批量数据处理,97-2003Excel导入、导出
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- ASP.NET 导出正式Excel文档(可锁定首行,有效防止数字类型数据科学计数法转换)
- asp.net npoi 导出excel VS2010 framework 4.0 handler 一般处理程序
- Asp.net导出excel时长数字被科学计数法的解决方案。(身份证长数字作为字符处理)
- asp.net Excel导出及数据格式化处理(摘)
- asp.net导出excel科学计数问题
- Asp.net导出excel时长数字被科学计数法的解决方案。(身份证长数字作为字符处理)
- ASP.NET Export to Excel(导出数据到Excel) & C#导出Excel,某单元格内容长度超过255的处理方法
- ASP.NET导入导出Excel方法大全
- Asp.net导入导出Excel总结
- asp.net 使用Linq 把数据导出到Excel
- asp.net gridview导出到Excel中。
- asp.net导出excel文件方法之一
- 关于asp.net导出Excel
- asp.net GridView导出到Excel代码
- asp.net导出Excel的方法
- Asp.net导出Excel/Csv文本格式数据
- asp.net 将DataTable中的数据导出到Excel并下载方法
- 使用asp.net导出Excel