| |

Inserting data into excel sheet using JExcel API

before going to use this post My strong advice to see this post first.

 

 

/* by using this program iam trying to insert data to the Excel sheet */

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package excelsheetreading;

/**
*
* @author vijay
*/

// in this program iam going to write insert some data with out formatting like fonts and decimals.
import java.io.File;
import java.io.IOException;
import java.util.Date;
import jxl.*;
import jxl.write.*;
import jxl.write.Number;
class WriteBook
{
// now here iam trying to enter one name and number to the sheet “First Sheet”

public static void main(String args[]) throws IOException, WriteException
{
// STEP 1:
// the first step is to create a writable workbook using the factory method on the Workbook class.
WritableWorkbook workbook = Workbook.createWorkbook(new File(“C:/Documents and Settings/vijay/Desktop/test.xls”));
//test.xls is my work book
// STEP 2:
//
WritableSheet sheet = workbook.createSheet(“First Sheet”,0); // sheet name
//STEP 3:
//adding(inserting) name to the sheet at location (0,2)
Label label = new Label(0,2,”A label record”);
sheet.addCell(label);
//adding number to the sheet at location (1,2)
Number number = new Number(1,2,3.1459);
sheet.addCell(number);
//Step 4:
//close the all opened connections
workbook.write();
workbook.close();
}
}

// before running
//1. make sure that jxl.jar file in your classpath
//2. and check test.xls file is available
//3. finally dont open the test.xls file while running this program

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *