Add a sheet into existing excel file

I want to add a sheet to existing excel file. How can I do that? I am working on one selenium project and I want to add all of my automation result sheets into single excel file. Right now I am able to create new excel file for each sheet.

  • Automail email data being exported to Excel, and viceversa
  • openpyxl 2.4.2: cell value generated by formula empty after saving
  • Doing an array formula lookup
  • Excel vba, compare rows of two workbooks and replace
  • Transfering specific data from one workbook to another
  • Copy email subject in outlook to excel using vba with two email address?
  • Insert Specified Number of Rows on Specified Date Column Change
  • Returning multiple values with INDEX array formula
  • phpexcel not reading sheet correctly
  • Combining CSV Files into one master file and keep the file name in the Column 2
  • Parsing Text Out of Cell in Excel
  • PHPExcel: won't read file, only when I first download it, put it in excel and put it back on the server
  • 3 Solutions collect form web for “Add a sheet into existing excel file”

    If you use Apache POI from Java:

    To open an existing sheet or to create a new sheet respectively:

    final File file = "/tmp/sheet.xls";
    final HSSFWorkbook workbook;
    if (file.exists() == false) {
      System.out.println("Creating a new workbook '" + file + "'");
      workbook = new HSSFWorkbook();
    } else {
      System.out.println("Appending to existing workbook '" + file + "'");
      final InputStream is = new FileInputStream(file);
      try {
        workbook = new HSSFWorkbook(is);
      } finally {

    To check whether a sheet exists in order to create a unique sheet name, you could use something like this:

    int sheetIndex = 1;
    while (workbook.getSheet("Sheet " + sheetIndex) != null) {

    then you can add a sheet by calling createSheet:

    HSSFSheet sheet = workbook.createSheet("Sheet " + sheetIndex);

    In this case the sheet names are “Sheet 1”, “Sheet 2”, etc.

    From VBA, with the proper workbook activated:


    (when automating, it is best to be specific)

    You need to maintain a reference to this new worksheet. In VBA this would be

    Set wsRef = Worksheets.Add
    MS Excel Spreadsheet is the best Office Software, Excel VBA and Excel Formulas make Spreadsheet work faster.