标签:winform excel oledb hdr imex
最近在用C#写一个创建Excel并将数据导出到Excel的WinForm程序,
参数HDR的值:
string strConn = "Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;" + "data source=" + @excelPath + ";Extended Properties=‘Excel 12.0; HDR=yes; IMEX=2‘"; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = strConn;但是事实并非如此,当执行Insert Into语句时却出现异常:“操作必须使用一个可更新的查询”!
FileInfo fi = new FileInfo(excelPath); System.Security.AccessControl.FileSecurity fileSecurity = fi.GetAccessControl(); fileSecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); fileSecurity.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow)); fi.SetAccessControl(fileSecurity); DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(excelPath)); System.Security.AccessControl.DirectorySecurity dirSecurity = di.GetAccessControl(); dirSecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); dirSecurity.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow)); di.SetAccessControl(dirSecurity);
关于OleDB连接Excel的Extended Properties(扩展属性)HDR=YES; IMEX=2个人理解心得,布布扣,bubuko.com
关于OleDB连接Excel的Extended Properties(扩展属性)HDR=YES; IMEX=2个人理解心得
标签:winform excel oledb hdr imex
原文地址:http://blog.csdn.net/testcs_dn/article/details/25496155