1

I'm processing Excel file with multiple sheets via Pandas (read_excel) and need to get the name of the active sheet. Active sheet contains most recent data and the name convention is subject to "creator's mood". So I cannot use simple reading a sheet by name or index... Is there a way how to do it?

UPDATE (solution): Except xlrd with sheet_visible property proposed in Eswar's link (thank you) I discovered another solution with usage of xlwings library:

import xlwings as xw
wb = xw.Book('myfile.xls')
active_sheet_name = wb.sheets.active.name

=> Python is almighty...in many ways ;)

Lukas
  • 2,034
  • 19
  • 27
  • May be the trick lies in getting to know in which sheet the active cell is? So,, probably a brute for method......read all the sheets and look for the active cell. That should be your active sheet. – Eswar Oct 01 '18 at 11:18
  • https://stackoverflow.com/a/47558794/5658251 should help you solve the same.... – Eswar Oct 01 '18 at 11:20
  • Thank you Eswar, this solves my problem! – Lukas Oct 01 '18 at 11:40

1 Answers1

2

The only solution I see is this:

import pandas as pd

active_sheet = input("Enter the required sheet: ")
df = pd.read_excel(file_with_data, sheet_name = active_sheet)
...

You open the .xlsx file, see what the creator's mood was on that day and how he named the sheet that you need, then simply enter it's name when prompted.

Hope it helps.

Radu
  • 35
  • 7