the list of sheet names is empty

Issue #868 invalid
John Matecsa created an issue

Test code: from openpyxl import Workbook wb = Workbook() wb.save('test.xlsx') wb = Workbook('test.xlsx') print ('test1', wb.sheetnames) for sheet in wb: print('test2', sheet.title)

Console Output: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/matecsaj/Projects/bearpaw-catalog-fixer/main.py test1 []

Expected Result: print the name of the sheet which according to LibreOffice is 'Sheet'

pip3 list: openpyxl (2.4.8)

Comments (6)

  1. John Matecsa reporter

    I took a second look at things today and came to realize that that my report was unclear. Please ignore my orginal report and take a fresh look at the following.

    Code: from openpyxl import Workbook from openpyxl import load_workbook wb1 = Workbook() print('test1', wb1.sheetnames) wb1.save('test.xlsx') wb2 = load_workbook('test.xlsx') print('test2', wb2.sheetnames) wb3 = Workbook('test.xlsx') print('test3', wb3.sheetnames)

    Console: test1 ['Sheet'] test2 ['Sheet'] test3 []

    In my odd little mind the following aught to accomplish the same thing by they don't, as demonstrated by the 3rd test.

    wb = load_workbook('test.xlsx') wb = Workbook('test.xlsx')

    I humbly suggest that either they be made equivalent or that the latter return an error.

  2. Jacob Scherber

    formatting (use the <> button when putting code into comments):

    from openpyxl import Workbook 
    from openpyxl import load_workbook 
    wb1 = Workbook()
    print('test1', wb1.sheetnames)
    wb1.save('test.xlsx')
    wb2 = load_workbook('test.xlsx')
    print('test2', wb2.sheetnames)
    wb3 = Workbook('test.xlsx')
    print('test3', wb3.sheetnames)
    
  3. CharlieC

    The report hasn't changed: you're not using the library correctly. While I can understand what you want: to be able to pass in the path of a file to the Workbook constructor, that isn't the way the library works. Not only would this be a bit tricky to implement, it could introduce more confusion: do you pass in the name of the workbook to open or under which it should be saved. It would also allow potentially contradictory flags read_only and write_only to be set at the same time.

  4. Log in to comment