Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Reading Excel File

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to read an excel file from java class. But it is taking more than 20 mins to read the file. Please help me in this issue. I am placing my code below

-------------------------------CODE------------------------------

WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
Workbook workbook = Workbook.getWorkbook(file, ws);
Sheet s = workbook.getSheet(0);
System.out.println("Initial read Excel Return 3333333");
int rows = s.getRows();
for (int i = 0; i < rows; i++) {
System.out.println("000");
Cell c = (Cell) s.getCell(0, i);
if(c != null && c.getContents() != null && !(c.getContents().trim().equals(""))){
XLDataBean bean = new XLDataBean();
bean.setRefNo(c.getContents());
c = (Cell) s.getCell(1, i);
bean.setTrackingNo(c.getContents());
c = (Cell) s.getCell(2, i);
bean.setUrl(c.getContents());
c = (Cell) s.getCell(3, i);
bean.setDisDate(c.getContents());
list.add(bean);
}else{
break;
}
}
-------------------------------------CODE----------------------------------

Regards
Pooja D
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Poja,

Just Debug, where it will take the time ? check by one by one line ,

Then only we will identify the issues.
 
Pooja Dornadhula
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lot of time is consuming in the below line of the code

Sheet s = workbook.getSheet("Sheet1");
 
krishnamoorthy kitcha
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pooja,

check with index

like

sheet = wb.getSheetAt(0);

wb means

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
wb = new HSSFWorkbook(fs);
sheet = wb.getSheetAt(0);
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many rows are you iterating through? The maximum number of rows depends on the version of Excel, but is between 65536 and 1048576, so yea, iterating through all those will take a while.
[ September 21, 2007: Message edited by: Joe Ess ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic