Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how upload xlsx file in java give sample application
Posted
Comments
Shubhashish_Mandal 29-Jan-13 5:25am    
This is not a question, and you can't ask anyone to write a sample app for you.Be specific where you stuck.
There are lots of example exist to upload a file in java. so Google it
DalliaF 8-Mar-13 2:55am    
sample???---



1)Write .xlsx file:

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

public class CreateFile{
public static void main(String args[]) throws IOException{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
int rowCount=0;
int count=0;
HSSFRow headerRow = sheet.createRow((short) 0);
HSSFRow dataRow =sheet.createRow((short) 1);
headerRow.createCell((short)0).setCellValue("ID");
headerRow.createCell((short)1).setCellValue("NAME");
headerRow.createCell((short)2).setCellValue("Address");
for(int i=0;i<5;i++){
rowCount++;
sheet.createRow((short)rowCount);
dataRow.createCell((short)0).setCellValue(1);
dataRow.createCell((short)1).setCellValue("Rose");
dataRow.createCell((short)2).setCellValue("Delhi");
count++;
}
File f = new File("c:\\test.xlsx");
FileOutputStream fos = new FileOutputStream(f);
wb.write(fos);
}
}

2)Read .xlsx File:

import java.io.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class ReadFile {
public static void main( String [] args ) {

String fileName="C:\\test.xlsx";
Vector dataHolder=ReadFile(fileName);
read(dataHolder);
}
public static Vector ReadFile(String fileName){
Vector cellVectorHolder = new Vector();
try{
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector=new Vector();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement(myCell);
}
cellVectorHolder.addElement(cellStoreVector);
}
}catch (Exception e){ }
return cellVectorHolder;
}
private static void read(Vector dataHolder) {
for (int i=0;i<dataholder.size();>< cellStoreVector.size();j++){
HSSFCell myCell = (HSSFCell)cellStoreVector.elementAt(j);
String stringCellValue = myCell.toString();
System.out.print(stringCellValue+"\t");
}
System.out.println();
}
}
}
DalliaF 8-Mar-13 2:56am    
their is a sample code here at --->http://www.roseindia.net/answers/viewqa/JSP-Servlet/7190-Java-xlsx.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900