The Python Oracle

Open a Workbook with XLWINGS without making it visible

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Digital Sunset Looping

--

Chapters
00:00 Open A Workbook With Xlwings Without Making It Visible
00:50 Answer 1 Score 12
01:03 Accepted Answer Score 11
01:29 Answer 3 Score 3
01:43 Answer 4 Score 2
01:59 Answer 5 Score 0
02:08 Thank you

--

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

--

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)