How could I close Excel file using pywinauto
<p>I'm having a problem that I can't excel file.</p>

<p>I was using swapy+pywinauto.<br>
program export excel file with different name (ex. time..) 
I used swapy to close the export excel.</p>

<pre><code>from pywinauto.application import Application
app = Application().Start(cmd_line=u'"C:\\Program Files\\Microsoft Office\\Office14\\EXCEL.EXE" \\dde')
xlmain = app.XLMAIN
xlmain.Wait('ready')
xlmain.Close()
app.Kill_()
</code></pre>

<p>but got error below.</p>

<pre><code>Traceback (most recent call last):


 File "D:/23007.py", line 54, in &lt;module&gt;
xlmain.Wait('ready')

WaitUntil(timeout, retry_interval, lambda: self.__check_all_conditions(check_method_names))


File "C:\Python35\lib\site-packages\pywinauto\timings.py", line 308, in WaitUntil
raise err

pywinauto.timings.TimeoutError: timed out

Process finished with exit code 1
</code></pre>

<p><a href="http://i.stack.imgur.com/c1BOC.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/c1BOC.jpg" alt="enter image description here"></a></p>

<p>Why do you use <code>app.XLMAIN</code>? Is the title of window similar to <code>XLMAIN</code>? Usually the title is <code>&lt;file name&gt; - Excel</code> so that pywinauto can handle it so: <code>xlmain = app["&lt;file name&gt; - Excel"]</code>.</p>

<p>Obviously <code>Wait('ready')</code> raised an exception because the window with title <code>"XLMAIN"</code> or similar is not found.</p>

<p>Generally I would recommend using pyWin32 standard module <code>win32com.client</code> to work with Excel (through standard COM interface). See the second answer here for example: <a href="http://stackoverflow.com/questions/441758/driving-excel-from-python-in-windows">Driving Excel from Python in Windows</a></p>

python excel pywinauto