List of usage examples for org.apache.poi.hssf.usermodel HSSFCell toString
public String toString()
From source file:utilesBD.servidoresDatos.JServerServidorDatosExcel.java
/** * Metodo que se encarga de leer los datos de un archivo en formato excel * @return Fila que contiene la informacion del archivo *//* www .j ava 2 s . c o m*/ public JFilaDatosDefecto leeLineaExcel(HSSFRow hssfRow) { JFilaDatosDefecto loLinea = new JFilaDatosDefecto(); //Me barro todos los elementos de una fila for (int i = hssfRow.getFirstCellNum(); i < hssfRow.getLastCellNum(); i++) { HSSFCell hssfCell = hssfRow.getCell(i); if (hssfCell != null) { switch (hssfCell.getCellType()) { case HSSFCell.CELL_TYPE_BOOLEAN: loLinea.addCampo(String.valueOf(hssfCell.getBooleanCellValue())); break; case HSSFCell.CELL_TYPE_FORMULA: try { loLinea.addCampo(hssfCell.getStringCellValue()); } catch (Exception e) { try { loLinea.addCampo(String.valueOf(hssfCell.getNumericCellValue())); } catch (Exception e1) { try { loLinea.addCampo(new JDateEdu(hssfCell.getDateCellValue()).toString() .replace("31/12/1899 ", "")); } catch (Exception e2) { try { loLinea.addCampo(String.valueOf(hssfCell.getBooleanCellValue())); } catch (Exception e3) { loLinea.addCampo(""); } } } } break; case HSSFCell.CELL_TYPE_NUMERIC: if (HSSFDateUtil.isCellDateFormatted(hssfCell)) { loLinea.addCampo( new JDateEdu(hssfCell.getDateCellValue()).toString().replace("31/12/1899 ", "")); } else { double ldValor = hssfCell.getNumericCellValue(); loLinea.addCampo( JFormat.msFormatearDouble(ldValor, "############.#########").replace(',', '.')); } break; case HSSFCell.CELL_TYPE_STRING: loLinea.addCampo(hssfCell.toString()); break; default: loLinea.addCampo(""); } } else { loLinea.addCampo(""); } } return loLinea; }
From source file:utility.UploadDataFromFile.java
private void addBillItemMaster() throws IOException, SQLException { int i = 0;/* w w w . j a v a 2s . c o m*/ String filename = jtxtDatabaseLocation.getText(); // // Create an ArrayList to store the data read from excel sheet. // List sheetData = new ArrayList(); FileInputStream fis = null; // // Create a FileInputStream that will be use to read the excel file. // fis = new FileInputStream(filename); // // Create an excel workbook from the file system. // HSSFWorkbook workbook = new HSSFWorkbook(fis); // // Get the first sheet on the workbook. // HSSFSheet sheet = workbook.getSheetAt(0); // // When we have a sheet object in hand we can iterator on each // sheet's rows and on each row's cells. We store the data read // on an ArrayList so that we can printed the content of the excel // to the console. // Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = sheet.getRow(i); i++; List data = new ArrayList(); if (row != null) { for (int j = 0; j < 8; j++) { HSSFCell cell = row.getCell(j); if (cell != null) { data.add(cell.toString().toUpperCase()); } else { data.add(""); } } } else { break; } sheetData.add(data); } addBillItemMasterINDatabase(sheetData); }
From source file:utility.UploadDataFromFile.java
private void addDoctorAccountMaster() throws IOException, SQLException { int i = 0;/*from w ww . j a v a 2 s . c o m*/ String filename = jtxtDatabaseLocation.getText(); // // Create an ArrayList to store the data read from excel sheet. // List sheetData = new ArrayList(); FileInputStream fis = null; // // Create a FileInputStream that will be use to read the excel file. // fis = new FileInputStream(filename); // // Create an excel workbook from the file system. // HSSFWorkbook workbook = new HSSFWorkbook(fis); // // Get the first sheet on the workbook. // HSSFSheet sheet = workbook.getSheetAt(0); // // When we have a sheet object in hand we can iterator on each // sheet's rows and on each row's cells. We store the data read // on an ArrayList so that we can printed the content of the excel // to the console. // Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = sheet.getRow(i); i++; List data = new ArrayList(); if (row != null) { for (int j = 0; j < 9; j++) { HSSFCell cell = row.getCell(j); if (cell != null) { data.add(cell.toString().toUpperCase()); } else { data.add(""); } } } else { break; } sheetData.add(data); } addAccountInDatabase(sheetData); }
From source file:utility.UploadDataFromFile.java
private void addReferanceDoctorAccountMaster() throws IOException, SQLException { int i = 0;/*from w ww . j a va 2 s . c o m*/ String filename = jtxtDatabaseLocation.getText(); // // Create an ArrayList to store the data read from excel sheet. // List sheetData = new ArrayList(); FileInputStream fis = null; // // Create a FileInputStream that will be use to read the excel file. // fis = new FileInputStream(filename); // // Create an excel workbook from the file system. // HSSFWorkbook workbook = new HSSFWorkbook(fis); // // Get the first sheet on the workbook. // HSSFSheet sheet = workbook.getSheetAt(0); // // When we have a sheet object in hand we can iterator on each // sheet's rows and on each row's cells. We store the data read // on an ArrayList so that we can printed the content of the excel // to the console. // Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = sheet.getRow(i); i++; List data = new ArrayList(); if (row != null) { for (int j = 0; j < 8; j++) { HSSFCell cell = row.getCell(j); if (cell != null) { data.add(cell.toString().toUpperCase()); } else { data.add(""); } } } else { break; } sheetData.add(data); } addRefDoctorAccountInDatabase(sheetData); }
From source file:utility.UploadDataFromFile.java
private void addDoctorMaster() throws IOException, SQLException { int i = 0;//from w w w.j a v a 2s.c o m String filename = jtxtDatabaseLocation.getText(); // // Create an ArrayList to store the data read from excel sheet. // List sheetData = new ArrayList(); FileInputStream fis = null; // // Create a FileInputStream that will be use to read the excel file. // fis = new FileInputStream(filename); // // Create an excel workbook from the file system. // HSSFWorkbook workbook = new HSSFWorkbook(fis); // // Get the first sheet on the workbook. // HSSFSheet sheet = workbook.getSheetAt(0); // // When we have a sheet object in hand we can iterator on each // sheet's rows and on each row's cells. We store the data read // on an ArrayList so that we can printed the content of the excel // to the console. // Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = sheet.getRow(i); i++; List data = new ArrayList(); if (row != null) { for (int j = 0; j < 3; j++) { HSSFCell cell = row.getCell(j); if (cell != null) { data.add(cell.toString().toUpperCase()); } else { data.add(""); } } } else { break; } sheetData.add(data); } addDoctorInDatabase(sheetData); }
From source file:utility.UploadDataFromFile.java
private void addPatientMaster() throws IOException, SQLException { int i = 0;//w w w. j av a 2s. com String filename = jtxtDatabaseLocation.getText(); // // Create an ArrayList to store the data read from excel sheet. // List sheetData = new ArrayList(); FileInputStream fis = null; // // Create a FileInputStream that will be use to read the excel file. // fis = new FileInputStream(filename); // // Create an excel workbook from the file system. // HSSFWorkbook workbook = new HSSFWorkbook(fis); // // Get the first sheet on the workbook. // HSSFSheet sheet = workbook.getSheetAt(0); // // When we have a sheet object in hand we can iterator on each // sheet's rows and on each row's cells. We store the data read // on an ArrayList so that we can printed the content of the excel // to the console. // Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = sheet.getRow(i); i++; List data = new ArrayList(); if (row != null) { for (int j = 0; j < 11; j++) { HSSFCell cell = row.getCell(j); if (cell != null) { data.add(cell.toString().toUpperCase()); } else { data.add(""); } } } else { break; } sheetData.add(data); } addPatientInDatabase(sheetData); }
From source file:velo.importer.AccountsList.java
License:Open Source License
public void importFromXls(InputStream is, String spreadSheetName) throws Exception { HSSFWorkbook workbook = new HSSFWorkbook(is); //Count the number of sheets if (workbook.getNumberOfSheets() < 1) { throw new Exception("Number of sheets in excel is less than 1!"); }// w w w .j a v a 2s . c om HSSFSheet sheet = workbook.getSheet(spreadSheetName); if (sheet == null) { throw new Exception("Could not find sheet named '" + spreadSheetName + "'"); } //todo 3 cells at least! //Make sure the headers correspond to the expected values HSSFRow header = sheet.getRow(0); HSSFCell accountNameTitle = header.getCell((short) 0); HSSFCell targetNameTitle = header.getCell((short) 1); if (!accountNameTitle.toString().equalsIgnoreCase("ACCOUNT")) { throw new Exception( "Column one in first row must equal to 'ACCOUNT' and represents the Account to associate"); } if (!targetNameTitle.toString().equalsIgnoreCase("RESOURCE_UNIQUE_NAME")) { throw new Exception( "Column one in first row must equal to 'RESOURCE_UNIQUE_NAME' and represents the resource unique name the account is related to!"); } for (int i = 1; i <= sheet.getLastRowNum(); i++) { HSSFRow row = sheet.getRow(i); HSSFCell accountName = row.getCell((short) 0); HSSFCell targetName = row.getCell((short) 1); String targetNameErrMsg = "Target Name at row # '" + i + "' is empty!"; if (targetName == null) { throw new Exception(targetNameErrMsg); } else if (targetName.toString().length() < 1) { throw new Exception(targetNameErrMsg); } String accountErrMsg = "Account Name at row # '" + i + "' is empty!"; if (accountName == null) { throw new Exception(accountErrMsg); } else if (accountName.toString().length() < 1) { throw new Exception(accountErrMsg); } System.out.println("Row(" + i + ") - Account: '" + accountName.toString() + "', On Target: '" + targetName.toString() + "'"); velo.importer.ImportAccount ia = new velo.importer.ImportAccount(); ia.setResourceName(targetName.toString()); ia.setAccountName(accountName.toString()); this.add(ia); } }
From source file:velo.importer.AccountsToUsersList.java
License:Open Source License
public void importFromXls(InputStream is, String spreadSheetName) throws Exception { HSSFWorkbook workbook = new HSSFWorkbook(is); //Count the number of shits if (workbook.getNumberOfSheets() < 1) { throw new Exception("Number of sheets in excel is less than 1!"); }/* w ww .j a v a 2 s.c o m*/ HSSFSheet sheet = workbook.getSheet(spreadSheetName); if (sheet == null) { throw new Exception("Could not find sheet named '" + spreadSheetName + "'"); } //todo 3 cells at least! //Make sure the headers correspond to the expected values HSSFRow header = sheet.getRow(0); HSSFCell userNameTitle = header.getCell((short) 0); HSSFCell accountNameTitle = header.getCell((short) 1); HSSFCell targetNameTitle = header.getCell((short) 2); if (!userNameTitle.toString().equalsIgnoreCase("USER")) { throw new Exception( "Column one in first row must equal to 'USER' and represents the User that owns the account!"); } if (!accountNameTitle.toString().equalsIgnoreCase("ACCOUNT")) { throw new Exception( "Column one in first row must equal to 'ACCOUNT' and represents the Account to associate"); } if (!targetNameTitle.toString().equalsIgnoreCase("RESOURCE_UNIQUE_NAME")) { throw new Exception( "Column one in first row must equal to 'TARGET-SYSTEM' and represents the resource unique name the account is related to!"); } for (int i = 1; i <= sheet.getLastRowNum(); i++) { HSSFRow row = sheet.getRow(i); HSSFCell userName = row.getCell((short) 0); HSSFCell accountName = row.getCell((short) 1); HSSFCell targetName = row.getCell((short) 2); String targetNameErrMsg = "Target Name at row # '" + i + "' is empty!"; if (targetName == null) { throw new Exception(targetNameErrMsg); } else if (targetName.toString().length() < 1) { throw new Exception(targetNameErrMsg); } String userNameErrMsg = "User Name at row # '" + i + "' is empty!"; if (userName == null) { throw new Exception(userNameErrMsg); } else if (userName.toString().length() < 1) { throw new Exception(userNameErrMsg); } String accountErrMsg = "Account Name at row # '" + i + "' is empty!"; if (accountName == null) { throw new Exception(accountErrMsg); } else if (accountName.toString().length() < 1) { throw new Exception(accountErrMsg); } //System.out.println("Row("+i+") - User: '" + userName.toString() + "', Account: '" + accountName.toString() + "', On Target: '" + targetName.toString() + "'"); velo.importer.ImportAccountToUser iatu = new velo.importer.ImportAccountToUser(); iatu.setUserName(userName.toString()); iatu.setResourceName(targetName.toString()); iatu.setAccountName(accountName.toString()); this.add(iatu); } }
From source file:velo.importer.RolesToRolesFolderList.java
License:Open Source License
public void importFromXls(InputStream is, String spreadSheetName) throws Exception { HSSFWorkbook workbook = new HSSFWorkbook(is); //Count the number of sheets if (workbook.getNumberOfSheets() < 1) { throw new Exception("Number of sheets in excel is less than 1!"); }//w w w. j a va 2 s. c o m HSSFSheet sheet = workbook.getSheet(spreadSheetName); if (sheet == null) { throw new Exception("Could not find sheet named '" + spreadSheetName + "'"); } //todo 3 cells at least! //Make sure the headers correspond to the expected values HSSFRow header = sheet.getRow(0); HSSFCell accountNameTitle = header.getCell((short) 0); HSSFCell targetNameTitle = header.getCell((short) 1); if (!accountNameTitle.toString().equalsIgnoreCase("ROLE_UNIQUE_NAME")) { throw new Exception( "Column one in first row must equal to 'ROLE_UNIQUE_NAME' and represents the Role to create"); } if (!targetNameTitle.toString().equalsIgnoreCase("ROLES_FOLDER_UNIQUE_NAME")) { throw new Exception( "Column one in first row must equal to 'ROLES_FOLDER_UNIQUE_NAME' and represents the roles folder unique name the role is related to!"); } for (int i = 1; i <= sheet.getLastRowNum(); i++) { HSSFRow row = sheet.getRow(i); HSSFCell roleName = row.getCell((short) 0); HSSFCell rolesFolderName = row.getCell((short) 1); String RolesFolderNameErrMsg = "Roles Folder Name at row # '" + i + "' is empty!"; if (rolesFolderName == null) { throw new Exception(RolesFolderNameErrMsg); } else if (rolesFolderName.toString().length() < 1) { throw new Exception(RolesFolderNameErrMsg); } String roleErrMsg = "Role Name at row # '" + i + "' is empty!"; if (roleName == null) { throw new Exception(roleErrMsg); } else if (roleName.toString().length() < 1) { throw new Exception(roleErrMsg); } System.out.println("Row(" + i + ") - Role: '" + roleName.toString() + "', On Roles Folder: '" + rolesFolderName.toString() + "'"); ImportRoleToRolesFolder role = new ImportRoleToRolesFolder(roleName.toString(), rolesFolderName.toString()); this.add(role); } }