Hello. I am trying to export two tables from an Access database to excel. I have been able to connect to the database using the code provided. But I have not been able to export the table to excel. I also want to rename the field names that will display in excel (P_UpNumber = Upstream Manhole, P_DownNumber = Downstream Manhole).
<SPAN class="keyword token">import</SPAN> pyodbc
<SPAN class="comment token"># MS Access DB connection</SPAN>
pyodbc<SPAN class="punctuation token">.</SPAN>lowercase <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
conn <SPAN class="operator token">=</SPAN> pyodbc<SPAN class="punctuation token">.</SPAN>connect<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'Driver={Microsoft Access Driver (*.mdb, *.accdb)};'</SPAN> <SPAN class="operator token">+</SPAN>
r<SPAN class="string token">'DBQ=C:\Desktop\PACP.MDB;'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Open cursor and execute SQL</SPAN>
cursor <SPAN class="operator token">=</SPAN> conn<SPAN class="punctuation token">.</SPAN>cursor<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>execute<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'select P_UpNumber, P_DownNumber FROM T_PIPES'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">.</SPAN>fetchall<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Prior to my machine being upgraded to Windows 10, I had code that exported the rows to a csv without field names. But now it does not export it and I do not receive any error messages. My guess is that it has to do with the Access now being 64 Bit. Any help will be much appreciated. Thank you.