0

I have a CSV file with 5 sheets. I want to read the second sheet.(Basically specify which sheet to read in my code).

Currently using CsvReader and CsvWriter java packages to read /write to a csv file. Which works great!!!

But is there anyway I can specify which sheet I want to read?

Anyone tried this out?

Thanks

0

3 Answers 3

2

CSV file format does not support multiple sheets. You can save only only one sheet per file in CSV file format.

Sign up to request clarification or add additional context in comments.

Comments

1

This is my code to read excel file and you can loop for many sheet. But you must use plug-in jxl. Just download and import to lib. This my link can hlep you : http://www.mediafire.com/?fr1xkgdtx49awa8 .Sorry for bad english.

public List<Result> read(File inputWorkbook) throws IOException  {
    List<Result> list = new ArrayList<Result>();
    Workbook w;
    try {
        w = Workbook.getWorkbook(inputWorkbook);
        // Get the first sheet
        Sheet sheet = w.getSheet(0);
        // Loop over first 10 column and lines
        for (int j = 1; j < sheet.getRows(); j++) {
            Result rs= new Result(); 
            Cell cell0 = sheet.getCell(0, j);
            for (int i = 0; i < sheet.getColumns(); i++) 
            {
                Cell cell = sheet.getCell(i, j);
                CellType type = cell.getType();
                if (cell.getType() == CellType.LABEL) {
                    System.out.println("I got a label " + cell.getContents());
                }

                if (cell.getType() == CellType.NUMBER) {
                    System.out.println("I got a number " + cell.getContents());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}

Comments

0

I think what you need is to use Apache POI for opening an exel document and obtaining a specific sheet using

workbook.getSheet(sheetNumber);

Here's an example from apache on reading/writing excel

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.