/// <summary>
/// 涂聚文
/// 20150728
/// EXCEL win7 32位,64位OK
/// </summary>
public class ExcelHelperImport
{ /*
http://www.cnblogs.com/wangrsh2010/archive/2012/03/21/2410182.html
* http://npoi.codeplex.com/SourceControl/latest
* http://sourceforge.net/projects/myxls/
http://svn.code.sf.net/p/myxls/code/trunk myxls-code
*/ /// <summary>
///
/// </summary>
/// <param name="strFileName"></param>
/// <param name="inumber"></param>
/// <returns></returns>
public static System.Data.DataTable ReadExcel(String strFileName,int inumber)
{
Workbook book = new Workbook();
book.Open(strFileName); //过时
Worksheet sheet = book.Worksheets[inumber];
Cells cells = sheet.Cells;
return cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
}
/// <summary>
/// geovindu
/// </summary>
/// <param name="strFileName"></param>
/// <param name="num"></param>
/// <returns></returns>
public static DataTable ImportExcel(string strFileName, int num)
{
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(strFileName); ////Creating a file stream containing the Excel file to be opened
//FileStream fstream = new FileStream(strFileName, FileMode.Open);
////Instantiating a Workbook object
////Opening the Excel file through the file stream
//Workbook workbook = new Workbook(fstream); //Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[num];
Cells cells = worksheet.Cells;
//Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable
//DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, 7, 2, true);
DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, cells.MaxDataRow+1 , cells.MaxDataColumn+1 , false);
//fstream.Close();
return dataTable; } /// <summary>
/// geovindu 涂聚文
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <param name="response"></param>
private static void Export<T>(IEnumerable<T> data, HttpResponse response,string filename)
{
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=" + filename + ".xls");
response.ContentEncoding = System.Text.Encoding.UTF8;
response.ContentType = "application/ms-excel";
response.BinaryWrite(workbook.SaveToStream().ToArray());
response.End();
} /// <summary>
/// Geovin Du
/// </summary>
/// <param name="dataTable"></param>
/// <param name="fileName"></param>
public static void ExportToExcel(DataTable dataTable, string fileName)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
foreach (DataColumn column in dataTable.Columns)
{
context.Response.Write(column.ColumnName + ",");
}
context.Response.Write(Environment.NewLine); foreach (DataRow row in dataTable.Rows)
{
for (int i = 0; i < dataTable.Columns.Count; i++)
{
context.Response.Write(row[i].ToString() + ",");
}
context.Response.Write(Environment.NewLine);
}
context.Response.ContentType = "application / ms - excel";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
context.Response.End();
} }

  from: http://www.aspose.com/.net/excel-component.aspx

https://github.com/heavenwing/WeiXinSDK

https://github.com/heavenwing/MyWeChatPublic

https://github.com/geffzhang/opendotnet

https://github.com/jrsoftware/issrc

http://sourceforge.net/projects/ibatisnet/files/ibatisnet/

http://sourceforge.net/projects/nhibernate/files/?source=navbar

http://sourceforge.net/projects/castleproject/files/?source=navbar

https://github.com/castleproject/

 /// <summary>
/// 获取工作表名称
/// </summary>
/// <param name="strFileName"></param>
/// <returns></returns>
private static DataTable getDataSheetName(string strFileName)
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
// Aspose.Cells.Workbook workbook = new Workbook();//4.0
//workbook.Open(strFileName);//4.0
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(strFileName);// 7.0
for(int i=0;i<workbook.Worksheets.Count;i++)
{
dt.Rows.Add(i, workbook.Worksheets[i].Name);
}
return dt;
} /// <summary>
/// 获取工作表名称
/// </summary>
/// <param name="strFileName"></param>
/// <param name="com"></param>
public static void getSheetName(String strFileName, System.Windows.Forms.ComboBox com)
{
DataTable dt = getDataSheetName(strFileName);
com.DataSource = dt;
com.DisplayMember = "name";
com.ValueMember = "id";
com.AutoCompleteMode = AutoCompleteMode.Suggest;
com.AutoCompleteSource = AutoCompleteSource.ListItems;
KillExcelProceed();
} /// <summary>
///
/// </summary>
/// <param name="strFileName">文件</param>
/// <param name="inumber">第几个工作表</param>
/// <returns></returns>
public static System.Data.DataTable ReadExcel(String strFileName, int inumber)
{
Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(strFileName);// 7.0
//Workbook book = new Workbook();
//book.Open(strFileName); // 4.0 过时
//book.Worksheets.Count;
Worksheet sheet = book.Worksheets[inumber];
Cells cells = sheet.Cells;
return cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
}

  

