Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
how upload xlsx file in java give sample application
Posted 28-Jan-13 21:05pm
Comments
Shubhashish_Mandal at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100