User Tools

Site Tools


technology:java:spreadsheet_reader

Spreadsheet Reader

This example shows how to read a worksheet in an Excel spreadsheet using the Java Excel API by Andy Khan. This code was written as an example for a large client project in 2003.

import java.io.*;
import java.util.Date;
import jxl.*;
class  SpreadsheetReader
{
    public static void main(String[] args) throws Exception
    {
        Cell cell = null;
        String contents = null;
        Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));
        Sheet sheet = workbook.getSheet(0);
        //read/print a 2-D square of cells;
        for (int x = 0; x < 10; x++){
            for (int y = 0; y < 10; y++){
                cell = sheet.getCell(x,y);
                contents = cell.getContents();
                System.out.println("Cell ["+x+","+y+"]="+contents);
            }
        }
    }
}
/home/cfreyer/public_html/data/pages/technology/java/spreadsheet_reader.txt · Last modified: 2009/04/01 10:37 by Chris Freyer