/// <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. 【Linux】——sleep无法正常休眠

    最近在开发项目的时候遇到一个问题,当使用 sleep(2) 的时候,程序居然没有按照指定的时间去休眠,但是连续执行两次 sleep(2) 的时候,程序可以正常的休眠 2 秒.真是见鬼了.最后查看了以下 ...

  2. magic_quotes_gpc 、 magic_quotes_runtime 、 magic_quotes_sybase 介绍

    一.三个配置项的作用与区别 magic_quotes_gpc 作用:对php服务器端接收的 GET POST COOKIE 的值执行 addslashes() 操作.作用范围是:WEB客户服务端.作用 ...

  3. 微软MVC对架构的一点思考

    毕业即将三年,在学校学习.做毕设一直使用拖控件的 Winform\WebForm,工作后公司采用MVC3架构做项目. 下面使用mvc的个人总结 : 1.架构上分层清晰.便于研发,耦合性好 2.缓存机制 ...

  4. 老鼠跑猫叫主人惊醒c++观察者模式实现

    这个题目算是比较经典的观察者模式了,老鼠作为一个Subject,主动发出跑的动作,紧跟着猫由于老鼠的跑而发出叫声,主人也被惊醒,在这里猫跟主人都是被动的,是观察者角色,代码实现如下: class CS ...

  5. PHP cURL应用实现模拟登录与采集使用方法详解

    对于做过数据采集的人来说,cURL一定不会陌生.虽然在PHP中有file_get_contents函数可以获取远程链接的数据,但是它的可控制性太差了,对于各种复杂情况的采集情景,file_get_co ...

  6. makeJar

    task makeJar(type: Jar) { //指定生成的jar名 baseName 'plugin' //从哪里打包class文件 from('build/intermediates/cla ...

  7. Android Launcher 研究学习

    Launcher是系统启动后第一个启动的程序,是其它应用程序的入口,也就是我们的手机程序的桌面程序; 一.Launcher的定义及构成: <1>通过查看官方提供的Launcher源码可以知 ...

  8. Maximum Entropy Markov Models for Information Extraction and Segmentation

    1.The use of state-observation transition functions rather than the separate transition and observat ...

  9. python 字符串相加

    我们通过操作符号+来进行字符串的相加,不过建议还是用其他的方式来进行字符串的拼接,这样效率高点. 原因:在循环连接字符串的时候,他每次连接一次,就要重新开辟空间,然后把字符串连接起来,再放入新的空间, ...

  10. QCopChannel的用法

    QT提供了很多的进程间通讯的方法,例如共享内存,QProcess等等.但有一种方法是嵌入式端所独有的,那就是Qt Communications Protocol(QCOP)QT通讯协议,这种方法只能用 ...