Skip to content

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

Closed
@phil20686

Description

@phil20686

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions