Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

java program reading the spreadsheet document data

My java program looks like  this
import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {

      private String inputFile;

      public void setInputFile(String inputFile) {
            this.inputFile = inputFile;
      }

      public void read() throws IOException  {
            File inputWorkbook = new File(inputFile);
            Workbook w;
            try {
                  w = Workbook.getWorkbook(inputWorkbook);
                  // Get the first sheet
                  Sheet sheet = w.getSheet(0);
                  // Loop over first 10 column and lines
                  System.out.println(sheet.getRows());
                for (int i = 0; i < sheet.getRows(); i++) {
          for (int j = 0; j < sheet.getColumns(); j++) {
            Cell cell = sheet.getCell(i, j);
            String x = cell.getContents();
            System.out.println(x);
          }
      }
                 
                 
                 
                 
     

                 
            } catch (BiffException e) {
                  e.printStackTrace();
            }
      }

      public static void main(String[] args) throws IOException {
            ReadExcel test = new ReadExcel();
            test.setInputFile("c:/gp/Report.xls");
            test.read();
      }

}
Console output looks like this

 Name  |  Number
CS020  |  7120917302
HE030  |  18533976
PF044  |  7116244216
|
|
|
|
|
|
|

My program is displaying the First row also which is heading. I do not want to display the heading. I would like skip first row. Also my program priniting pipe character many times after printing 3 rows of data from excel spread sheet. Please advise on how can I fix these two issues.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

sorry i forgot to attach. Here it is
Reportt.xls
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

How tp unformat for unwanted rows please advise
Avatar of gudii9

ASKER

I see one issue

it is printing

CS020  |  7120917302
HE030  |  18533976
PF044  |  7116244216


CS020  |  7120917302
HE030  |  18533976
PF044  |  7116244216



two times as the number of columns is 2. (i want to display only one time).How to fix this issue. Please advise