Setup Menus in Admin Panel

ITeLearn.com

Error in read excel function | Selenium Automation | Discussions | ITeLearn.com

Forum usage guidelines

  1. Search First.: If you don’t find a similar post, start a new topic. If you find a similar thread and still have a question, reply to that topic. Duplicate threads will be ignored/deleted without warning.
  2. Proper Subject: Ensure you choose a very appropriate topic name. Else it will be tough to get support from other members.
  3. Patience, please: Our Tech team or other members will usually try to respond within 24 hours on weekdays and max within 48 hours on weekends. Sometimes sooner.
  4. Share opinions: Please feel free to reply, add or comment on any ongoing topics. Collective learning will be of great benefit to all.

 
ITeLearn reviews from participants.

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Error in read excel function
April 17, 2017
8:57 pm
Abhinaya Abhinaya
Member
Forum Posts: 6
Member Since:
March 28, 2017
Offline

Below is the code that i am using and getting an error as” This method must return a result of type string[][]”.

public static String[][] readXL(String fPath, String fSheet) throws Exception{
String[][] xData;

File myxl = new File(fPath);
FileInputStream myStream = new FileInputStream(myxl);
HSSFWorkbook myWB = new HSSFWorkbook(myStream);
HSSFSheet mySheet = myWB.getSheet(fSheet);
xRows=mySheet.getLastRowNum()+1;
xCols=mySheet.getRow(0).getLastCellNum();
System.out.println(“Total rows:”+xRows);
System.out.println(“Total columns:”+xCols);

xData= new String[xRows][xCols];
for (int i=0; i < xRows; i++) {
HSSFRow row=mySheet.getRow(i);
for (int j=0; j<xCols; j++){
HSSFCell cell= row.getCell(j);
String value = "-";
if(cell!=null){
value = cellToString(cell);

xData[i][j]=value;
System.out.println(value);
System.out.println("—-");
}
System.out.println("");
}
myxl=null;
return xData;
}
}

April 19, 2017
9:37 am
Techhelp
Member
Forum Posts: 1889
Member Since:
October 26, 2012
Offline

Use this working code

public static String[][] readXL(String sPath, String iSheet) throws Exception{
String[][] xData;

File myxl = new File(sPath);
FileInputStream myStream = new FileInputStream(myxl);
HSSFWorkbook myWB = new HSSFWorkbook(myStream);
HSSFSheet mySheet = myWB.getSheet(iSheet);
xRows = mySheet.getLastRowNum()+1;
xCols = mySheet.getRow(0).getLastCellNum();
xData = new String[xRows][xCols];
for (int i = 0; i < xRows; i++) {
HSSFRow row = mySheet.getRow(i);
for (int j = 0; j < xCols; j++) {
HSSFCell cell = row.getCell(j);
String value = cellToString(cell);
xData[i][j] = value;
System.out.print(value);
System.out.print("####");
}
System.out.println("");
}
myWB.close();
return xData;
}

Forum Timezone: UTC -8

Most Users Ever Online: 70

Currently Online: Syed Gillani
7 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Techhelp: 1889

Manu: 114

Shan Nathan: 80

Palanki sai charan: 67

Userone: 59

Vishal Anand: 53

Archana Sapre: 51

Geetha Reddy: 44

useL: 38

Priyanka Perumalla: 36

Member Stats:

Guest Posters: 19

Members: 7846

Moderators: 0

Admins: 1

Forum Stats:

Groups: 1

Forums: 22

Topics: 2064

Posts: 5695

Newest Members: Syed Gillani, Naga Venkata Yerramsetti, Amulya Rajendran, kiran pujar, Anupama Odnala, Hitesh Shah, Jaya Vysyaraju, Md Payel Miah, Ashwini Yerra, Jennifer Manual

Administrators: Karthik eLearn (Admin): 49

0 Responses on Discussions"

Main Menu