1. /// <summary>
  2. /// 涂聚文
  3. /// 20150728
  4. /// EXCEL win7 32位,64位OK
  5. /// </summary>
  6. public class ExcelHelperImport
  7. {
  8.  
  9. /*
  10. http://www.cnblogs.com/wangrsh2010/archive/2012/03/21/2410182.html
  11. * http://npoi.codeplex.com/SourceControl/latest
  12. * http://sourceforge.net/projects/myxls/
  13. http://svn.code.sf.net/p/myxls/code/trunk myxls-code
  14. */
  15.  
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. /// <param name="strFileName"></param>
  20. /// <param name="inumber"></param>
  21. /// <returns></returns>
  22. public static System.Data.DataTable ReadExcel(String strFileName,int inumber)
  23. {
  24. Workbook book = new Workbook();
  25. book.Open(strFileName); //过时
  26. Worksheet sheet = book.Worksheets[inumber];
  27. Cells cells = sheet.Cells;
  28. return cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
  29. }
  30. /// <summary>
  31. /// geovindu
  32. /// </summary>
  33. /// <param name="strFileName"></param>
  34. /// <param name="num"></param>
  35. /// <returns></returns>
  36. public static DataTable ImportExcel(string strFileName, int num)
  37. {
  38. Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(strFileName);
  39.  
  40. ////Creating a file stream containing the Excel file to be opened
  41. //FileStream fstream = new FileStream(strFileName, FileMode.Open);
  42. ////Instantiating a Workbook object
  43. ////Opening the Excel file through the file stream
  44. //Workbook workbook = new Workbook(fstream);
  45.  
  46. //Accessing the first worksheet in the Excel file
  47. Worksheet worksheet = workbook.Worksheets[num];
  48. Cells cells = worksheet.Cells;
  49. //Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable
  50. //DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, 7, 2, true);
  51. DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, cells.MaxDataRow+1 , cells.MaxDataColumn+1 , false);
  52. //fstream.Close();
  53. return dataTable;
  54.  
  55. }
  56.  
  57. /// <summary>
  58. /// geovindu 涂聚文
  59. /// </summary>
  60. /// <typeparam name="T"></typeparam>
  61. /// <param name="data"></param>
  62. /// <param name="response"></param>
  63. private static void Export<T>(IEnumerable<T> data, HttpResponse response,string filename)
  64. {
  65. Workbook workbook = new Workbook();
  66. Worksheet sheet = (Worksheet)workbook.Worksheets[0];
  67.  
  68. PropertyInfo[] ps = typeof(T).GetProperties();
  69. var colIndex = "A";
  70.  
  71. foreach (var p in ps)
  72. {
  73.  
  74. sheet.Cells[colIndex + 1].PutValue(p.Name);
  75. int i = 2;
  76. foreach (var d in data)
  77. {
  78. sheet.Cells[colIndex + i].PutValue(p.GetValue(d, null));
  79. i++;
  80. }
  81.  
  82. colIndex = ((char)(colIndex[0] + 1)).ToString();
  83. }
  84.  
  85. response.Clear();
  86. response.Buffer = true;
  87. response.Charset = "utf-8";
  88. response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
  89. response.ContentEncoding = System.Text.Encoding.UTF8;
  90. response.ContentType = "application/ms-excel";
  91. response.BinaryWrite(workbook.SaveToStream().ToArray());
  92. response.End();
  93. }
  94.  
  95. /// <summary>
  96. /// Geovin Du
  97. /// </summary>
  98. /// <param name="dataTable"></param>
  99. /// <param name="fileName"></param>
  100. public static void ExportToExcel(DataTable dataTable, string fileName)
  101. {
  102. HttpContext context = HttpContext.Current;
  103. context.Response.Clear();
  104. foreach (DataColumn column in dataTable.Columns)
  105. {
  106. context.Response.Write(column.ColumnName + ",");
  107. }
  108. context.Response.Write(Environment.NewLine);
  109.  
  110. foreach (DataRow row in dataTable.Rows)
  111. {
  112. for (int i = 0; i < dataTable.Columns.Count; i++)
  113. {
  114. context.Response.Write(row[i].ToString() + ",");
  115. }
  116. context.Response.Write(Environment.NewLine);
  117. }
  118. context.Response.ContentType = "application / ms - excel";
  119. context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
  120. context.Response.End();
  121. }
  122.  
  123. }

  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/

  1. /// <summary>
  2. /// 获取工作表名称
  3. /// </summary>
  4. /// <param name="strFileName"></param>
  5. /// <returns></returns>
  6. private static DataTable getDataSheetName(string strFileName)
  7. {
  8. DataTable dt = new DataTable();
  9. dt.Columns.Add("id", typeof(int));
  10. dt.Columns.Add("name", typeof(string));
  11. // Aspose.Cells.Workbook workbook = new Workbook();//4.0
  12. //workbook.Open(strFileName);//4.0
  13. Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(strFileName);// 7.0
  14. for(int i=0;i<workbook.Worksheets.Count;i++)
  15. {
  16. dt.Rows.Add(i, workbook.Worksheets[i].Name);
  17. }
  18. return dt;
  19. }
  20.  
  21. /// <summary>
  22. /// 获取工作表名称
  23. /// </summary>
  24. /// <param name="strFileName"></param>
  25. /// <param name="com"></param>
  26. public static void getSheetName(String strFileName, System.Windows.Forms.ComboBox com)
  27. {
  28. DataTable dt = getDataSheetName(strFileName);
  29. com.DataSource = dt;
  30. com.DisplayMember = "name";
  31. com.ValueMember = "id";
  32. com.AutoCompleteMode = AutoCompleteMode.Suggest;
  33. com.AutoCompleteSource = AutoCompleteSource.ListItems;
  34. KillExcelProceed();
  35. }
  36.  
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. /// <param name="strFileName">文件</param>
  41. /// <param name="inumber">第几个工作表</param>
  42. /// <returns></returns>
  43. public static System.Data.DataTable ReadExcel(String strFileName, int inumber)
  44. {
  45. Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(strFileName);// 7.0
  46. //Workbook book = new Workbook();
  47. //book.Open(strFileName); // 4.0 过时
  48. //book.Worksheets.Count;
  49. Worksheet sheet = book.Worksheets[inumber];
  50. Cells cells = sheet.Cells;
  51. return cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
  52. }

  

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. 图片上传代码(C#)

    //上传 protected void Button1_Click(object sender, EventArgs e)        {            if (FileUpload1.Ha ...

  2. Spring3系列5-Bean的基本用法

    Spring3系列5-Bean的基本用法 本篇讲述了Bean的基本配置方法,以及Spring中怎样运用Bean. 主要内容如下: 一.      Spring中Bean的相互引用 二.      Sp ...

  3. asp.net MVC 自动下载apk

    在Asp.net MVC中直接把.apk文件放入/Upload/App/ 路径下,然后通过IIS发布完之后,再通过http://xxx/Upload/App/xx.apk访问是访问不到的,因此不能下载 ...

  4. Linux设备驱动剖析之Input(四)

    static void input_pass_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) ...

  5. Spark源码系列(七)Spark on yarn具体实现

    本来不打算写的了,但是真的是闲来无事,整天看美剧也没啥意思.这一章打算讲一下Spark on yarn的实现,1.0.0里面已经是一个stable的版本了,可是1.0.1也出来了,离1.0.0发布才一 ...

  6. 解决play-1.4.0在linux或mac下提示No such file or directory的问题

    问题原因:"play"脚本中有特殊符号. 解决方案:写脚本去掉即可. 代码:fixplay.py 放在play-1.4.0目录下执行.亲测在osx与ubuntu下均可用. with ...

  7. C#壓縮文件幫助類 使用ICSharpCode.SharpZipLib.dll

    using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; using System; using Syst ...

  8. 本人独立博客:http://www.zjmainstay.cn

    为了方便各种管理,本人创建了独立博客,博客地址:http://www.zjmainstay.cn 欢迎新老朋友围观.

  9. BZOJ 1251 序列终结者(Splay)

    题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技术 ...

  10. There is no mode by that name loaded / mode not given 产生原因(个案)

    使用jQM DateBox用于界面显示日期选择控件,结果发现之前是正常的.今天用就不行啦.提示There is no mode by that name loaded / mode not given ...