-1

My code looks like this:

public void method(String value,int row,int column) throws Exception {  
    try {    
        FileInputStream inp = new FileInputStream("C:\\Users\\sit2autouser1\\Desktop\\Newdatasheet.xlsx");
        Workbook wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheet("Sheet2");
        Cell cell = sheet.getRow(row).getCell(column);
        String cellContents = value;
        // Modify the cellContents here
        // Write the output to a file
        cell.setCellValue(cellContents);
        FileOutputStream fileOut = new FileOutputStream("C:\\Users\\sit2autouser1\\Desktop\\Newdatasheet.xlsx");
        wb.write(fileOut);
        fileOut.close();
    } catch (Exception e) {
        throw (e);
    }
}   

It is throwing error just before close and it is also corrupting the Excel file. I am getting the same error, as soon as it reaches .write function it opens up a new tab which says "Source not found","Edit Source Look up path". And the heading of the tab is Integer.decode(String) line: not available.

Zombo
  • 1
  • 62
  • 391
  • 407
Kaustav Basu
  • 25
  • 1
  • 1
  • 8

2 Answers2

0

Try below code snippet for creating workbook instance.

FileInputStream fis = new FileInputStream(new File("C:\\Users\\sit2autouser1\\Desktop\\Newdatasheet.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook (fis);
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
Kuldeep Singh
  • 199
  • 1
  • 11
  • ,i am being able to create the instance.I am facing the issue when its reach the .write line. – Kaustav Basu Sep 14 '15 at 11:57
  • I tried it with your code on my side, its working fine. can you mention error here? – Kuldeep Singh Sep 14 '15 at 12:29
  • when i am debugging it ,i am getting the same error.as soon as it reaches .write function,It opens up a new tab which says "Source not found","Edit Source Look up path".And the heading of the tab is Integer.decode(String) line: not available.I wanted to put up an image,but i dont have the rights can you please help. – Kaustav Basu Sep 14 '15 at 12:48
0

I think you are not setting value properly. see the third line of code

Below is my working code:-

        FileInputStream fis=new FileInputStream(xlpath);

        Workbook wb=WorkbookFactory.create(fis);

        wb.getSheet(sheetName).getRow(rowNum).createCell(cellNum).setCellValue(input);

        FileOutputStream fos=new FileOutputStream(xlpath);

        wb.write(fos);

        fos.close();

OR

Make sure that in the remote debug configuration your eclipse project is selected.

Below is the reference, you can try that also:-

http://stackoverflow.com/questions/6174550/eclipse-java-debugging-source-not-found
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • I tried using your code but when i am debugging it ,i am getting the same error.as soon as it reaches .write function,It opens up a new tab which says "Source not found","Edit Source Look up path".And the heading of the tab is Integer.decode(String) line: not available.I wanted to put up an image,but i dont have the rights can you please help.. – Kaustav Basu Sep 14 '15 at 12:42
  • Is your excel file present on that location.Is that location have privileges by system to read/write.updated my answer and provide a reference. that might help you – Shubham Jain Sep 14 '15 at 12:49
  • yes the excel file is present in that location.its there on the desktop and does not have any priveleges.I tried adding my project remotedebug configuration,i am not sure if i did the right thing,but its still not working.Surprisingly this code was working fine before,and is working fine when i am running it,the problem appears only when i debug it. – Kaustav Basu Sep 14 '15 at 13:05
  • In the debug window the line Integer.decode(String) line: not available is under Thread[main](Suspended(exceptionNumberFormatException)) – Kaustav Basu Sep 14 '15 at 13:15