csharp: Importing or Exporting Data from Worksheets using aspose cell
/// <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的更多相关文章
- 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. ...
- 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 ...
- 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 ...
- 扩增子分析QIIME2-3数据导出Exporting data
# 激活工作环境 source activate qiime2-2017.8 # 建立工作目录 mkdir -p qiime2-exporting-tutorial cd qiime2-exporti ...
- 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 ...
- 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 ...
- abap 通过importing 和 exporting 调用其它函数
1:其它函数的(输入或输出)参数名都在=号左边.
- 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"></ ...
- 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 ...
随机推荐
- 安装与配置 Elasticsearch
环境:centos6.7 #查询已经安装的JDK rpm -qa | grep jdk #卸载 yum -y remove java-1.8.0-openjdk-headless-1.8.0.91- ...
- dsoframer控件学习小结(打开WORD,EXCEL等文件)
根据自己对dsoframer控件的学习,想把dsoframer控件进行简单的包装为C#的usercontrol,大体需要作如下:(创建windows的usercontrol的步骤就不再说了...)我们 ...
- 【NLP】word2vec
http://blog.csdn.net/mytestmy/article/details/26969149?utm_source=tuicool&utm_medium=referral
- [转]一个小试验验证对象的指针计数置为nil的情况
本文转载于新风作浪的博客专栏,博客地址:http://blog.csdn.net/duxinfeng2010/article/details/8757211 以下博客原文: 最近遇到这样一个问题,以前 ...
- Linux监控工具 (Linux Monitor Tools)
最近发现几个好用的工具,顺便总结下. Zabbix和Nagios属于重量级,企业级Service procps-ng: top, free, ps, pgrep, vmstat ... sysstat ...
- ORA-00119: invalid specification for system parameter LOCAL_LISTENER - 转
错误分析 listener 可以正常启动: [oracle@o_target admin]$ cat listener.ora# listener.ora Network Configuration ...
- 【Android】如何实现ButterKnife
如何实现ButterKnife ButterKnife的原理简述 示例代码ButterKnifeProcedure Pluggable Annotation Processing 注解处理器 Java ...
- Android NDK中的C++调试踩坑标记
RT, Android NDK中的C++调试, GDB调试比较麻烦,在ADT Eclipse中: 1.配置好NDK给工程加上Native Support 2.编译中加上NDK_DEBUG=1 3.然后 ...
- 谈一下OOP的乱用现象
很久很久以前写了两篇设计模式乱用的文章,最近心血来潮,突然想写篇OOP乱用. 最近在移植一个旧项目,接手过程很多嘈想吐,开一篇谈一下OOP的乱用. 大多数公司用MVC是为了解耦合,但是这套代码的MVC ...
- unity web player的debug和log信息
win8模式下 unity web player的报错信息在如下目录下:C:\Users\xxx\AppData\Local\Temp\UnityWebPlayer\log 注:目录里的文件可能被隐藏 ...