HDR =はい; Excelのインポート(またはデータベース接続)についてIMEX = 1



Hdr Yes Imex 1 About Excel Import



#region xml driver ---------------------------- /// /// The only thing to note is that if the operating system of the target machine is 64-bit. /// The project needs to be compiled to x86 instead of simply using the default Any CPU. /// /// /// private string GetOleDbConnectionString(string strExcelFileName) { // Office 2007 and below. string strJETConnString = String.Format('Provider=Microsoft.Jet.OLEDB.4.0Data Source={0}Extended Properties='Excel 8.0HDR=NOIMEX=1'', strExcelFileName) // The xlsx extension uses .xlsx string strASEConnXlsxString = String.Format('Provider=Microsoft.ACE.OLEDB.12.0Data Source={0}Extended Properties='Excel 12.0 XmlHDR=NOIMEX=1'', strExcelFileName) // The xls extension is used. string strACEConnXlsString = String.Format('Provider=Microsoft.ACE.OLEDB.12.0Data Source={0}Extended Properties='Excel 8.0HDR=NO'', strExcelFileName) // Other string strOtherConnXlsString = String.Format('Provider=Microsoft.Jet.OLEDB.4.0Data Source={0}Extended Properties='Excel 8.0HDR=NOIMEX=1'', strExcelFileName) //cp string cp_strACEConnXlsString = String.Format('Provider=Microsoft.Ace.OleDb.12.0Data Source={0}Extended Properties='Excel 12.0 HDR=NO IMEX=1'', strExcelFileName) //cp2 string cp_strACEConnXlsString_jet12 = String.Format('Provider=Microsoft.Jet.OleDb.12.0Data Source={0}Extended Properties='Excel 12.0 HDR=NO IMEX=1'', strExcelFileName) //1.[cp2] Try to use ACE written by cp. If no error occurs, use ACE driver. try { System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(cp_strACEConnXlsString_jet12) cn.Open() cn.Close() // Use ACE return cp_strACEConnXlsString } catch (Exception ex) { // Failed to start ACE. string msg = ex.Message } // 2. Try to use ACE written by cp. If no error occurs, use ACE driver. try { System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(cp_strACEConnXlsString) cn.Open() cn.Close() // Use ACE return cp_strACEConnXlsString } catch (Exception ex) { // Failed to start ACE. string msg = ex.Message } // 3. Try using ACE. If no error occurs, use ACE driver. try { System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(strACEConnXlsString) cn.Open() cn.Close() // Use ACE return strACEConnXlsString } catch (Exception ex) { // Failed to start ACE. string msg = ex.Message } // 4. Try to use Jet. If no error occurs, use the Jet driver. try { System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(strJETConnString) cn.Open() cn.Close() // Use Jet return strJETConnString } catch (Exception ex) { // Failed to start Jet. string msg = ex.Message } // 5. Try to use Jet. If no error occurs, use the Jet driver. try { System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(strASEConnXlsxString) cn.Open() cn.Close() // Use Jet return strASEConnXlsxString } catch (Exception ex) { // Failed to start Jet. string msg = ex.Message } // If both ACE and JET fail, JET is used by default. return strOtherConnXlsString } #endregion xml driver ---------------------------- Provider=Microsoft.Jet.OLEDB.4.0Data Source={0}Extended Properties='Excel 8.0HDR=YESIMEX=1'

パラメータHDRの値:
HDR =はい。これは、最初の行がタイトルであり、データとして使用されないことを意味します。 HDR = NOを使用する場合、最初の行がデータとして使用されるタイトルではないことを意味します。システムのデフォルトはYESです
パラメータExcel8.0
Excel8.0はExcel97以降で使用されます
IMEX(IMport EXportモード)設定
IMEXには3つのモードがあります。
0はエクスポートモードです
1はインポートモードです
2はリンクモードです(完全な更新機能)
ここで説明したいのはIMEXパラメーターです。これは、モードが異なれば読み取りと書き込みの動作も異なるためです。
IMEX = 0の場合、「エクスポートモード」です。このモードで開いたExcelファイルは、「書き込み」の目的でのみ使用できます。
IMEX = 1の場合、「インポートモード」であり、このモードで開かれたExcelファイルは「読み取り」目的でのみ使用できます。
IMEX = 2の場合、「リンクモード」です。このモードで開かれたExcelファイルは、「読み取り」と「書き込み」の両方の目的をサポートできます。
意味は次のとおりです。
0 ---出力モード
1 ---入力モード
2 ----リンクモード(完全更新機能)