about OLE DB connecting Excel's Extended properties (extended attributes) Hdr=yes; imex=2 personal understanding of the experience

Source: Internet
Author: User
Tags ole

Recently in C # write a WinForm program that creates Excel and exports the data to Excel.

Let me connect to OLE DB extended properties (extended attributes) of Excel Hdr=yes; Imex=2 has a deep understanding!

Values for the number of parameters of HDR:

Hdr=yes. This means that the first line is the title. Do not use for data, assuming that with Hdr=no, the first row is not a title, as data to use. The system default is Yes
number of references Excel 8.0Use extended Properties=excel for Excel 97 to 2003 version numbers with Excel 8.0,2007 or 2010 12.0 IMEX (IMport EXport mode) settings
There are three modes of IMEX:
0 is Export mode
1 is Import mode
2 is Linked mode (full update capabilities)
What I would like to highlight here is the IMEX, because different patterns represent different reading and writing behaviors:
When Imex=0 is "Export-out mode". The Excel file opened by this mode can only be used for "write" purposes.


When Imex=1 is in "Import Mode". The Excel file opened by this mode can only be used for "read" purposes.
When imex=2 is "connected mode". The Excel file opened in this mode can support both "read" and "write" purposes at the same time.


meaning for example the following:
0---output mode;
1---input mode;
2----link mode (ability to update completely)

According to the description described above. The following connection string should be able to be read by the plugin record:
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;
but that's not the case. An exception occurred when an INSERT INTO statement was executed: "The operation must use an updatable query"! Here's what I need to explain the circumstances of my error: Windows 7,framework 4, 0,microsoft Office 2007,vs2010,c# WinForm; note that C # WinForm programs, not Web applications I just encountered this error when I thought there was no permission, but using administrator is still the same error! Also the following code to add permissions, or the same error:
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);D irectoryinfo di = new DirectoryInfo (Path.getdirectoryname (Excelpath)); System.Security.AccessControl.DirectorySecurity dirsecurity = di. GetAccessControl ();d irsecurity.addaccessrule (New FileSystemAccessRule ("Everyone", Filesystemrights.fullcontrol, Accesscontroltype.allow));d Irsecurity.addaccessrule (New FileSystemAccessRule ("Users"), Filesystemrights.fullcontrol, Accesscontroltype.allow));d I. Setaccesscontrol (dirsecurity);
Or go to search to see how others are solved, but look at the other people to solve the problem, to me here is test do not pass! The question of whether to push or IMEX value, instead of 1. Then change it to 0, Nimah, the miracle has come!  Then, try setting the Imex to 4 or 10. The result is no problem, only 1 and 2 not. It's the rhythm of the pit daddy.

about OLE DB connecting Excel's Extended properties (extended attributes) Hdr=yes; imex=2 personal understanding of the experience

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.