Example usage for org.apache.poi.hssf.usermodel HSSFSheet iterator

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet iterator

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet iterator.

Prototype

@Override
public Iterator<Row> iterator() 

Source Link

Document

Alias for #rowIterator() to allow foreach loops

Usage

From source file:org.wandora.application.tools.extractors.excel.ExcelAdjacencyMatrixExtractor.java

License:Open Source License

public void processSheet(HSSFSheet sheet, TopicMap tm) {
    Iterator<Row> rowIterator = sheet.iterator();
    boolean isFirst = true;
    columnLabels = new HashMap();
    rowLabels = new HashMap();
    while (rowIterator.hasNext() && !forceStop()) {
        Row row = rowIterator.next();// www .  j a  va2s .  c o m
        if (isFirst) {
            processAsLabels(row, tm);
            isFirst = false;
        } else {
            processRow(row, tm);
        }
    }
}

From source file:org.wandora.application.tools.extractors.excel.ExcelTopicExtractor.java

License:Open Source License

public void processSheet(HSSFSheet sheet, TopicMap tm) {
    Iterator<Row> rowIterator = sheet.iterator();
    while (rowIterator.hasNext() && !forceStop()) {
        Row row = rowIterator.next();/*from w ww . j  av  a  2  s  .  com*/
        processRow(row, tm);
    }
}

From source file:org.wandora.application.tools.extractors.excel.ExcelTopicNameExtractor.java

License:Open Source License

public void processSheet(HSSFSheet sheet, TopicMap tm) {
    Iterator<Row> rowIterator = sheet.iterator();
    boolean isFirst = true;
    languagesPerColumn = new HashMap();
    while (rowIterator.hasNext() && !forceStop()) {
        Row row = rowIterator.next();/* w w  w. ja  va2  s  .  c o  m*/
        if (isFirst && FIRST_ROW_CONTAINS_LANGUAGES) {
            processRowAsLanguages(row, tm);
            isFirst = false;
        } else {
            processRow(row, tm);
        }
    }
}

From source file:org.wandora.application.tools.extractors.excel.ExcelTopicOccurrenceExtractor.java

License:Open Source License

public void processSheet(HSSFSheet sheet, TopicMap tm) {
    Iterator<Row> rowIterator = sheet.iterator();
    boolean isFirst = true;
    occurrenceTypes = new HashMap();
    while (rowIterator.hasNext() && !forceStop()) {
        Row row = rowIterator.next();/*from w  w w.j a va 2 s .  c  o m*/
        if (isFirst && FIRST_ROW_CONTAINS_OCCURRENCE_TYPES) {
            processRowAsOccurrenceTypes(row, tm);
            isFirst = false;
        } else {
            processRow(row, tm);
        }
    }
}

From source file:org.wandora.application.tools.extractors.excel.ExcelTopicTreeExtractor.java

License:Open Source License

public void processSheet(HSSFSheet sheet, TopicMap tm) {
    Iterator<Row> rowIterator = sheet.iterator();
    hierarchy = new Topic[1000];
    while (rowIterator.hasNext() && !forceStop()) {
        Row row = rowIterator.next();// ww  w  .  j  a v a2 s .  c  o  m
        processRow(row, tm);
    }
}

From source file:personality_prediction.Liwcdict.java

void extract_features() {
    File f = new File("C:\\Users\\divya\\Desktop\\Personality Mining\\LIWC2007.cat");
    LIWCDictionary dict = new LIWCDictionary(f);
    System.out.println("1.. for viewing dictionary");
    System.out.println("2..generating excel file");
    Scanner sc = new Scanner(System.in);
    int choice = sc.nextInt();
    if (choice == 1) {
        dict.Display_Dictionary_Map();
    } else {// w w w  .  ja  v  a  2s  .c  om
        Liwcdict obj = new Liwcdict();
        Map<String, Double> counts;
        // String filename="C:\\Users\\somya\\Desktop\\Personality Mining\\WEKA_Dataset\\feature_values.xls" ;
        HSSFWorkbook hwb = new HSSFWorkbook();
        HSSFSheet sheet = hwb.createSheet("new sheet");
        try {
            FileInputStream file = new FileInputStream(new File(
                    "C:\\Users\\divya\\Desktop\\Personality Mining\\mypersonality_final\\mypersonality_final.xls"));
            //Create Workbook instance holding reference to .xlsx file
            HSSFWorkbook workbook = new HSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            HSSFSheet sheet_1 = workbook.getSheetAt(0);
            Iterator<Row> rowIterator = sheet_1.iterator();
            int row_count = 0;
            while (rowIterator.hasNext()) {
                //for(int i=0;i<10;i++){
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();
                Cell cell = cellIterator.next();
                cell = cellIterator.next();
                String tweet = cell.getStringCellValue();

                counts = dict.getJustCounts(tweet, true);
                //counts=dict.getCounts(tweet, true);
                obj.export2excel(counts, row_count, tweet, sheet, hwb);
                System.out.println(tweet);
                //Check the cell type and format accordingly
                //System.out.print(cell.getStringCellValue() + "t");
                row_count++;
            }
            file.close();
        }

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

        // LIWCDictionary.tokenize("g hjgjh hgjh");
    }
}

