Aspose.Cells组件可以不依赖excel来导入导出excel文件:

导入:

  1. public static System.Data.DataTable ReadExcel(String strFileName)
  2. {
  3. Workbook book = new Workbook();
  4. book.Open(strFileName);
  5. Worksheet sheet = book.Worksheets[0];
  6. Cells cells = sheet.Cells;
  7. return cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
  8. }
public static System.Data.DataTable ReadExcel(String strFileName)
{
Workbook book = new Workbook();
book.Open(strFileName);
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells; return cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
}

导出:

  1. private static void Export<T>(IEnumerable<T> data, HttpResponse response)
  2. {
  3. Workbook workbook = new Workbook();
  4. Worksheet sheet = (Worksheet)workbook.Worksheets[0];
  5. PropertyInfo[] ps = typeof(T).GetProperties();
  6. var colIndex = "A";
  7. foreach (var p in ps)
  8. {
  9. sheet.Cells[colIndex + 1].PutValue(p.Name);
  10. int i = 2;
  11. foreach (var d in data)
  12. {
  13. sheet.Cells[colIndex + i].PutValue(p.GetValue(d, null));
  14. i++;
  15. }
  16. colIndex = ((char)(colIndex[0] + 1)).ToString();
  17. }
  18. response.Clear();
  19. response.Buffer = true;
  20. response.Charset = "utf-8";
  21. response.AppendHeader("Content-Disposition", "attachment;filename=xxx.xls");
  22. response.ContentEncoding = System.Text.Encoding.UTF8;
  23. response.ContentType = "application/ms-excel";
  24. response.BinaryWrite(workbook.SaveToStream().ToArray());
  25. response.End();
  26. }
private static void Export<T>(IEnumerable<T> data, HttpResponse response)
{
Workbook workbook = new Workbook();
Worksheet sheet = (Worksheet)workbook.Worksheets[0]; PropertyInfo[] ps = typeof(T).GetProperties();
var colIndex = "A"; foreach (var p in ps)
{ sheet.Cells[colIndex + 1].PutValue(p.Name);
int i = 2;
foreach (var d in data)
{
sheet.Cells[colIndex + i].PutValue(p.GetValue(d, null));
i++;
} colIndex = ((char)(colIndex[0] + 1)).ToString();
} response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=xxx.xls");
response.ContentEncoding = System.Text.Encoding.UTF8;
response.ContentType = "application/ms-excel";
response.BinaryWrite(workbook.SaveToStream().ToArray());
response.End();
}

非常简单,好用!

 
 
http://blog.csdn.net/weiky626/article/details/7514637

(C#)利用Aspose.Cells组件导入导出excel文件的更多相关文章

  1. 【转】 (C#)利用Aspose.Cells组件导入导出excel文件

    Aspose.Cells组件可以不依赖excel来导入导出excel文件: 导入: public static System.Data.DataTable ReadExcel(String strFi ...

  2. aspose.cells根据模板导出excel

    又隔十多天没写博客了,最近都在忙项目的事情,公司人事变动也比较大,手头上就又多了一个项目.最近做用aspose.cells根据模板导出excel报价单的功能,顺便把相关的核心记下来,先上模板和导出的效 ...

  3. ASP.NET Core导入导出Excel文件

    ASP.NET Core导入导出Excel文件 希望在ASP.NET Core中导入导出Excel文件,在网上搜了一遍,基本都是使用EPPlus插件,EPPlus挺好用,但商用需要授权,各位码友若有好 ...

  4. C# -- 使用Aspose.Cells创建和读取Excel文件

    使用Aspose.Cells创建和读取Excel文件 1. 创建Excel Aspose.Cells.License li = new Aspose.Cells.License(); li.SetLi ...

  5. 导入导出Excel文件

    搭建环境 先新建web project ,然后Add Struts Capabilties: 下载导入导出Excel所需的jar包: poi-3.8-20120326.jar包  :  http:// ...

  6. 基于C#语言MVC框架Aspose.Cells控件导出Excel表数据

    控件bin文件下载地址:https://download.csdn.net/download/u012949335/10610726 @{ ViewBag.Title = "xx" ...

  7. java利用Aspose.cells.jar将本地excel文档转化成pdf(完美破解版 无水印 无中文乱码)

    下载aspose-cells-8.5.2.jar包 http://pan.baidu.com/s/1kUBzsQ7 JAVA代码 package webViewer; import java.io.* ...

  8. C# 利用Aspose.Cells .dll将本地excel文档转化成pdf(完美破解版 无水印 无中文乱码)

    Aspose.Cells .dll下载  http://pan.baidu.com/s/1slRENLF并引用 C#代码 using System; using System.Collections. ...

  9. java导入导出Excel文件

    package poi.excel; import java.io.IOException; import java.io.InputStream; import java.io.OutputStre ...

随机推荐

  1. jquery获得select的文本

    本来以为jQuery("#select1").val();是取得选中的值, 那么jQuery("#select1").text();就是取得的文本. 这是不正确 ...

  2. Lucene全文搜索 分组,精确查找,模糊查找

    http://zm603380946.iteye.com/blog/1827318 完全个人理解,如有更好的方法,欢迎一起讨论 LuceneUtils.java package com.zbiti.l ...

  3. HBase Coprocessor 剖析与编程实践(转载http://www.cnblogs.com/ventlam/archive/2012/10/30/2747024.html)

    HBase Coprocessor 剖析与编程实践 1.起因(Why HBase  Coprocessor) HBase作为列族数据库最经常被人诟病的特性包括:无法轻易建立“二级索引”,难以执行求和. ...

  4. ElasticSearch — 集群搭建

    1.es需要java环境,故先检查java环境是否正常 2.下载elasticsearch安装包 http://www.elasticsearch.org/download/ 目前最新版本到1.4.0 ...

  5. eclipse,android Localization (Internationalization) 安卓本地化(国际化)

    1.创建新的资源文件,名字保持一致.提示"已存在",继续. 2.使用“语言”作为识别器,然后选择相应的语言代码.Tips:其他的适配,如国家.屏幕大小等,也是通过这里的识别器实现适 ...

  6. fzu Problem - 2232 炉石传说(二分匹配)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...

  7. 基于IDL 的WebRS系统设计图

    图1 用例图 图2 结构图

  8. ubuntu上的mysql数据库双机备份设置

    配置环境: myslq 5.5.3 + ubuntu server 12.04 一.配置MySQL主服务器(192.168.0.1) 1.增加一个账号专门用于同步 1 mysql>grant r ...

  9. NYOJ 925 国王的烦恼

    从最后一天开始往前加边. 同一天的边同时加到图上,加完之后检查集合数量是否和没加之前有变化. 有变化的话,答案就+1. #include<cstdio> #include <iost ...

  10. Java的SSH框架

    SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架.   1.业务流程  集成SSH框架的系统从职责上分为四层:表示层.业务逻辑层.数据 ...