The Python Oracle

Open a Workbook with XLWINGS without making it visible

This video explains
Open a Workbook with XLWINGS without making it visible

--

Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping

--

Chapters
00:00 Question
01:15 Accepted answer (Score 4)
01:48 Answer 2 (Score 7)
02:04 Answer 3 (Score 3)
02:22 Answer 4 (Score 2)
02:42 Thank you

--

Full question
https://stackoverflow.com/questions/3899...

Question links:
[http://docs.xlwings.org/en/v0.6.4/api.ht...]: http://docs.xlwings.org/en/v0.6.4/api.ht...
[http://docs.xlwings.org/en/stable/api.ht...]: http://docs.xlwings.org/en/stable/api.ht...

Accepted answer links:
[with xw.App]: https://docs.xlwings.org/en/stable/api.h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #excel #visibility #xlwings

#avk47



ANSWER 1

Score 13


Here is my working code fragment:

    import xlwings

    excel_app = xlwings.App(visible=False)
    excel_book = excel_app.books.open('PATH_TO_YOUR_XLSX_FILE')
    excel_book.save()
    excel_book.close()
    excel_app.quit()



ANSWER 2

Score 3


You can also try:

import xlwings as xw

app = xw.App(visible=False)
book = xw.Book('PATH_TO_YOUR_XLSX_FILE')
sheet = book.sheets('sheetname')
df = sheet.range('A1:D10')
book.close()
app.quit()

#corrected typo




ANSWER 3

Score 2


You could try 'with open', for example

with open ("write.csv", "a", newline='') as file:  
    fields=['score', 'name']                       
    writer=csv.DictWriter(file, fieldnames=fields)
    writer.writerow({'score' : score, 'name' : username})

with open ("write.csv", "r") as file:
    sortlist=[]
    reader=csv.reader(file)
    for i in reader:
        sortlist.append(i)



ANSWER 4

Score 0


This works for me:

import xlwings as xw

app = xw.App(visible=False)
readsheet = xw.Book('FILE_PATH').sheets['Sheet1']
df = pd.DataFrame(readsheet.range('A1', 'Z99').value)