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 ;)

3
  • 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. Commented Oct 1, 2018 at 11:18
  • stackoverflow.com/a/47558794/5658251 should help you solve the same.... Commented Oct 1, 2018 at 11:20
  • Thank you Eswar, this solves my problem! Commented Oct 1, 2018 at 11:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.