<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Open, Refresh Connections, Save, and Close Excel File in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353837#M27775</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nothing else...script works well...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unless you can convince my IT dept to give my username sufficient privileges to execute scheduled tasks from my machine &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Aug 2014 13:40:26 GMT</pubDate>
    <dc:creator>mpboyle</dc:creator>
    <dc:date>2014-08-07T13:40:26Z</dc:date>
    <item>
      <title>Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353832#M27770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We have data in an Excel spreadsheet that is linked to a web xml file.&amp;nbsp; This data contains lat/long positions which we use to convert the data into a feature class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already have a script created that will convert the data to a feature class, but to update the data within the spreadsheet, I need to manually open the Excel file, refresh all the data connections (4 different worksheets), save, and close.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm pretty new to python and am looking for a way to automate the process of opening, refreshing all data connections, saving, and closing an Excel file in order to fully automate this process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have a python example of opening, refreshing data connections, saving, and closing an Excel file?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 19:22:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353832#M27770</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2014-08-04T19:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353833#M27771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Updating Excel spreadsheets can be tricky, in part due to the particulars of the Excel file format. That said, since the 10.2 release, you can use the xlrd and xlwt python modules to read and write Excel spreadsheets. You can combine these two existing modules with an additional module, xlutils, as is shown in this example:&lt;/P&gt;&lt;P&gt; &lt;A href="http://stackoverflow.com/a/2726298" title="http://stackoverflow.com/a/2726298"&gt;python - writing to existing workbook using xlwt - Stack Overflow&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Depending on what you're doing, you may have an easier time just writing a new spreadsheet with xlwt alone, which ships with ArcGIS, and using some semantic naming to track which spreadsheet is the current iteration.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Aug 2014 15:50:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353833#M27771</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2014-08-05T15:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353834#M27772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matthew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The two mentioned modules are excellent, and I use them when needed to traverse excel and making edits or new sheets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The deeper you want to manage your excel assets will make it more cumbersome; i.e. a new MODULE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For what you want to accomplish you are going to need to access the application, or atleast that is what I have done in the past.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://sourceforge.net/projects/pywin32/files/" title="http://sourceforge.net/projects/pywin32/files/" rel="nofollow noopener noreferrer" target="_blank"&gt;Python for Windows extensions -&amp;nbsp; Browse Files at SourceForge.net&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="kwd" style="color: #00008b; background: transparent;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt; win32com&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;client
&lt;/SPAN&gt;&lt;/CODE&gt;



&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;xl = win32com&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;client&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af; background: transparent;"&gt;DispatchEx&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str" style="color: #800000; background: transparent;"&gt;"Excel.Application"&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;



&lt;/PRE&gt;&lt;P&gt;You will need to access Excel so you can so you can refresh your connections.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;wb = xl&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;workbooks&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;open&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str" style="color: #800000; background: transparent;"&gt;"***YOUR EXCEL FILE LOCATION***"&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;
xl&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af; background: transparent;"&gt;Visible&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt; &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b; background: transparent;"&gt;True
&lt;/SPAN&gt;&lt;/CODE&gt;



&lt;/PRE&gt;&lt;P&gt;Next call the refresh all()&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt; &lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;wb&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af; background: transparent;"&gt;RefreshAll&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;()&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;Next of course save.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af; background: transparent;"&gt;wb.Close&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;savechanges&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="lit" style="color: #800000; background: transparent;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;
xl&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af; background: transparent;"&gt;Quit&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;()&lt;/SPAN&gt;&lt;/CODE&gt;



&lt;/PRE&gt;&lt;P&gt;In addition to save and close.&lt;/P&gt;&lt;P&gt;If you need to run a macro, but you shouldn't need to for refreshing.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;xl&lt;/SPAN&gt;&lt;SPAN class="pun" style="background: transparent;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="background: transparent;"&gt;run('**MACROFILE LOCATION*** !macro')&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353834#M27772</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2021-12-11T16:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353835#M27773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/26032"&gt;Todd Ulery&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found the python for windows extensions and that seems to have done what I was after.&amp;nbsp; Below is a sample of the script I'm using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14072654678786246" jivemacro_uid="_14072654678786246" modifiedtitle="true"&gt;
&lt;P&gt;from win32com.client import Dispatch&lt;/P&gt;
&lt;P&gt;xl = Dispatch('Excel.Application')&lt;/P&gt;
&lt;P&gt;wb = xl.Workbooks.Open(r'...path to file...')&lt;/P&gt;
&lt;P&gt;wb.RefreshAll()&lt;/P&gt;
&lt;P&gt;wb.Close(True)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like I said, this seems to have worked for me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Aug 2014 19:07:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353835#M27773</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2014-08-05T19:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353836#M27774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Script looks good, was there anything else?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 17:20:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353836#M27774</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-08-06T17:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353837#M27775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nothing else...script works well...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unless you can convince my IT dept to give my username sufficient privileges to execute scheduled tasks from my machine &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 13:40:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353837#M27775</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2014-08-07T13:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353838#M27776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would be as well interested in how to convince IT people and sys admins &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 13:44:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353838#M27776</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2014-08-07T13:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Open, Refresh Connections, Save, and Close Excel File</title>
      <link>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353839#M27777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think we might all suffer from this dilemma. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/confused.png" /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 13:46:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/open-refresh-connections-save-and-close-excel-file/m-p/353839#M27777</guid>
      <dc:creator>ToddUlery</dc:creator>
      <dc:date>2014-08-07T13:46:56Z</dc:date>
    </item>
  </channel>
</rss>

