Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Program to insert a row in the same sheet of excel file

Have Programming Question? Ask it here!
 
 
 


DILEEPKRISHNA
Java Program to insert a row in the same sheet of excel file
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


Java program to insert a row in the same sheet of excel file using poi package in java


Advertisement
View Answers

February 7, 2012 at 12:28 PM


import  java.io.*;  
import  java.sql.*;
import  org.apache.poi.hssf.usermodel.HSSFSheet;  
import  org.apache.poi.hssf.usermodel.HSSFWorkbook; 
import  org.apache.poi.hssf.usermodel.HSSFRow;
import  org.apache.poi.hssf.usermodel.HSSFCell;  

public class CreateExcelFile{
    public static void main(String[]args){
try{
String filename="c:/data.xls" ;
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet =  hwb.createSheet("new sheet");

HSSFRow rowhead=   sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("SNo");
rowhead.createCell((short) 1).setCellValue("Name");
rowhead.createCell((short) 2).setCellValue("Address");
rowhead.createCell((short) 3).setCellValue("Contact No");
rowhead.createCell((short) 4).setCellValue("E-mail");

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from employee");
int i=1;
while(rs.next()){
HSSFRow row=   sheet.createRow((short)i);
row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt("id")));
row.createCell((short) 1).setCellValue(rs.getString("name"));
row.createCell((short) 2).setCellValue(rs.getString("address"));
row.createCell((short) 3).setCellValue(Integer.toString(rs.getInt("contactNo")));
row.createCell((short) 4).setCellValue(rs.getString("email"));
i++;
}
FileOutputStream fileOut =  new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");

} catch ( Exception ex ) {
    System.out.println(ex);

}
    }
}

For more information, visit the following links:

http://www.roseindia.net/java/poi/setDataFormat.shtml

Examples of POI API



