List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getRow
@Override public HSSFRow getRow(int rowIndex)
From source file:gtu._work.etc.TestCaseExcelMakerUI.java
License:Open Source License
void loadInitExcel() throws Exception { File file = new File("C:/Users/gtu001/Desktop/RL-10?.xls"); HSSFWorkbook book = ExcelUtil.getInstance().readExcel(file); Map<String, String> map = new HashMap<String, String>(); for (int ii = 0; ii < book.getNumberOfSheets(); ii++) { HSSFSheet sheet = book.getSheetAt(ii); for (int jj = 0; jj <= sheet.getLastRowNum(); jj++) { if (sheet.getRow(jj).getCell(0) == null) { continue; }/*from w ww . j av a2s . co m*/ if (sheet.getRow(jj).getCell(1) == null) { continue; } String key = ExcelUtil.getInstance().readHSSFCell(sheet.getRow(jj).getCell(0)).toUpperCase();//title num String value = ExcelUtil.getInstance().readHSSFCell(sheet.getRow(jj).getCell(1));//title chn map.put(key, value); } } File dir = new File("C:/Users/gtu001/Desktop/ (2)"); Set<String> list = new HashSet<String>(); for (File f : dir.listFiles()) { list.add(f.getName().replaceAll("\\.jpg", "").replaceAll("[a-zA-Z]$", "").toUpperCase()); } JTableUtil util = JTableUtil.newInstance(jTable1); StringBuilder sb = new StringBuilder(); for (Iterator<String> it = list.iterator(); it.hasNext();) { String key = it.next(); if (map.containsKey(key)) { util.getModel().addRow(new Object[] { "rl" + key, map.get(key), "", "" }); } else { sb.append(key + "\n"); } } if (sb.length() != 0) { JCommonUtil._jOptionPane_showMessageDialog_error(sb.toString()); } }
From source file:guardias.CalendarioExcel.java
private void leerExcelFile(File excelFile, List<Medico> listadoMedicos) { InputStream excelStream = null; try {/* w w w.j a va 2 s . com*/ excelStream = new FileInputStream(excelFile); // Representacin del ms alto nivel de la hoja excel. HSSFWorkbook hssfWorkbook = new HSSFWorkbook(excelStream); // Elegimos la hoja que se pasa por parmetro. HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0); // Objeto que nos permite leer un fila de la hoja excel, y de aqu extraer el contenido de las celdas. HSSFRow hssfRow; // Obtengo el nmero de filas ocupadas en la hoja int rows = hssfSheet.getLastRowNum(); // Cadena que usamos para almacenar la lectura de la celda Date cellCalendario; String cellFestivo; String cellPeticion; this.leerGuardiasPrevistas(hssfSheet.getRow(FILA_DEFINICION_GUARDIAS_PREVISTAS), listadoMedicos); List<DiaCalendario> listadoDias = new ArrayList<>(); // Para este ejemplo vamos a recorrer las filas obteniendo los datos que queremos for (int r = COMIENZO_FILAS; r < rows; r++) { hssfRow = hssfSheet.getRow(r); if (hssfRow == null) { break; } else { cellCalendario = hssfRow.getCell(COLUMNA_FECHA_MES).getDateCellValue(); if (cellCalendario != null) { cellFestivo = hssfRow.getCell(COLUMNA_FESTIVO) == null ? "" : hssfRow.getCell(COLUMNA_FESTIVO).getStringCellValue(); LOGGER.log(Level.FINE, "Row: {0} -> [Columna {1}: {2}] [Columna {3}: {4}] ", new Object[] { r, COLUMNA_FECHA_MES, cellFestivo, COLUMNA_FESTIVO, cellFestivo }); DiaCalendario diaCalendario = new DiaCalendario(); diaCalendario.setTime(cellCalendario.getTime()); //Se comprueba si es sabado o Domingo if (TratarFechas.esFinde(diaCalendario)) { diaCalendario.setEsFinde(Boolean.TRUE); //TODO setear nivel de importancia (cada dia del finde tiene una importancia) } else { diaCalendario.setEsFinde(Boolean.FALSE); } if (ES_FESTIVO.equalsIgnoreCase(cellFestivo)) { //Por norma general los festivos se pondrn a dedo diaCalendario.setEsFestivo(Boolean.TRUE); } else { diaCalendario.setEsFestivo(Boolean.FALSE); } //No se tiene en cuenta que tipo de falta tiene (solo tiene que estar vacio) this.obtenerDisponibilidadMedicosEnExcel(listadoMedicos, hssfRow, diaCalendario, listadoMedicos); cellPeticion = hssfRow.getCell(COLUMNA_PETICION) == null ? "" : hssfRow.getCell(COLUMNA_PETICION).getStringCellValue(); LOGGER.log(Level.FINE, "----{0}", cellPeticion); diaCalendario.setPeticionMedico(cellPeticion); listadoDias.add(diaCalendario); } } } this.setListadoDiasCalendario(listadoDias); } catch (FileNotFoundException fileNotFoundException) { LOGGER.log(Level.WARNING, "The file not exists (No se encontro el fichero): {0}", fileNotFoundException); } catch (IOException ex) { LOGGER.log(Level.WARNING, "Error in file procesing (Error al procesar el fichero): {0}", ex); } catch (ExceptionColumnaDisponibilidad ex) { LOGGER.log(Level.WARNING, "Error en lectura de celdas al leer la dispoibilidad, hay alguna celda que no es ni " + CONSTANTE_FIESTA + " ni " + CONSTANTE_CONSULTA + "{0}", ex); } finally { try { excelStream.close(); } catch (IOException ex) { LOGGER.log(Level.WARNING, "Error in file processing after close it (Error al procesar el fichero despues de cerrarlo): {0}", ex); } } }
From source file:guineu.data.parser.impl.GCGCParserXLS.java
License:Open Source License
public void fillData() { try {// ww w. ja va2 s . c o m book = this.openExcel(DatasetName); HSSFSheet sheet; try { sheet = book.getSheet(sheetName); } catch (Exception exception) { sheet = book.getSheetAt(0); } int initRow = this.getRowInit(sheet); if (initRow > -1) { numberRows = this.getNumberRows(initRow, sheet); HSSFRow row = sheet.getRow(initRow); for (int i = 0; i < row.getLastCellNum(); i++) { HSSFCell cell = row.getCell(i); this.head.add(cell.toString()); } this.readMetabolites(initRow + 1, numberRows, sheet); this.setExperimentsName(head); } else { this.dataset = null; } } catch (IOException ex) { Logger.getLogger(GCGCParserXLS.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:guineu.data.parser.impl.GCGCParserXLS.java
License:Open Source License
/** * Reads lipid information.//from w w w . j a va 2 s . com * @param initRow * @param numberRows * @param numberCols * @param sheet */ public void readMetabolites(int initRow, int numberRows, HSSFSheet sheet) { for (int i = initRow; i < numberRows + initRow; i++) { HSSFRow row = sheet.getRow(i); this.readRow(row); this.rowsReaded++; } }
From source file:guineu.data.parser.impl.LCMSParserXLS.java
License:Open Source License
public void fillData() { try {/*from w w w .j a va 2 s . c o m*/ book = this.openExcel(DatasetName); HSSFSheet sheet; try { sheet = book.getSheet(sheetName); } catch (Exception exception) { sheet = book.getSheetAt(0); } int initRow = this.getRowInit(sheet); if (initRow > -1) { numberRows = this.getNumberRows(initRow, sheet); HSSFRow row = sheet.getRow(initRow); for (int i = 0; i < row.getLastCellNum(); i++) { HSSFCell cell = row.getCell((short) i); this.head.add(cell.toString()); } this.readLipids(initRow + 1, numberRows, sheet); this.setExperimentsName(head); } else { this.dataset = null; } } catch (IOException ex) { Logger.getLogger(LCMSParserXLS.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:guineu.data.parser.impl.LCMSParserXLS.java
License:Open Source License
/** * Reads lipid information./* www. j a va 2 s. c o m*/ * @param initRow * @param numberRows * @param numberCols * @param sheet */ public void readLipids(int initRow, int numberRows, HSSFSheet sheet) { for (int i = initRow; i < numberRows + initRow; i++) { HSSFRow row = sheet.getRow(i); this.readRow(row); this.rowsReaded++; } }
From source file:guineu.database.intro.impl.WriteFile.java
License:Open Source License
/** * Writes the LC-MS data set into an excel file. * * @param dataset LC-MS data set/*from w w w .j a v a 2 s .c om*/ * @param path Path where the new file will be created * @param parameters Parameters for saving the file (columns saved in the new file) */ public void WriteExcelFileLCMS(Dataset dataset, String path, SimpleParameterSet parameters) { FileOutputStream fileOut = null; try { // Prepares sheet HSSFSheet sheet; try { FileInputStream fileIn = new FileInputStream(path); POIFSFileSystem fs = new POIFSFileSystem(fileIn); wb = new HSSFWorkbook(fs); int NumberOfSheets = wb.getNumberOfSheets(); sheet = wb.createSheet(String.valueOf(NumberOfSheets)); } catch (Exception exception) { wb = new HSSFWorkbook(); sheet = wb.createSheet("Normalized"); } HSSFRow row = sheet.getRow(0); if (row == null) { row = sheet.createRow(0); } LCMSColumnName elementsObjects[] = parameters.getParameter(SaveLCMSParameters.exportLCMS).getValue(); // Writes head int fieldsNumber = elementsObjects.length; int cont = 0; for (LCMSColumnName p : elementsObjects) { this.setCell(row, cont++, p.getColumnName(), null); } int c = fieldsNumber; for (String experimentName : dataset.getAllColumnNames()) { this.setCell(row, c++, experimentName, null); } // Writes content for (int i = 0; i < dataset.getNumberRows(); i++) { SimplePeakListRowLCMS lipid = (SimplePeakListRowLCMS) dataset.getRow(i); row = sheet.getRow(i + 1); if (row == null) { row = sheet.createRow(i + 1); } cont = 0; for (LCMSColumnName p : elementsObjects) { try { this.setCell(row, cont++, lipid.getVar(p.getGetFunctionName()), null); } catch (Exception ee) { } } c = fieldsNumber; for (String experimentName : dataset.getAllColumnNames()) { this.setCell(row, c++, lipid.getPeak(experimentName), null); } } //Writes the output to a file fileOut = new FileOutputStream(path); wb.write(fileOut); fileOut.close(); } catch (Exception exception) { } }
From source file:guineu.database.intro.impl.WriteFile.java
License:Open Source License
/** * Writes the basic data set into an excel file. * * @param dataset basic data set/*from w w w . j av a 2 s .c o m*/ * @param path Path where the new file will be created */ public void WriteXLSFileBasicDataset(Dataset dataset, String path) { FileOutputStream fileOut = null; try { HSSFSheet sheet; try { FileInputStream fileIn = new FileInputStream(path); POIFSFileSystem fs = new POIFSFileSystem(fileIn); wb = new HSSFWorkbook(fs); int NumberOfSheets = wb.getNumberOfSheets(); sheet = wb.createSheet(String.valueOf(NumberOfSheets)); } catch (Exception exception) { wb = new HSSFWorkbook(); sheet = wb.createSheet("Page 1"); } HSSFRow row = sheet.getRow(0); if (row == null) { row = sheet.createRow(0); } int cont = 0; for (String experimentName : dataset.getAllColumnNames()) { this.setCell(row, cont++, experimentName, null); } HSSFPalette palette = wb.getCustomPalette(); Color[] colors = dataset.getRowColor(); if (colors.length > 0) { for (int i = 0; i < dataset.getNumberRows(); i++) { palette.setColorAtIndex((short) 0x12, (byte) colors[i].getRed(), (byte) colors[i].getGreen(), (byte) colors[i].getBlue()); HSSFColor mycolor = palette.getColor((short) 0x12); //unmodified SimplePeakListRowOther lipid = (SimplePeakListRowOther) dataset.getRow(i); row = sheet.getRow(i + 1); if (row == null) { row = sheet.createRow(i + 1); } int c = 0; for (String experimentName : dataset.getAllColumnNames()) { if (lipid.getPeak(experimentName) == null) { this.setCell(row, c++, "", mycolor); } else { this.setCell(row, c++, lipid.getPeak(experimentName), mycolor); } } } } else { List<String> names = dataset.getAllColumnNames(); for (int i = 0; i < dataset.getNumberRows(); i++) { SimplePeakListRowOther lipid = (SimplePeakListRowOther) dataset.getRow(i); row = sheet.getRow(i + 1); if (row == null) { row = sheet.createRow(i + 1); } for (int j = 0; j < names.size(); j++) { Color c = dataset.getCellColor(i, j + 1); HSSFColor mycolor = null; if (c != null) { mycolor = palette.findColor((byte) c.getRed(), (byte) c.getGreen(), (byte) c.getBlue()); } if (lipid.getPeak(names.get(j)) == null) { this.setCell(row, j, "", null); } else { this.setCell(row, j, lipid.getPeak(names.get(j)), mycolor); } } } } //Write the output to a file fileOut = new FileOutputStream(path); wb.write(fileOut); fileOut.close(); } catch (Exception exception) { } }
From source file:guineu.database.intro.impl.WriteFile.java
License:Open Source License
/** * Writes the GCxGC-MS data set into an excel file. * * @param dataset GCxGC-MS data set/* ww w .ja v a 2s . co m*/ * @param path Path where the new file will be created * @param parameters Parameters for saving the file (columns saved in the new file) */ public void WriteExcelFileGCGC(Dataset dataset, String path, SimpleParameterSet parameters) { FileOutputStream fileOut = null; try { HSSFSheet sheet; try { FileInputStream fileIn = new FileInputStream(path); POIFSFileSystem fs = new POIFSFileSystem(fileIn); wb = new HSSFWorkbook(fs); int NumberOfSheets = wb.getNumberOfSheets(); sheet = wb.createSheet(String.valueOf(NumberOfSheets)); } catch (Exception exception) { wb = new HSSFWorkbook(); sheet = wb.createSheet("Normalized"); } HSSFRow row = sheet.getRow(0); if (row == null) { row = sheet.createRow(0); } GCGCColumnName elementsObjects[] = parameters.getParameter(SaveGCGCParameters.exportGCGC).getValue(); // Write head int fieldsNumber = elementsObjects.length; int cont = 0; for (GCGCColumnName p : elementsObjects) { this.setCell(row, cont++, p.getColumnName(), null); } int c = fieldsNumber; for (String experimentName : dataset.getAllColumnNames()) { this.setCell(row, c++, experimentName, null); } // Write content for (int i = 0; i < dataset.getNumberRows(); i++) { SimplePeakListRowGCGC metabolite = (SimplePeakListRowGCGC) dataset.getRow(i); row = sheet.getRow(i + 1); if (row == null) { row = sheet.createRow(i + 1); } cont = 0; for (GCGCColumnName p : elementsObjects) { try { this.setCell(row, cont++, metabolite.getVar(p.getGetFunctionName()), null); } catch (Exception ee) { } } c = fieldsNumber; for (String experimentName : dataset.getAllColumnNames()) { try { this.setCell(row, c++, metabolite.getPeak(experimentName), null); } catch (Exception e) { this.setCell(row, c, "NA", null); } } } //Write the output to a file fileOut = new FileOutputStream(path); wb.write(fileOut); fileOut.close(); } catch (Exception e) { System.out.println("Inoracle2.java --> WriteExcelFileGCGC() " + e); } }
From source file:guineu.database.intro.impl.WriteFile.java
License:Open Source License
void WriteExcelExpressionSetDataset(Dataset dataset, String path, SimpleParameterSet parameters) { FileOutputStream fileOut = null; try {/*from w w w .java 2s .c om*/ // Prepares sheet HSSFSheet sheet; try { FileInputStream fileIn = new FileInputStream(path); POIFSFileSystem fs = new POIFSFileSystem(fileIn); wb = new HSSFWorkbook(fs); int NumberOfSheets = wb.getNumberOfSheets(); sheet = wb.createSheet(String.valueOf(NumberOfSheets)); } catch (Exception exception) { wb = new HSSFWorkbook(); sheet = wb.createSheet("Normalized"); } HSSFRow row = sheet.getRow(0); if (row == null) { row = sheet.createRow(0); } ExpressionDataColumnName elementsObjects[] = parameters .getParameter(SaveExpressionParameters.exportExpression).getValue(); // Writes head int fieldsNumber = elementsObjects.length; int cont = 0; for (ExpressionDataColumnName p : elementsObjects) { this.setCell(row, cont++, p.getColumnName(), null); } int c = fieldsNumber; for (String experimentName : dataset.getAllColumnNames()) { this.setCell(row, c++, experimentName, null); } // Writes content for (int i = 0; i < dataset.getNumberRows(); i++) { SimplePeakListRowExpression lipid = (SimplePeakListRowExpression) dataset.getRow(i); row = sheet.getRow(i + 1); if (row == null) { row = sheet.createRow(i + 1); } cont = 0; for (ExpressionDataColumnName p : elementsObjects) { try { if (cont == 0) { System.out.println(lipid.getVar(p.getGetFunctionName())); } this.setCell(row, cont++, lipid.getVar(p.getGetFunctionName()), null); } catch (Exception ee) { } } c = fieldsNumber; for (String experimentName : dataset.getAllColumnNames()) { this.setCell(row, c++, lipid.getPeak(experimentName), null); } } //Writes the output to a file fileOut = new FileOutputStream(path); wb.write(fileOut); fileOut.close(); } catch (Exception exception) { } }