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

 
 


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

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

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 Pages:
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
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
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
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
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
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
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.
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  
Shifting Row Using JSP
Shifting row using JSP       In this program we are going to shift the row using java... from 0 in excel file. shiftRows(int startRow, int endRow, int n): This method
excel
excel  how to read columns values of excel file in java and store in array list in java like col1 col2 2 3 1 7 7...(); k++){ int j=i+1; HSSFSheet sheet = wb.getSheetAt(k
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
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
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  
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
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
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
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
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.
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
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.
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
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
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 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
exporting data to excel sheet - JDBC
query in java swing program,i want to print the result about the query in excel... = wb.createSheet("Excel Sheet"); try{ Connection con = null...exporting data to excel sheet  Sir i have already send request about
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 save data to excel with a 2.1 work sheet format without changing it?
How to save data to excel with a 2.1 work sheet format without changing... and save it to excel file then read it again .. the problem is , when data is saved , the extension file is changed to excel file with text ( tab limited
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
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
JSP Excel Tutorial
excel sheet and and insert values into table to the excel sheet .   ... new excel sheet In this program we are going to create a new  excel...; In this program we are going to select the  excel sheet  using java .You can
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
How to get data from Excel sheet - Struts
excel sheet and display in console first then later insert this data into database. i am using java, jsp, struts also but not using struts html tags just using...How to get data from Excel sheet  Hi, I have an excel sheet
excel sheet reading and using that data - JSP-Servlet
excel sheet reading and using that data  i have to do a read a excel sheet file of a employee record and then i have to use a employee details...://www.roseindia.net/tutorial/java/poi/readExcelFile.html http
Set Zoom Magnification of Excel Sheet
Set  Zoom Magnification of Excel Sheet In this section, you will learn how to set the zoom magnification of a Excel workbook's sheet. Zoom... In the below code, an Excel(.xlsx) workbook's sheet's magnification
export data from database to excel sheet - JDBC
execute a query then result will be display in MS-EXCEL sheet. please give me... HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Excel Sheet"); HSSFRow rowhead...("Data is saved in excel file."); rs.close(); connection.close(); } catch
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
JDBC to EXcel
JDBC to EXcel  How to insert data in excel sheet from java
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
make header and footer and attache it with excel sheet.
 make header and footer and attache it with excel sheet... header and footer and attaché it with excel sheet.  Code description ... and footer and page it on sheet.  The method used in this example shift row
How to save excel sheet into mysql database using blob or clob
How to save excel sheet into mysql database using blob or clob  Hi All, I am new to java and i need to upload excel sheet to mysql, please suggest...) ); Please help me with the code or steps to insert a large xlsx sheet. waiting
excel to database
excel to database   How to export data from excel sheet to mysql database by using java with request parameter Here q=40 is a request parameter...(); Workbook workbook = Workbook.getWorkbook(new File("C:/data.xls"), ws
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
ODCB-EXCEL - Java Beginners
ODCB-EXCEL  Hi, i would like to extract data from an excel file. my excel file name is: TEST.xls the worksheet name is : qas i have configure... to extract the data of the excel file that has been stored into the database or you
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
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
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
Need to Remove Duplicate Records from Excel Sheet
Duplicate Records from Excel Sheet. I have one excel sheet having two fields (EmpNum, Rating) have to save in another excel sheet with unique empnum of latest empnum rating (without using sql query have to remove records from excel using java
reading data from excel file and plotting graph
at the same time from one excel file using different columns..how can i do that? waiting...reading data from excel file and plotting graph  I am doing a project using NetBeans in which i have to take input an excel file and then using

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.