/// <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. 使用golang 开发的 andriod应用

    最近在捣鼓一个东东,就是使用golang开发andriod应用.说起来简单操作起来还挺麻烦,中间又学习了很多东西.比如ubuntu,docker,angular,ionic,jquery mobile ...

  2. Intellij idea 乱码问题(英文操作系统)

    英文操作系统导致 Debug 下的变量查看时显示乱码,可通过改变字体解决此问题.

  3. Oracle 11g RAC客户端使用SCAN IP无法连接问题

    Oracle 版本:11.2.0.1.0 客户端:Windows Server 2003/PLSQL Developer Oracle服务器端的ip设置如下: ##公网ip 192.168.135.2 ...

  4. [Android界面] 这样的选择器怎么实现?? 充值选择

    1  充值的或年纪的 或  1 先讲例子 http://blog.csdn.net/lmj623565791/article/details/48393217: 本文出自:[张鸿洋的博客] 一.概述 ...

  5. SQL语句 - 基本查询

    select select_list [ into new_table ] from table_source [ where search_condition ] [ group by broup_ ...

  6. sys.stdout sys.stderr的用法

    stdout:标准输出 stderr:标准错误 print  相当于 sys.stdout.write() + 换行 一个将数据流写入文件的程序,文件名为:main.py def main(out=s ...

  7. struts2 using kindeditor upload pictures (including jmagic compressed images)

    Project uses a kindeditor3.4 UploadContentImgAction @SuppressWarnings("serial") @ParentPac ...

  8. Understanding apps: mobile, native or responsive

    Background Maybe you have decided to get an app built. You will not build it yourself (obviously!) s ...

  9. 队列queue的C实现

    头文件—————————————————————————————— #ifndef _QUEUE_H_ #define _QUEUE_H_ #include <stdlib.h> #def ...

  10. java正则表达式小练习(IP地址检测、排序,叠词的处理,邮件地址的获取)

    import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.reg ...