Related Tutorials/Questions & Answers:
Java Program to insert a row in the same sheet of excel file
Java Program to insert a row in the same sheet of excel file  Java program to insert a row in the same sheet of excel file using poi package in java
insert rows from Excel sheet into a database by browsing the file
insert rows from Excel sheet into a database by browsing the file  hello, I am trying to insert rows from Excel sheet into SQL database by browsing Excel file in java(JSP). I can insert rows using ODBC connetion. But using odbc
Advertisements
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java    How to export data from html file to excel sheet by using java
Selecting Excel Sheet File
selecting excel sheet file       In this program we are going to select the excel sheet...) for rest. The selected sheet will displayed as shown in output of program
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java   reading the data from Html file
Insert Image into Excel Sheet
Insert Image into Excel Sheet In this section, you will learn how to insert image into excel sheet using Apache POI. In the given below example, am image is insert into excel sheet at row 1 and at column 1. you can specify the top
reading excel sheet in java
reading excel sheet in java  can anyone tell me a proper java code to read excel sheet using poi   Here is a java code that reads an excel file using POI api and display the data on the console. import java.io.
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
How to Create New Excel Sheet Using JSP
a new  excel sheet using java .You can create any number of  new excel sheets in a excel file.  To create a excel sheet we can use third party APIs... How to create new excel sheet using jsp  
insert data 50 row *column into 300 row *column by using xls sheet data (50 row *column) are given in xls sheet
insert data 50 row *column into 300 row *column by using xls sheet data (50 row *column) are given in xls sheet   1- there are matrix of data with 300 row and 300 column,this is master table we have input data 50 row and 50
Printing data into Excel sheet - Java Beginners
a Java Bean that will retrieve the data from the database and insert it into excel... where there is need to bring the data into "Excel Sheet" with proper format.My... database then showing it(data) to in "Excel Sheet" is it possible to do ? if yes
Insert excel file data into database Using Java Programming
Insert excel file data into database in Java Program In this PHP tutorial section, you will learn how to insert excel file data into the database. We have... excel file data into Database Using java programming: import java.io.
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
Create Excel Sheet Using JSP
create excel sheet using jsp       In this example we create excel sheet and insert values into table of the excel sheet . In this example we use page directive
Create and Save Excel File in JSP
. Java program allows to you to create any number of excel sheets in an excel file.  To create an excel sheet we can use third party API which is Apache... Create and Save Excel File in JSP  
Export data in excel sheet in java in struts - Struts
Export data in excel sheet in java in struts  Hello, All how can i export data in excel file i java  Hi friend, For solving the problem visit to : http://www.roseindia.net/jsp/excelfile.shtml Thanks
How to insert rows from Excel spreadsheet into database by browsing the excel file?
How to insert rows from Excel spreadsheet into database by browsing the excel file?  I want to insert rows from excel sheet to database.for this i... excel file and insert rows into MSSQL database in JSP???   Have a look
Create Excel Sheet Using JSP
into excel sheet using java .You can create any number of cells and rows... create excel sheet using jsp   ... cells  into 0th row. The code of the program is given below
code for attendence in excel sheet - Java Magazine
"in an an HTML page, time of the system should save in the excel file of that Empid row(IE 1st row),"when i enter the same Empid once again, the time of the system should... the problem : Create a Excel file   Search
insert values from excel file into database
insert values from excel file into database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel... the following link: Insert values from excel file to database
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Updating rows who has same id with different values for each row from java program
Updating rows who has same id with different values for each row from java...) with "lalitha" as a value for sname column from java program. Same for records with sid... rows with same id. student table: sid sname age 2 aruna 25 2
How to read every cell of an excel sheet using Apache POI and insert those data into a DB?
How to read every cell of an excel sheet using Apache POI and insert those data into a DB?   i have an excel sheet, whose data in each cell has... the rows of an excel sheet. Need the source code
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
How to export data from html to excel sheet by using java
How to export data from html to excel sheet by using java   How to export data from html to excel sheet by using java
Excel file Handling in Java
Excel file Handling in Java  Hello Sir, I am new to Java, I have Started Java Core by myself. I want to make a project which include 3-4 Excel file...://www.roseindia.net/tutorial/java/poi/readExcelFile.html   Now to create an excel file
How to open excel sheet when excel file is placed in some folder in desktop
How to open excel sheet when excel file is placed in some folder in desktop  How to open an excel sheet using windows.open in IE... I am getting an error msg that the path is not correct.. But i have specified the correct path
connection of java file to excel file and put data from excel file into oracle db
connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we give action to that button excel sheet? how we connect excel file to java file
Reading And Writing Excel File
; The output of the program is given below: Download this excel file. Download... reading and writing excel file   ... the excel sheet  using java . The package we need to import is : java.io.
Convert the excel sheet data into oracle table through java or jsp
Convert the excel sheet data into oracle table through java or jsp  Hi Friends, Let me help this issue i am phasing Convert the excel sheet data into oracle table through java or jsp
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
Problem in executing macro enabled excel sheet using java
Problem in executing macro enabled excel sheet using java  Hi, I have written a java code which will read a excel sheet with macro enabled... to execute VB script it is unable to execute macro and cannot generate the script file
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
Create Bar Graph from reading excel sheet in Java
Create Bar Graph from reading excel sheet in Java  I'm New to Java and I have to create a java program where I have to read data from multiple excel sheets say 4 sheets and sheet represents browsers (like FF, IE8, IE9 , chrome
How to set background of an excel sheet using POI - Java Magazine
How to set background of an excel sheet using POI  Hi, i am trying to format the excel using java. How to set the background color of an excel sheet( complete sheet which includes all cells). i am using poi2.5.1. Thanks
Insert data in Excel File from Database using JSP
Insert data in Excel File from Database  using JSP ... developed a application to insert data  in excel file from database in JSP. We... the data from database, create an excel file and data insert into newly
Find Name of Excel Sheet
Find Name of Excel Sheet       In this program we are going to find the name of an excel... This is basically stores the sheet name and tells where the beginning of file record
Find Type of Excel Sheet
Find Type of Excel Sheet       In this program we are going to find type of an excel sheet..._CHART,  5.TYPE_EXCEL_4_MACRO, 6.TYPE_WORKSPACE_FILE The code of the program
excel file using JDBC java.?
excel file using JDBC java.?  hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a excel file and then appends the same excel file as required. i am writing my code on notepad and have successfully
How to export data from database to excel sheet by using java in standalone project
How to export data from database to excel sheet by using java in standalone project  How to export data from database to excel sheet by using java in standalone project
how to use Excel Templet to write excel file using java.
how to use Excel Templet to write excel file using java.  how to use Excel Templet to write excel file using java
update excel sheet using jsp::
update excel sheet using jsp::   Hi Sir,... I have a excel sheet for employee details "i retrieve particular datas from given excel sheet and display it into another excel sheet using jsp
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
Inserting Image In Excel Sheet Using JSP
Inserting Image In Excel Sheet Using JSP       In this example, we create excel sheet... in Excel and suggest the file to use when the user saves the file by setting
Excel sheet image reading issue
Excel sheet image reading issue   Hello every one.I?m trying to read images from an excel sheet using OleDbDataReader. My excel file has 6... Properties='Excel 8.0;HDR = YES;'"); conn.Open(); OleDbCommand cmd
Zoom in Excel
; In this program we are going to make a java program through which we can zoon in(-)  an excel sheet. By this means you can make an excel sheet... ratio of the excel sheet e.g. setZoom(3,4) means zoom the sheet as 75
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
 

 

 

DMCA.com