Hello
I am looking to make an application that performs basic data analysis techniques. I want to read and write into excel files, any pointers will be much appreciated!
thanks!

hi dear
for reading and writing from/into excel files.
you have to use these java packages.
java.io.File;
java.io.IOException;
jxl.Cell;
jxl.CellType;
jxl.Sheet;
jxl.Workbook;
jxl.read.biff.BiffException;
after that try this code this is only for readiing the file try it your own for writing.

public class ReadExcel {

  private String inputFile;

  public void setInputFile(String inputFile) {
    this.inputFile = inputFile;
  }

  public void read() throws IOException  {
    File inputWorkbook = new File(inputFile);
    Workbook w;
    try {
      w = Workbook.getWorkbook(inputWorkbook);
      // Get the first sheet
      Sheet sheet = w.getSheet(0);
      // Loop over first 10 column and lines

      for (int j = 0; j < sheet.getColumns(); j++) {
        for (int i = 0; i < sheet.getRows(); i++) {
          Cell cell = sheet.getCell(j, i);
          CellType type = cell.getType();
          if (type == CellType.LABEL) {
            System.out.println("I got a label "
                + cell.getContents());
          }

          if (type == CellType.NUMBER) {
            System.out.println("I got a number "
                + cell.getContents());
          }

        }
      }
    } catch (BiffException e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) throws IOException {
    ReadExcel test = new ReadExcel();
    test.setInputFile("c:/temp/lars.xls");
    test.read();
  }

} 

have to? no. there are several packages available to perform these tasks, of which apache's POI library is a very well known example, that is used in tons of applications world wide. there's also no need to provide entire code examples, since the documentation sections of the frameworks provide more then enough coverage of the materail to get going.

This article has been dead for over six months. Start a new discussion instead.