• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 794
  • Last Modified:

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
0
gudii9
Asked:
gudii9
  • 3
2 Solutions
 
CEHJCommented:
Change
 for (int i = 0; i < sheet.getRows(); i++) {

Open in new window

to
 for (int i = 1; i < sheet.getRows(); i++) {

Open in new window

then

I'd need to see the sheet to find out why it's printing pipe chars
0
 
gudii9Author Commented:
sorry i forgot to attach. Here it is
Reportt.xls
0
 
Amitkumar PSr. ConsultantCommented:
The attached sheet has two columns (Column A and Column B) is formatted from row 1 to 6133. This is why you are getting an additional pipe symbol.

Check by printing the output of "sheet.getRows()".

ie. System.out.println("No of Rows : "+sheet.getRows());
0
 
gudii9Author Commented:
How tp unformat for unwanted rows please advise
0
 
gudii9Author Commented:
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now