csharp: Importing or Exporting Data from Worksheets using aspose cell的更多相关文章

  1. csharp:asp.net Importing or Exporting Data from Worksheets using aspose cell

    using System; using System.Data; using System.Configuration; using System.Collections; using System. ...

  2. mysql --secure-file-priv is set to NULL.Operations related to importing and exporting data are disabled

    --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabledmy ...

  3. Tutorial: Importing and analyzing data from a Web Page using Power BI Desktop

    In this tutorial, you will learn how to import a table of data from a Web page and create a report t ...

  4. 扩增子分析QIIME2-3数据导出Exporting data

    # 激活工作环境 source activate qiime2-2017.8 # 建立工作目录 mkdir -p qiime2-exporting-tutorial cd qiime2-exporti ...

  5. csharp: ODP.NET,System.Data.OracleClient(.net 4.0) and System.Data.OleDb读取Oracle g 11.2.0的区别

    ODP.NET: 引用: using Oracle.DataAccess; //Oracle g 11.2.0 using Oracle.DataAccess.Client; using Oracle ...

  6. csharp: Procedure with DAO(Data Access Object) and DAL(Data Access Layer)

    sql script code: CREATE TABLE DuCardType ( CardTypeId INT IDENTITY(1,1) PRIMARY KEY, CardTypeName NV ...

  7. abap 通过importing 和 exporting 调用其它函数

    1:其它函数的(输入或输出)参数名都在=号左边.

  8. Csharp: Create Excel Workbook or word from a Template File using aspose.Word 14.5 and aspose.Cell 8.1

    winform: /// <summary> /// /// </summary> /// <param name="sender"></ ...

  9. mysqld: Can't change dir to 'D:\TONG\mysql-5.7.19-winx64\data\' (Errcode: 2 - No such file or directory)

    mysqld: Can't change dir to 'D:\TONG\mysql-5.7.19-winx64\data\' (Errcode: 2 - No such file or direct ...

随机推荐

  1. 解决Win7旗舰版开机后无线网络识别非常慢的问题

    最近电脑开机后WIFI识别和连接非常慢,不知何故.查看百度安全卫士的优化记录,发现其禁用了 Network List Service,将该服务设为自动启动,重启服务后,问题解决.PS:如此优化太可恶!

  2. 1.什么是泛型和C#中泛型在Class上的实现

    阅读目录 一:什么是泛型? 二:C#中泛型在Class上的实现   一:什么是泛型? 我们在编程的时候需要一个数据类型,但是在刚开始的时候还不确定这个数据类型是怎么样的,或者说对于不同的多个数据类型有 ...

  3. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】【实验一】流水灯模块

    实验一:流水灯模块 对于发展商而言,动土仪式无疑是最重要的任务.为此,流水灯实验作为低级建模II的动土仪式再适合不过了.废话少说,我们还是开始实验吧. 图1.1 实验一建模图. 如图1.1 所示,实验 ...

  4. [AX2012]Report data provider调试

    运行使用RDP作为数据源的报表时,RDP类被编译成.NET的服务调用,RDP是X++的代码,它的调试是在MorphX调试器中完成.要在MorphX调试器中调试RDP的X++代码需要以下配置: 添加AO ...

  5. SOA架构改造简单记录

    前端支持PC.Mobile.H5三个平台 nginx做负载均衡,主备机,keepalived,检测脚本,master和slave切换时完成相关工作: web做集群,web仅仅是web,与后端服务模块采 ...

  6. 网络存储-Samba、NAS---未知的用户名或错误密码

    项目中的文件需要保存到网络存储设备中,之前用的是NAS.因没来得及采购就先用Samba顶上.代码发现通用…… 一.定义: Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器 ...

  7. 解决Visual Studio 2010新建工程时出现『1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt』错误

    VS2010在经历一些更新后,建立Win32 Console Project时会出"error LNK1123" 错误.   解决方案为: 第一步:将:项目|项目属性|配置属性|清 ...

  8. IOS实现中间凸起圆形TabBar

    中间凸起的圆形TabBar曾经比较流行,类似于闲鱼之类的APP就使用了中间凸起TabBar,这两天自己动手实现了一个,效果图如下: 大致原理:重写UITabBar和UITabBarController ...

  9. C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件)的解决方法

    最近在做项目的时候需要操作ftp进行文件的上传下载,但在调用using (var response = (FtpWebResponse)FtpWebRequest.GetResponse())的时候总 ...

  10. react-native SyntaxError xxxxx/xx.js:Unexpected token (23:24)

    在运行react-native项目时提示 SyntaxError xxxxx/xx.js:Unexpected token (23:24) 我这边的问题原因:jsx语法错误,解决办法就是认真排查代码然 ...