How to create a new workbook using POI?

How to create a new workbook using POI?

Previous Home Next

 

In this page of the example we are going to create the workbook with help of the POI APIs in java language. for creation of the workbook we use the method createDocumentInputStream("Workbook").


 getSid():-
This methods give the description copied from class.


 
package r4r;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.eventusermodel.*;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.dev.EFHSSF;
public class findtypeofworkbook implements HSSFListener {
	public static void main(String[] args) throws IOException
	  {  
	  FileInputStream fis = new FileInputStream(args[0]);
	  POIFSFileSystem pfs = new POIFSFileSystem(fis);
	  InputStream in = pfs.createDocumentInputStream("Workbook");
	  HSSFRequest hreq = new HSSFRequest();
	  hreq.addListenerForAllRecords(new findtypeofworkbook());
	  HSSFEventFactory fact = new HSSFEventFactory();
	  fact.processEvents(hreq, in);
	  fis.close();
	  in.close();
	  System.out.println("STOP");
	  }
	  public void processRecord(Record record)
	  {
	  switch (record.getSid())
	  {
	  case BOFRecord.sid:
	  BOFRecord bof = (BOFRecord) record;
	  if (bof.getType() == bof.TYPE_WORKBOOK)
	  {
	  System.out.println("Workbook");
	  
	  } 
	  break;
	  }
	 }
}


Previous Home Next