/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 *
 * @author oracle_java
 */
public class NHT2 {

    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);


            //---------------------------read from XML and store in array----------------------------------//

            int x = sheet.getRows() - 1;       // Machines_numbers
            int y = sheet.getColumns() - 1;    // Jobs_numbers
            // we subtracted 1 from rows and coulumns because the first row and column is test

            String[][] array = new String[x][y]; //processing time for every product on every machine
            int[][] arr = new int[x][y]; //هنا اضنا المصفوفة الجديدة من النوع انتجر

            String output = "";   // Accumulate text here (should be StringBuilder).
            //... Print array in rectangular form using nested for loops.
            for (int i = 1; i < sheet.getRows(); i++) {
                for (int j = 1; j < sheet.getColumns(); j++) {

                    Cell cell = sheet.getCell(j, i);


                    array[i - 1][j - 1] = cell.getContents();

                    arr[i - 1][j - 1] = Integer.parseInt(array[i - 1][j - 1]);// هنا قمت بعملية التحويل بين الصنفين

                    output += " " + arr[i - 1][j - 1]; // أريد طباعة المصفوفة الجديدة
                }
                output += "\n";
            }



            JOptionPane.showMessageDialog(null, "The input is " + "\n" + output,
                    "F" + (sheet.getRows() - 1) + "|Sijk, prmu|Cmax", JOptionPane.INFORMATION_MESSAGE);


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

    public static void main(String[] args) throws IOException {
        NEHT read = new NEHT();
        read.setInputFile("c:/temp/test1.xls"); // مكان تخزين الملف المطلوب قرائته
        read.read();

        System.exit(0);

    }
}