From source file:personality_prediction.Liwcdict.java

void fetch_tweet() {
    try {/*w w w.  ja v  a  2  s  .  c o  m*/
        FileInputStream file = new FileInputStream(new File(
                "C:\\Users\\somya\\Desktop\\Personality Mining\\mypersonality_final\\mypersonality_final.xls"));
        //Create Workbook instance holding reference to .xlsx file
        HSSFWorkbook workbook = new HSSFWorkbook(file);

        //Get first/desired sheet from the workbook
        HSSFSheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();
        int row_count = 0;
        //while (rowIterator.hasNext())
        for (int i = 0; i < 10; i++) {
            Row row = rowIterator.next();
            //For each row, iterate through all the columns
            Iterator<Cell> cellIterator = row.cellIterator();

            Cell cell = cellIterator.next();
            cell = cellIterator.next();
            String tweet = cell.getStringCellValue();
            System.out.println(tweet);
            //Check the cell type and format accordingly
            //System.out.print(cell.getStringCellValue() + "t");

            row_count++;

            file.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ProduseFurnizor.ProduseFurnizor9.java

public ArrayList<Produs> getProduse() {
    ArrayList<Produs> produse = new ArrayList<>();
    try {/*  w w w.  j  a  v a  2 s  .co m*/

        urlFurnizor = new URL(url);
        in = urlFurnizor.openStream();

        HSSFWorkbook workbook = new HSSFWorkbook(in);
        HSSFSheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            if (row.getRowNum() != 0) {
                int stocFurnizor;
                Produs p = new Produs(null, null, null, 0, 0, false);
                //System.out.println("Parcurgem rand " + row.getRowNum());
                String codProdus = row.getCell(0).getStringCellValue().trim();
                String denumireProdus = row.getCell(1).getStringCellValue().trim();
                switch (row.getCell(2).getCellType()) {
                case (Cell.CELL_TYPE_STRING):
                    stocFurnizor = Integer.parseInt(row.getCell(2).getStringCellValue());
                    break;
                case (Cell.CELL_TYPE_NUMERIC):
                    stocFurnizor = (int) Math.round(row.getCell(2).getNumericCellValue());
                    break;
                default:
                    stocFurnizor = 0;
                }

                //System.out.println(codProdus + "/" + denumireProdus + "/" + stocFurnizor);
                p.setFurnizor("Hubners");
                p.setCodProdus(codProdus);
                p.setNume(denumireProdus);
                p.setCantitate(stocFurnizor);
                int cantitateSite = ProduseController.getInstance().getStocSite(p);
                if (cantitateSite != 99999) {
                    p.setCantitateSite(cantitateSite);
                    p.setInSite(true);
                } else {
                    p.setCantitateSite(0);
                }

                double pretFurnizor = row.getCell(3).getNumericCellValue();
                p.setPretFurnizor(pretFurnizor);
                produse.add(p);
            }

        }

    } catch (Exception ex) {
        Logger.getLogger(ProduseFurnizor9.class.getName()).log(Level.SEVERE, null, ex);
    }
    return produse;
}

From source file:regression.home.java

public void openData() {
    JFileChooser fileChooser = new JFileChooser();
    int returnValue = fileChooser.showOpenDialog(null);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        try {//from  w  w w . j a va2  s. c  om
            FileInputStream file = new FileInputStream(selectedFile.getPath());
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> rowIteratorCount = sheet.iterator();
            Iterator<Row> rowIteratorValue = sheet.iterator();
            int rowCount = 0, colCount = 0, rowValue = 0, colValue = 0;

            while (rowIteratorCount.hasNext()) {
                Row row = rowIteratorCount.next();
                Iterator<Cell> cellIteratorCount = row.cellIterator();
                colCount = 0;
                while (cellIteratorCount.hasNext()) {
                    Cell cell = cellIteratorCount.next();
                    colCount++;
                }
                rowCount++;
            }
            di.header = new String[colCount];
            di.dataValue = new String[rowCount - 1][colCount];

            while (rowIteratorValue.hasNext()) {
                Row row = rowIteratorValue.next();
                Iterator<Cell> cellIteratorValue = row.cellIterator();
                colValue = 0;
                while (cellIteratorValue.hasNext()) {
                    Cell cell = cellIteratorValue.next();
                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        if (rowValue == 0) {
                            di.header[colValue] = String.valueOf(cell.getBooleanCellValue());
                        } else {
                            di.dataValue[rowValue - 1][colValue] = String.valueOf(cell.getBooleanCellValue());
                        }
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        if (rowValue == 0) {
                            di.header[colValue] = String.valueOf(cell.getNumericCellValue());
                        } else {
                            double cellVal = cell.getNumericCellValue();
                            String dt = null;
                            if (cellVal % 1 != 0) {
                                dt = new DecimalFormat("#0.00##").format(cell.getNumericCellValue());
                                di.dataValue[rowValue - 1][colValue] = dt;
                            } else {
                                dt = new DecimalFormat("#0").format(cell.getNumericCellValue());
                                di.dataValue[rowValue - 1][colValue] = dt;
                            }
                        }
                        break;
                    case Cell.CELL_TYPE_STRING:
                        if (rowValue == 0) {
                            di.header[colValue] = String.valueOf(cell.getStringCellValue());

                        } else {
                            di.dataValue[rowValue - 1][colValue] = String.valueOf(cell.getStringCellValue());
                        }
                        break;
                    }
                    colValue++;
                }
                rowValue++;
            }
            DefaultTableModel model = new DefaultTableModel(di.dataValue, di.header);
            di.jTable1.setModel(model);
            di.jTable1.getTableHeader().setFont(new Font("Tahoma", Font.PLAIN, 16));
            for (int c = 0; c < di.header.length; c++) {
                di.jTable1.getColumnModel().getColumn(c).setCellRenderer(new FTable());
            }

            file.close();
            di.setVisible(true);
            dispose();
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(fileChooser, "File Not Found");
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(fileChooser, "Ekstensi File yang Anda masukkan salah");
        }
    }
}

