Forum Stats

  • 3,768,511 Users
  • 2,252,802 Discussions
  • 7,874,602 Comments

Discussions

how to write cell after check another cell in another excel file?

rio111
rio111 Member Posts: 2
edited Jul 27, 2016 10:37PM in New To Java

i want to write on "Double Order" column after check the "Order ID" column wheter it's double value or not. i use apache poi. can someone help me?

public static void main(String[] args) throws IOException {

      

            FileInputStream file = new FileInputStream(new File(

                    "C:\\Users\\Ricky\\Desktop\\Double Booking1.xlsx"));

          

            XSSFWorkbook workbook = new XSSFWorkbook(file);

          XSSFSheet sheet = workbook.getSheetAt(0);

            Iterator<Row> rowIterator = sheet.iterator();

            while (rowIterator.hasNext()) {

                Row row = rowIterator.next();

               

                Iterator<Cell> cellIterator = row.cellIterator();

                while (cellIterator.hasNext()) {

                    Cell cell = cellIterator.next();

                    if(cell.getColumnIndex()==1) {

                       

                    }

                    System.out.print(cell.toString() + "  ");

                }

                System.out.println();

            }

    }


       

Customer IDOrder IDDouble Order
1004-1445880FU-002774
1004-1445880FU-002774
1004-1445880FU-002774
1004-1445880FU-002774
1004-1445880FU-002774
1004-1445880FU-002850
1004-1445880FU-002850
1004-1445880FU-002850
1004-1445880FU-002850
1004-1445880FU-002850
Tagged:

Answers

  • Jiri.Machotka-Oracle
    Jiri.Machotka-Oracle Member Posts: 5,078
    edited Jul 27, 2016 8:52AM

    Cell cell = cellIterator.next();


    returns you the content of the cell. You need to trace whether you are viewing the Customer ID, Order ID, or Double Order. Now, the question is: is your order id duplicate if only Order ID appears twice or more, or do you want to check the pair [Customer ID, Order]? Either way, you will need some structure that will store these (Order ID, or [Customer ID, Order]) for you, so that you can make a check on duplicity. Since you need just an information whether you have seen this, or not, you can use a Set (e.g. HashSet) to store what's required and use the contains method to check the duplicity. If the Set does not contain the member, you will add it; or you have a duplicate. Find the appropriate method that will allow you to write the result into the Double Order cell.

  • rio111
    rio111 Member Posts: 2
    edited Jul 27, 2016 10:37PM

    @Jiri.Machotka-Oracle it duplicate when the @OrderID appears twice

This discussion has been closed.