tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Excel > JExcel API > How to add Data Type Cells to Excel Spreadsheet

How to add Data Type Cells to Excel Spreadsheet 

Java Excel API is an open source java library to read, write and modify Excel spread sheets. This requires the library jxl-2.6.12.jar to be in classpath. The following example shows how to add different Data Type Cells to Excel Spread sheet.

File Name  :  
com/bethecoder/tutorials/jexcelapi/write/AddDataTypeCellsTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jexcelapi.write;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Boolean;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

public class AddDataTypeCellsTest {

  /**
   @param args
   @throws IOException 
   @throws IOException 
   @throws WriteException 
   @throws BiffException 
   */
  public static void main(String[] argsthrows IOException, WriteException {
    //Creates a writable workbook with the given file name
    WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/JXL/AddTypesSheets.xls"));
    
    WritableSheet sheet = workbook.createSheet("My Sheet"0);
    
    sheet.addCell(new Label(00"ABC"));
    sheet.addCell(new Label(10"DEF"));
    
    sheet.addCell(new Boolean(01true));
    sheet.addCell(new Boolean(11false));
    
    sheet.addCell(new Number(021234.56));
    sheet.addCell(new Number(12, -9.87654));
    
    sheet.addCell(new DateTime(03new Date()));
    sheet.addCell(new DateTime(13new Date(System.currentTimeMillis() 90000000)));
    
    //Writes out the data held in this workbook in Excel format
    workbook.write()
    
    //Close and free allocated memory 
    workbook.close()
  }

}
   

It gives the following output,
add-data-types.gif


 
  


  
bl  br