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 ...
随机推荐
- 图片上传代码(C#)
//上传 protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.Ha ...
- Spring3系列5-Bean的基本用法
Spring3系列5-Bean的基本用法 本篇讲述了Bean的基本配置方法,以及Spring中怎样运用Bean. 主要内容如下: 一. Spring中Bean的相互引用 二. Sp ...
- asp.net MVC 自动下载apk
在Asp.net MVC中直接把.apk文件放入/Upload/App/ 路径下,然后通过IIS发布完之后,再通过http://xxx/Upload/App/xx.apk访问是访问不到的,因此不能下载 ...
- Linux设备驱动剖析之Input(四)
static void input_pass_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) ...
- Spark源码系列(七)Spark on yarn具体实现
本来不打算写的了,但是真的是闲来无事,整天看美剧也没啥意思.这一章打算讲一下Spark on yarn的实现,1.0.0里面已经是一个stable的版本了,可是1.0.1也出来了,离1.0.0发布才一 ...
- 解决play-1.4.0在linux或mac下提示No such file or directory的问题
问题原因:"play"脚本中有特殊符号. 解决方案:写脚本去掉即可. 代码:fixplay.py 放在play-1.4.0目录下执行.亲测在osx与ubuntu下均可用. with ...
- C#壓縮文件幫助類 使用ICSharpCode.SharpZipLib.dll
using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; using System; using Syst ...
- 本人独立博客:http://www.zjmainstay.cn
为了方便各种管理,本人创建了独立博客,博客地址:http://www.zjmainstay.cn 欢迎新老朋友围观.
- BZOJ 1251 序列终结者(Splay)
题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技术 ...
- There is no mode by that name loaded / mode not given 产生原因(个案)
使用jQM DateBox用于界面显示日期选择控件,结果发现之前是正常的.今天用就不行啦.提示There is no mode by that name loaded / mode not given ...