From source file:regression._dataImport.java

public void openData() {
    JFileChooser fileChooser = new JFileChooser();
    int returnValue = fileChooser.showOpenDialog(null);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        try {//from   w w  w.  j av  a2s  .  com
            FileInputStream file = new FileInputStream(selectedFile.getPath());
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> rowIteratorCount = sheet.iterator();
            Iterator<Row> rowIteratorValue = sheet.iterator();
            int rowCount = 0, colCount = 0, rowValue = 0, colValue = 0;

            while (rowIteratorCount.hasNext()) {
                Row row = rowIteratorCount.next();
                Iterator<Cell> cellIteratorCount = row.cellIterator();
                colCount = 0;
                while (cellIteratorCount.hasNext()) {
                    Cell cell = cellIteratorCount.next();
                    colCount++;
                }
                rowCount++;
            }
            header = new String[colCount];
            dataValue = new String[rowCount - 1][colCount];

            while (rowIteratorValue.hasNext()) {
                Row row = rowIteratorValue.next();
                Iterator<Cell> cellIteratorValue = row.cellIterator();
                colValue = 0;
                while (cellIteratorValue.hasNext()) {
                    Cell cell = cellIteratorValue.next();
                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        if (rowValue == 0) {
                            header[colValue] = String.valueOf(cell.getBooleanCellValue());
                        } else {
                            dataValue[rowValue - 1][colValue] = String.valueOf(cell.getBooleanCellValue());
                        }
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        if (rowValue == 0) {
                            header[colValue] = String.valueOf(cell.getNumericCellValue());
                        } else {
                            double cellVal = cell.getNumericCellValue();
                            String dt = null;
                            if (cellVal % 1 != 0) {
                                dt = new DecimalFormat("#0.00##").format(cell.getNumericCellValue());
                                dataValue[rowValue - 1][colValue] = dt;
                            } else {
                                dt = new DecimalFormat("#0").format(cell.getNumericCellValue());
                                dataValue[rowValue - 1][colValue] = dt;
                            }
                        }
                        break;
                    case Cell.CELL_TYPE_STRING:
                        if (rowValue == 0) {
                            header[colValue] = String.valueOf(cell.getStringCellValue());

                        } else {
                            dataValue[rowValue - 1][colValue] = String.valueOf(cell.getStringCellValue());
                        }
                        break;
                    }
                    colValue++;
                }
                rowValue++;
            }
            DefaultTableModel model = new DefaultTableModel(dataValue, header);
            jTable1.setModel(model);
            for (int c = 0; c < header.length; c++) {
                jTable1.getColumnModel().getColumn(c).setCellRenderer(new FTable());
            }

            file.close();
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(fileChooser, "File Not Found");
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(fileChooser, "Wrong File Type Selected");
        }
    }
}