'Python 3.8.0 xlwings save fails on windows 7

I am trying the following code: which is failing on winodows 7 with Python 3.8.0 but running successfully on Windows 10 Python 3.8.0

import xlwings as xw
template = "template1.xlsx"

app = xw.App(visible=False)
wb = xw.Book(template)
ws = wb.sheets['warnings']
ws.range('A12').value = "This is a Test"
wb.save(r"D:\Polyspace\test.xlsx")
wb.close()
app.quit()

and I am getting the error:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    wb.save(r"D:\Polyspace\test.xlsx")
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python38\lib\site-packages\xlwings\main.py", line 1065, in save
    self.impl.save(path, password=password)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python38\lib\site-packages\xlwings\_xlwindows.py", line 829, in save
    self.xl.SaveAs(
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python38\lib\site-packages\xlwings\_xlwindows.py", line 95, in __call__
    v = self.__method(*args, **kwargs)
  File "C:\Users\XXX\AppData\Local\Temp\gen_py\3.8\00020813-0000-0000-C000-000000000046x0x1x9.py", line 46571, in SaveAs
    return self._oleobj_.InvokeTypes(3174, LCID, 1, (24, 0), ((12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (3, 49), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)

if I do wb.save(), everything is fine. but if I want to save it to a new file is fails

I have already googled and tried all different solutions. mostly it was suggested to use a full path, but it still fails



Solution 1:[1]

You need to use a backslash not forward:

import xlwings as xw
template = "template1.xlsx"

app = xw.App(visible=False)
wb = xw.Book(template)
ws = wb.sheets['warnings']
ws.range('A12').value = "Peter"
wb.save(r'D:\Polyspace\test.xlsx')
wb.close()
app.quit()

Solution 2:[2]

Try using the normpath method from the os.path module. Your code would look something like this:

import xlwings as xw
import os

template = "template1.xlsx"

app = xw.App(visible=False)
wb = xw.Book(template)
ws = wb.sheets['warnings']
ws.range('A12').value = "This is a Test"

path = os.path.normpath(r'D:/Polyspace/test.xlsx')

wb.save(path)
wb.close()
app.quit()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Batuhan
Solution 2 ruck