0

I have an excelsheet in which I have data something like this ,my requirement is to read the excelsheet and get the screen_name having type dropdown , this is my sample input and I have also added output which can be used as a refrence

Seq     Screen_name        Type     
1.0     ds_top             dropdown     
2.0     ds_level            detail  

output for this will be :- ds_top

I was able to read the excelfile and get the column values of screen_names and type seperately but how to implement further logic

Any Help is appreciated

   import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

    public class ReadCellExample {
        String xlsxFile = "/home/spec.xlsx";
    
        public static void main(String[] args) throws IOException {
            ReadCellExample rc = new ReadCellExample();
             rc.ReadCellData(1, 1, 2);
        }
    
        public void ReadCellData(int vRow, int vColumn, int columndef) throws IOException {
            String value = null;
            Workbook wbook = null;
            FileInputStream fis = new FileInputStream(xlsxFile);
            wbook = new XSSFWorkbook(fis);
            Sheet sheet = wbook.getSheetAt(0);
            Row row = sheet.getRow(vRow);
            for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
                row = sheet.getRow(rowIndex);
                Cell cell = row.getCell(vColumn);
                value = cell.getStringCellValue();
            }
            for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
                row = sheet.getRow(rowIndex);
                Cell cell = row.getCell(columndef);
                value = cell.getStringCellValue();
            }
        }
    }
  • 1
    What is happening when you run your code? Does it crash or outputs undesired values? In short: Where **exactly** is the problem here? – deHaar Jun 11 '21 at 08:55
  • https://www.javatpoint.com/how-to-read-excel-file-in-java,. there are multiple working methods . try out – Meena Pintu Jun 11 '21 at 08:59
  • thanks @deHaar for the response , I am able to get everything from the excelsheet but now I want only screen and type values only , can you please help me with this – Divyesh Kumar Jun 11 '21 at 09:00
  • Do you know which columns have those values or do you have to find the columns by code? You can iterate by row number and column number, that would enable you to consider the rows and columns of interest exclusively. – deHaar Jun 11 '21 at 09:14
  • 1
    I can't check the code myself, but it looks like it could be working. What's the problem? Don't you get the desired output? – deHaar Jun 11 '21 at 09:22
  • no , I got the column name as screen_name but I want all the values in that column' – Divyesh Kumar Jun 11 '21 at 09:24
  • @DivyeshKumar are you expecting something of this sort: `screen_name-> {'d_top','ds_level'} , type->{'dropdown','detail'}`. The expected output is still unclear. – dodobird Jun 17 '21 at 09:21

0 Answers0