楼主都会玩数据库了,怎么还连xls文件与文本文件都分不清楚?
file1.xls只是文本文件;file2.xls才是正宗的xls文件,而且列名称不是ZINC_ID而是Molecule。- @set @n=0//&cscript.exe -e:jscript "%~f0"&pause&exit/b
-
- f1 = "file1.xls";
- f2 = "file2.xls";
-
- fso = new ActiveXObject("Scripting.FileSystemObject");
- csv = fso.GetBaseName(f1) + ".csv";
- fso.MoveFile(f1, csv);
- ts = fso.OpenTextFile("Schema.ini", 2, true);
- ts.WriteLine("["+csv+"]\r\nFormat=TabDelimited\r\n"); ts.Close();
-
- strConnect = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source="' + '.'
- + '";Extended Properties="text;FMT=Delimited;HDR=yes;";';
- strQuery = "SELECT a.* from ["+csv+"] as a "
- + " inner join (select Molecule from [查询1$]"
- + " in '' [Excel 8.0;IMEX=1;HDR=yes;DATABASE="+f2+";]) as b "
- + " ON (a.[ZINC_ID]=b.[Molecule])";
- AdoCnn = new ActiveXObject("ADODB.Connection");
- AdoCnn.Open(strConnect);
- AdoRs = AdoCnn.Execute(strQuery);
- s = AdoRs.GetString(2, -1, ",", "\r\n");
- AdoCnn.Close();
-
- fso.OpenTextFile('result.csv', 2, true).write(s);
- fso.MoveFile(csv, f1);
- fso.DeleteFile("Schema.ini");
复制代码
|