Skip to content

writer.save() prevents the creation of addtional sheets #11985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phil20686 opened this issue Jan 7, 2016 · 2 comments
Closed

writer.save() prevents the creation of addtional sheets #11985

phil20686 opened this issue Jan 7, 2016 · 2 comments
Labels
API Design Duplicate Report Duplicate issue or pull request IO Excel read_excel, to_excel

Comments

@phil20686
Copy link

When using pd.ExcelWriter, it appears that calling the save method prevents you from subsequently creating new sheets. E.g. see the following test script

import pandas as pd
import numpy as np
import os


if __name__ == "__main__" :
    dates = pd.date_range('20130101', periods=6)
    df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))

    currentpath = os.path.realpath(__file__)
    outputpath = os.path.join(currentpath, "..\\test.xlsx")

    writer = pd.ExcelWriter(outputpath)
    df.to_excel(writer, "thing1")

    writer.save() #if you remove this line it works as expected

    new_sheet = writer.book.add_worksheet("thing2")
    new_sheet.write(1,1,"test")

    print writer.book.sheetnames

    writer.save()
    writer.close()
@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

it appears that engine='xlsxwriter' (the default) does a .close() when saving, while engine='openpyxl' does not (it just saves).

not sure if this is a function of the engine.

you want to adjust the code and see if the test suite still passes? (and this is not tested obviously)

@jreback jreback added API Design IO Excel read_excel, to_excel labels Jan 7, 2016
@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Jan 21, 2019
@WillAyd
Copy link
Member

WillAyd commented Jan 21, 2019

Closing as duplicate of #9145

@WillAyd WillAyd closed this as completed Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Duplicate Report Duplicate issue or pull request IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

3 participants