Jexcel

Java Excel API Projects

Java Excel API Project 1

How To Create a new workbook?
Previous Home Next

 

In this we are going to create a new instance of writable workbook. So that we can perform tasks like add cells, merge cells, dd properties on spreadsheet, perform formatting etc. We will discus how we can create a spreadsheet in our next topic.  

To create a new instance of writable workbook JExcel API provides the factory methods in the Workbook class into jxl.jar .Which is  static method with return type is WritableWorkbook class. 

The Workbook class is a public abstract class which extends java.lang.Object class .This class contains many factory methods many accessors .
 Here in this topic we have used createWorkbook(java.io.File file) factory methods. It is a static methods .

The Workbook class provides following createWorkbook methods which we can use as per as our requirements. These all are static methods with return types WritableWorkbook.

createWorkbook(java.io.File file):- 
          This method is used to create a writable workbook for given file name. The file name will be a spreadsheet name with file locations.

createWorkbook(java.io.File file, Workbook in):- 
          This method is used to create a writable workbook for given file name as a copy of the workbook passed in. 

createWorkbook(java.io.File file, WorkbookSettings ws):- 
          This method is used to create a writable workbook for given file name which includes the given workbook settings. 

createWorkbook(java.io.File file, Workbook in, WorkbookSettings ws) :-
          This method is used to create a writable workbook for given file name which includes the given workbook settings as a copy of the workbook passed in. 

createWorkbook(java.io.OutputStream os):- 
          This method is used to create a writable workbook .

createWorkbook(java.io.OutputStream os, Workbook in):- 
          This method is used to create a writable workbook  as a copy of the workbook passed in. 

createWorkbook(java.io.OutputStream os, WorkbookSettings ws):- 
          This method is used to create a writable workbook as workbook setting of the workbook passed in.

createWorkbook(java.io.OutputStream os, Workbook in, WorkbookSettings ws):- 
          This method is used to create a writable workbook as workbook setting of the workbook as a copy of the workbook passed in.

Packages needed - 

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

Syntax :

WritableWorkbook workbook = Workbook.createWorkbook(new File("c://r4r/java/jexcel/output.xls")); 

It creates an object of writable workbook for “output.xls”  in c://r4r/java/jexcel folder.

 

Previous Home Next