摘要: //遍历文件 static List<string> TraversalFile(string filePath,string fileExtension) { List<string> returnList = new List<string>(); if (Directory.Exists(filePath) == true) { DirectoryInfo theFolder = new DirectoryInfo(filePath); var fileItem = from file in theFolder.GetFiles() where fil 阅读全文
posted @ 2012-05-17 15:46 任锋 阅读(481) 评论(0) 推荐(0) 编辑
摘要: 1 引言 在应用程序的设计中,经常需要读取Excel数据或将Excel数据导入转换到其他数据载体中,例如将Excel数据通过应用程序导入SQL Sever等数据库中以备使用。笔者在开发“汽车产业链ASP协同商务平台”中遇到了类似需求。某汽车整车生产企业需要将其车辆发车信息发布到汽车产业链平台上去,其数据为内部ERP系统生成的Excel数据表,用户首先将该数据表上传至汽车产业链平台,平台将此Excel数据读取导入到平台内部的SQL Sever数据库中,以供其它应用使用。汽车产业链平台的开发使用的开发工具为VS.NET,使用的语言是C#,在开发的过程中发现使用Microsoft.Jet.OLE.. 阅读全文
posted @ 2012-05-17 15:41 任锋 阅读(281) 评论(0) 推荐(0) 编辑
摘要: public DataSet ExcelToDataSet(string filename) { try { string strConn; // IMEX=1 可把混合型作为文本型读取,避免null值 strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1'"; OleDbConnection OleConn = new OleDbConnection( 阅读全文
posted @ 2012-05-17 15:32 任锋 阅读(2680) 评论(1) 推荐(0) 编辑
摘要: private void ProtectCellContents(){ if (!this.ProtectContents) { if (DialogResult.Yes == MessageBox.Show("Cell contents in this " + "worksheet are not protected. Protect cell contents?", "Example", MessageBoxButtons.YesNo)) { // Protect cell cont... 阅读全文
posted @ 2012-05-17 15:04 任锋 阅读(794) 评论(0) 推荐(0) 编辑
摘要: 对Excel操作时,由于使用权限的不同,可能对表格的操作权限也不一样。EXCEL提供了保护工作表以及允许编辑单元格功能。相应的在C#中就可以对Excel表格进行操作。主要用Protect()方法保护工作表,Worksheet.Protection.AllowEditRanges设置允许编辑的单元格。下面的代码示例演示如何实现对EXCEL进行保护的操作。public void CreateExcel() { //创建一个Excel文件 Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop 阅读全文
posted @ 2012-05-17 15:01 任锋 阅读(513) 评论(0) 推荐(0) 编辑
摘要: 打开一个工作簿。expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)expression 必选。该表达式返回一个 Workbooks 对象。FileName String 类型,必需。要打开的工作簿的文件名。UpdateLinks Variant 类型,可选。指定文件中链接 阅读全文
posted @ 2012-05-17 15:00 任锋 阅读(290) 评论(0) 推荐(0) 编辑