title: How do I add information to an excel sheet without deleting the rest in Python?
body: <p><strong>Problem</strong></p>
  
  <p>I need to make a python script that can export information to excel sheet without deleting sheets old information or sheets. See Pseudocode</p>
  
  <p><strong>Context:</strong></p>
  
  <p>This function is to be used in conjunction with a web scraper. And should hopefully, be able to extend data to an existing sheet, create a new sheet, and create a new file.</p>
  
  <p>With the help of other questions, I have come really close:
  <a href="https://stackoverflow.com/questions/42370977/how-to-save-a-new-sheet-in-an-existing-excel-file-using-pandas">How to save a new sheet in an existing excel file, using Pandas?</a>
  But I want the possibility to extend on existing sheets.</p>
  
  <p><strong>Pseudocode</strong></p>
  
  <pre><code>def OutputDataToExcel(Filename,Sheetname,df): #df is a pandas dataframe
      If Filename and Sheetname exists:
          extend the Sheetname with df (no header)
      elif Filename exists:
          create new sheet with Sheetname
          add df (with header)
      else:
      create new excelfile with Filename
      create new sheet with Sheetname
      add df (with header)
  </code></pre>
  
  <p><strong>My code so far</strong></p>
  
  <p><em>Some is out commented to focus on the problem</em></p>
  
  <pre><code>import openpyxl
  import pandas as pd
  
  def outputdata(Filename,Sheetname,df):
      #try:
      #will error if file or sheet cannot be found
      #And will extend information to the sheet
      xl1 = pd.read_excel(Filename,Sheetname)
      xl2 = pd.ExcelFile(Filename)
      wb=openpyxl.load_workbook(Filename)
      length = len(xl2.parse(Sheetname))
      writer = pd.ExcelWriter(Filename,sheet_name = Sheetname , engine = "openpyxl")
      df.to_excel(writer,Sheetname, startrow=length+1, index=False, header = None)
      writer.book = wb
  
      writer.save()
      #writer.close()
      #except:
          #try:
              #will error if file cannot be found
              #and will create a new sheet with information
              #wb=openpyxl.load_workbook(Filename)
              #wb.openpyxl.create_sheet(Sheetname)
              #df.to_excel(writer,Sheetname, index=False)
              #writer.save()
              #writer.close()
          #except:
              #writer = pd.ExcelWriter(Filename,sheet_name = Sheetname  , engine = "openpyxl")
              #df.to_excel(writer,Sheetname, index= False)
              #writer.save()
              #writer.close()
  </code></pre>
  
  <p><strong>The result</strong></p>
  
  <p>A new sheet is created with the name Sheetname1 and df is added to this sheet, insted of it being added to Sheetname.
  If I run it again a new sheet named Sheetname2 and df is then added here...</p>
  
  <p>I hope someone can help me, it's my first question so, please respond both with help or critic on how to present the problem.</p>