Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: Printing cells from Excel based on their value
    primarykey
    data
    text
    <p>I want to print some cells from Excel based on the value based on their value. For the most part it is working, but getting an error at the end. Here's what I have so far...</p> <p><strong>this has now been resolved, the working script is below</strong></p> <pre><code>from win32com.client import Dispatch import time, pythoncom xl = Dispatch('Excel.Application') wb = xl.Workbooks.Add(r'X:\HR &amp; IT\IT\LOGS\Dynamics Idle Sessions\Copy of Dynamics Idle Sessions.xlsm') ws = wb.Worksheets(1) xl.Run('Refresh') time.sleep(0.5) idlerow = 6 while idlerow &lt; 32: idletime = ws.Cells(idlerow,3).value user = ws.Cells(idlerow,4).value if idletime is not None: if idletime &gt; 60 and len(user) &gt; 6: print(user,'\thas been logged on to Dynamics for\t',idletime,'\tminutes.') elif idletime &gt; 60 and len(user) &lt;= 6: print(user,'\t\thas been logged on to Dynamics for\t',idletime,'\tminutes.') idlerow += 1 xl.Quit() pythoncom.CoUninitialize() </code></pre> <p>The error I'm getting:</p> <pre><code>"Traceback (most recent call last): File "X:/HR &amp; IT/Ryan/Python Scripts/DynamicsUsersMT60.py", line 15, in &lt;module&gt; if idletime &gt; 60 and len(user) &gt; 6: TypeError: unorderable types: NoneType() &gt; int()" </code></pre> <p>If I set idletime as an int I get the following error:</p> <pre><code>Traceback (most recent call last): File "X:/HR &amp; IT/Ryan/Python Scripts/DynamicsUsersMT60.py", line 13, in &lt;module&gt; idletime = int(ws.Cells(idlerow,3).value) TypeError: int() argument must be a string or a number, not 'NoneType' </code></pre> <p>These errors will only come up <strong>after</strong> the script appears to have run correctly and printed what I need. Little help please?</p> <p>Thanks a lot.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload