#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    26
    Rep Power
    0

    Unhappy no suitable constructor error XSSFWorkbook


    Hi Guys,

    All code examples I try I get the same error trying to update spreadsheet in java. I have imported all required jars. Here is a code example I'm trying to get to work but this line giving me error in all examples
    Code:
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    Here is full code below:
    Code:
    package copysheet2;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    
    public class Quora {
     // Excel file path
     public static final String XLS_FILE_PATH = "C:\\Users\\Example.xlsx";
    public static void main(String[] args) throws IOException, InvalidFormatException {
     FileInputStream file = new FileInputStream(XLS_FILE_PATH);
     XSSFWorkbook workbook = new XSSFWorkbook(file);
     
     // Getting sheet1
     Sheet sheet = workbook.getSheet("Sheet1");
     // Getting row at index 0 in sheet1
     Row row = sheet.getRow(0);
     int rowLength = row.getPhysicalNumberOfCells();
     // Creating sheet2
     Sheet sheetTwo = workbook.createSheet("Sheet2");
     // Creating row at index 0 in sheet2
     Row sheetTwoRow = sheetTwo.createRow(0);
     // Setting value in row of sheet2 from sheet1
     for (int i = 0; i < rowLength; i++) {
     Cell cell = sheetTwoRow.createCell(i);
     Cell firstSheetCell = row.getCell(i);
     cell.setCellValue(firstSheetCell.getStringCellValue());
     }
     // Writing changes in Excel file
     file.close();
     FileOutputStream outFile = new FileOutputStream(new File(XLS_FILE_PATH));
     workbook.write(outFile);
     outFile.close();
     }
     }
    Your help and advise is greatly appreciated, thanks.
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,181
    Rep Power
    2011
    You forgot to add the error message you received.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    26
    Rep Power
    0
    Thanks for reply Mr Fujin. The jar files were the issues. These jar files below made it work, may be some can be removed, but will need to be tested to avoid breaking the code.

    poi-3.9.jar
    poi-examples-3.9.jar
    poi-ooxml-3.9.jar
    poi-ooxml-schemas-3.9.jar
    xmlbeans-xpath-2.6.0.jar
    ooxml-schemas-1.3.jar
    commons-collections-20040616.jar
    stax-api-1.0.1.jar
    org.apache.xmlbeans.xmlbeans-2.4.0.jar
    log4j-1.2.16.jar
    dom4j-1.6.jar

IMN logo majestic logo threadwatch logo seochat tools logo