0

Hello guys i have tried editing and working with excel in java, but kept getting errors after doing everything as below:

package writer;
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.write.*;
import jxl.write.Number;


public class Writer {


    public static void main(String[] args) throws IOException{
        try{

   String fileName = "‪‪‪C:\\Users\\Valentine\\Documents\\NetBeansProjects\\Writer\\src\\Workbook.xls"; 
    WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName));
    WritableSheet sheet = workbook.createSheet("Sheet1", 0);
    //Adding A Label
    Label label = new Label(0,0,"A label record");
    sheet.addCell(label); 
    Number number = new Number(0,1,3.1459);
   sheet.addCell(number);
   workbook.write();
   workbook.close();

    }catch (WriteException e){

This is the error an getting

run:
Exception in thread "main" java.io.FileNotFoundException: ‪‪‪C:\Users\Valentine\Documents\NetBeansProjects\Writer\src\Workbook.xls (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
    at jxl.Workbook.createWorkbook(Workbook.java:301)
    at jxl.Workbook.createWorkbook(Workbook.java:286)
    at writer.Writer.main(Writer.java:17)
C:\Users\Valentine\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)

I appreciate your help. thanks

3
  • 1
    Does C:\Users\Valentine\Documents\NetBeansProjects\Writer\src\Workbook.xls file exist? Commented May 1, 2017 at 19:00
  • yes @RomanPuchkovskiy, it exits, thats where the excel file is Commented May 1, 2017 at 19:06
  • Assuming that the file actually does exist on that path, try a properly encoded java path, like this: "/Users/Valentine/Documents/NetBeansProjects/Writer/src/Workbook.xls" Windows paths (with back-slashes) generally work, but this is worth a try. Commented May 1, 2017 at 19:24

1 Answer 1

2

You need to close the excel file before running the program. Even though the exception is FileNotFoundException, if you have the file opened, and you run the program, it throws that exception which is a little misleading. Your program JVM process tries to lock the file which was locked by MS Excel program, so the exception is understandable

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.