Friday 9 January 2015

jxl : Creating xls sheet


Workbook class provides “createWorkbook” method, to create xls sheet.
       
Ex:
WritableWorkbook workbook = Workbook.createWorkbook(new File("data.xls"));

Above statement create data.xls file. “data.xls” file located in current working directory.

import java.io.IOException;
import jxl.*;
import jxl.write.*;
import java.io.File;

public class XLSWritableUtils {
    WritableWorkbook workbook = null;

    public XLSWritableUtils(String fileName){
        try {
            workbook = Workbook.createWorkbook(new File(fileName));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}


public class TestUtils {
    public static void main(String[] args) {
       String fileName = "data.xls";
       XLSWritableUtils utils = new XLSWritableUtils(fileName);
    }
}

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment