title: Reading cells from an Existing Excel File and Writing them into a new Excel File using Java
body: <p>So I'm currently creating a program to read, edit and place data from an existing Excel file into a new Excel File using the JXL Java library. At this stage I will just like to read data from the existing Excel file and place it into the new one. Can't seem to find a good way of doing it and for future work what is the best way to edit the data (having certain columns) and placing them into the new Excel File.</p>
  
  <p>Sorry if anything is unclear, just getting grips with Java and Stackoverflow.</p>
  
  <pre><code>import java.io.*;
  import jxl.*;
  import jxl.write.Number;
  import jxl.write.*;
  
  class Extraction {
  
  private String inputFile;
  
  String data;
  
  public void setInputFile(String inputFile){
  
      this.inputFile = inputFile;
  
  }
  
  public void read() throws IOException {
  
      File spreadsheet = new File(inputFile);
  
      Workbook w;
  
      try {
  
          w = Workbook.getWorkbook(spreadsheet);
  
          Sheet page = w.getSheet(0);
  
          File f = new File("C:\\Users\\alex\\Desktop\\New_Export.xls");                                                                                      
  
              if (!f.exists()){
  
                  String FileName = "C:\\Users\\alex\\Desktop\\New_Export.xls";
  
                  WritableWorkbook excel = Workbook.createWorkbook(new File(FileName));
  
                  WritableSheet sheet = excel.createSheet("Sheet1", 0);                                           
  
                      for (int y = 0; y &lt; page.getRows(); y++){
  
                          for (int x = 0; x &lt; page.getColumns(); x++){
  
                              Cell cell = page.getCell(x ,y +1);
                              CellType type = cell.getType();
  
                                  if(type == CellType.LABEL || type == CellType.NUMBER){
  
                                      data = cell.getContents();
  
                                      System.out.println(data);
  
  
  
  
                                      //To now input the read data into the new Excel File
  
                                      sheet.addCell();
  
                                  }
  
                          }
  
                          System.out.println(" ");
  
                      }   
  
                  System.out.println("The File Has Successfully Been Created!");
  
                  excel.write();
  
                  excel.close();
  
                  }
  
                  else{
  
                      System.err.println("File is already created!");
  
                  }
  
      }
      catch(Exception e){
  
          System.out.println(" ");  
  
      }       
  
  }       
  
  public static void main (String args[]) throws IOException{
  
      Extraction reading = new Extraction();
  
      reading.setInputFile("C:\\Users\\alex\\Desktop\\export.xls"); 
  
      reading.read();
  
  }
  }
  </code></pre>