Created
January 18, 2024 13:34
-
-
Save antoniomalves/3e917e4482c78d1cd7d4e3753b8ee452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.antoniomalves; | |
import org.apache.poi.ss.usermodel.Cell; | |
import org.apache.poi.ss.usermodel.Row; | |
import org.apache.poi.xssf.usermodel.XSSFSheet; | |
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |
import java.io.FileInputStream; | |
import java.util.Iterator; | |
/** | |
* Hello world! | |
* | |
*/ | |
public class App | |
{ | |
private static String MULHER = "F"; | |
public static void main( String[] args ) | |
{ | |
try | |
{ | |
Integer totalMulheres = 0; | |
FileInputStream file = new FileInputStream("C:\\Users\\anton\\Downloads\\Estudo_de_Caso_PGFN.xlsx"); | |
//Create Workbook instance holding reference to .xlsx file | |
XSSFWorkbook wb = new XSSFWorkbook(file); | |
//Get first/desired sheet from the workbook | |
XSSFSheet ws = wb.getSheetAt(0); | |
//Iterate through each rows one by one | |
Iterator<Row> rowIterator = ws.iterator(); | |
while (rowIterator.hasNext()) | |
{ | |
Row row = rowIterator.next(); | |
if(row.getRowNum() == 0){ | |
continue; | |
} | |
//For each row, iterate through all the columns | |
Iterator<Cell> cellIterator = row.cellIterator(); | |
while (cellIterator.hasNext()) | |
{ | |
Cell cell = cellIterator.next(); | |
//Check the cell type and format accordingly | |
if( cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getColumnIndex() == 5 && cell.getStringCellValue().equals(MULHER)) { | |
totalMulheres++; | |
} | |
} | |
} | |
file.close(); | |
System.out.println("Total de Mulheres: " + totalMulheres) ; | |
} | |
catch (Exception ex) | |
{ | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment