Note that there are some explanatory texts on larger screens.

plurals
  1. POexcel access denied with win32 python pywin32
    primarykey
    data
    text
    <p>My code is </p> <pre><code>#Opens template for creating final report excel = win32.dynamic.Dispatch('Excel.Application') template = os.path.abspath((folderpath+'\Poop.xlsx')) wb = excel.Workbooks.Open(template) freshws= wb.Sheets("Fresh") #Sheet names must match perfectly secws= wb.Sheets("sec") cur.execute("Select * from FIRALL") freshdata=list(cur.fetchall()) #writes to the first sheet datarowlen=0 for i,a in enumerate(freshdata): datarowlen = len(a) for j,b in enumerate(a): freshws.Cells(i+1,j+1).Value = a[j] cur.execute("Select * from SECVE") secdata=list(cur.fetchall()) #writes to the second sheet datarowlen=0 for i,a in enumerate(secdata): datarowlen = len(a) for j,b in enumerate(a): secws.Cells(i+1,j+1).Value = a[j] #saves the report wb.SaveAs() wb.Close() </code></pre> <p>The error i get when I run my code is</p> <pre><code>Traceback (most recent call last): File "main.py", line 369, in &lt;module&gt; wb = excel.Workbooks.Open(template) File "&lt;COMObject &lt;unknown&gt;&gt;", line 8, in Open pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel' , "Microsoft Excel cannot access the file 'path to stuff------------------------ Poop Report\\Poop.xlsx'. There are several possible reasons:\n\n\u2022 The file name or path does not exist.\n\u2022 The file is being used by another program.\ n\u2022 The workbook you are trying to save has the same name as a currently ope n workbook.", 'xlmain11.chm', 0, -2146827284), None) </code></pre> <p>I get a popup dialog saying access is denied. The file isn't readonly and I'm the owner of the workbook its trying to open. I've tried</p> <pre><code>win32.gencache.EnsureDispatch('Excel.Application') </code></pre> <p>I still get the same error. Is there something I'm missing? I switched to dynamic thinking late-binding would solve this error.</p> <p>another error I had was Pywins -2147418111 error when I was trying to fix this code.</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