List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getCell
@Override public HSSFCell getCell(int cellnum)
From source file:include.excel_import.Outter.java
License:Open Source License
private boolean isBlankRow(HSSFRow hssfrow) { if (hssfrow == null) return true; Iterator iterator = hssfrow.cellIterator(); int i;/*from w w w . ja v a 2 s . co m*/ for (i = 0; iterator.hasNext(); i++) { HSSFCell hssfcell = (HSSFCell) iterator.next(); } for (int j = 0; j < i; j++) { HSSFCell hssfcell1 = hssfrow.getCell((short) j); if (hssfcell1 == null) return true; if (hssfcell1.getCellType() != 3) return false; } return true; }
From source file:include.excel_import.Outter.java
License:Open Source License
private void removeColumn(int i, HSSFSheet hssfsheet) { for (int j = 0; j < getRowCount(hssfsheet); j++) { HSSFRow hssfrow = hssfsheet.getRow(j); HSSFCell hssfcell = hssfrow.getCell((short) i); if (hssfrow != null) hssfrow.removeCell(hssfcell); }//from w w w . j a v a 2 s .c om }
From source file:include.excel_import.Outter.java
License:Open Source License
public boolean validateValue() { for (int i = 0; i < wb.getNumberOfSheets(); i++) { HSSFSheet hssfsheet = wb.getSheetAt(i); String s = wb.getSheetName(i); for (int j = 1; j < getRowCount(hssfsheet); j++) { HSSFRow hssfrow = hssfsheet.getRow(j); HSSFRow hssfrow1 = hssfsheet.getRow(0); for (int k = 0; k < getColumnCount(hssfsheet); k++) { HSSFCell hssfcell = hssfrow1.getCell((short) k); String s1 = hssfcell.getStringCellValue(); HSSFCell hssfcell1 = hssfrow.getCell((short) k); if (!validateType(hssfcell1, s1, s)) { message += "" + (k + 1) + " : " + (j + 1) + "????<br>"; return false; }//from w ww .j a va 2 s.c o m } } } return true; }
From source file:include.excel_import.XlsInfo.java
License:Open Source License
/** * SHEET/*w w w .j a va 2 s . c o m*/ * @param sheet HSSFSheet * @return int */ public int getColumnCount(String sheetName) { if (columnCount.containsKey(sheetName)) { return ((Integer) columnCount.get(sheetName)).intValue(); } HSSFSheet sheet = getSheetForSheetName(sheetName); HSSFRow row = sheet.getRow(0); int size = 0; int cellssize = row.getPhysicalNumberOfCells(); for (int i = 0; i < cellssize; i++) { HSSFCell cell = row.getCell((short) i); if (cell != null) { size++; cell = null; } // end of if () } Integer mysize = new Integer(size); columnCount.put(sheetName, mysize); sheet = null; row = null; mysize = null; //System.gc(); return size; }
From source file:include.excel_import.XlsInfo.java
License:Open Source License
public Vector getColumnsName(String sheetName) { if (columnsNames.containsKey(sheetName)) { return (Vector) columnsNames.get(sheetName); }/*from w w w . j a va2s .c om*/ HSSFSheet sheet = getSheetForSheetName(sheetName); getColumnsName_result.clear(); HSSFRow row = sheet.getRow((short) 0); int cellssize = row.getPhysicalNumberOfCells(); for (int i = 0; i < cellssize; i++) { HSSFCell cell = row.getCell((short) i); getColumnsName_result.addElement(cell.getStringCellValue()); cell = null; } columnsNames.put(sheetName, getColumnsName_result); sheet = null; row = null; //System.gc(); return getColumnsName_result; }
From source file:include.excel_import.XlsInfo.java
License:Open Source License
public Vector getRowValues(int rowNum, Vector columnNames, String sheetName) { getRowValues_result.clear();/* w ww . ja va 2 s. co m*/ HSSFSheet sheet = getSheetForSheetName(sheetName); HSSFRow row = sheet.getRow(rowNum); for (int i = 0; i < getColumnCount(sheetName); i++) { try { Vector allColumnNames = getColumnsName(sheetName); String aName = (String) allColumnNames.elementAt(i); if (columnNames.contains(aName)) { HSSFCell cell = row.getCell((short) i); String itemType = getColumnType(aName, sheetName); dump(getRowValues_result, cell, itemType); cell = null; itemType = null; } // end of if () allColumnNames = null; aName = null; } catch (Exception e) { e.printStackTrace(); } // end of catch } sheet = null; row = null; //System.gc(); return getRowValues_result; }
From source file:include.excel_import.XlsInfo.java
License:Open Source License
public Vector getRowValues(int rowNum, String sheetName) { getRowValues_result.clear();//from w ww. ja va 2s .c o m HSSFSheet sheet = getSheetForSheetName(sheetName); HSSFRow row = sheet.getRow(rowNum); for (int i = 0; i < getColumnCount(sheetName); i++) { HSSFCell cell = row.getCell((short) i); String columnName = (String) getColumnsName(sheetName).elementAt(i); String itemType = getColumnType(columnName, sheetName); dump(getRowValues_result, cell, itemType); cell = null; columnName = null; itemType = null; } sheet = null; row = null; //System.gc(); return getRowValues_result; }
From source file:include.excel_import.XlsInfo.java
License:Open Source License
public String getColumnType(String columnName, String sheetName) { if (columnTypes.containsKey(sheetName + "-" + columnName)) { return (String) columnTypes.get(sheetName + "-" + columnName); }//from w w w.j a va 2 s.co m HSSFSheet sheet = getSheetForSheetName(sheetName); int index = getColumnsName(sheetName).indexOf(columnName); getColumnType_types.clear(); for (int i = 1; i < getRowCount(sheetName); i++) { HSSFRow row = sheet.getRow(i); HSSFCell cell = row.getCell((short) index); //debug!! if (index == -1) { System.err.println("getColumnType: index==-1"); } // end of if () if (cell == null) { System.err.println("getColumnType:cell==null"); } // end of if () String celltype = getCellDataType(cell); if (!getColumnType_types.containsKey(celltype)) { //? getColumnType_types.put(celltype, new Integer(1)); } else { getColumnType_types.put(celltype, new Integer(((Integer) getColumnType_types.get(celltype)).intValue() + 1)); } // end of else row = null; cell = null; celltype = null; } // end of for () Set set = getColumnType_types.keySet(); Iterator it = set.iterator(); Integer max = new Integer(0); String realtype = "BLANK"; int flag = 0; while (it.hasNext()) { String key = (String) it.next(); if (flag == 0) { max = (Integer) getColumnType_types.get(key);//max? realtype = key; flag++; } else if (max.compareTo((Integer) getColumnType_types.get(key)) < 0) { max = (Integer) getColumnType_types.get(key); realtype = key; } //key=null; } // end of while () columnTypes.put(sheetName + "-" + columnName, realtype); sheet = null; set = null; it = null; max = null; //System.gc(); return realtype; }
From source file:include.excel_import.XlsValidator.java
License:Open Source License
/** * ???? /*from w w w .j ava 2 s .c o m*/ * @return true: */ private boolean validateTitle(HSSFSheet sheet, String sheetName) { HSSFRow row = sheet.getRow((short) 0); if (row == null) { // message.append(",SHEET"); return false; } Iterator cells = row.cellIterator(); int size = 0; while (cells.hasNext()) { HSSFCell cell = (HSSFCell) cells.next(); size++; } for (int j = 0; j < size - 1; j++) { HSSFCell cell = row.getCell((short) j); if (cell == null) { return false; } else { if (cell.getCellType() != HSSFCell.CELL_TYPE_STRING) { message.append(""/*sheetName*/).append(""); message.append(j + 1).append("?<br>"); return false; } if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) { message.append(""/*sheetName*/).append("").append(j + 1).append("<br>"); return false; } } } return true; }
From source file:include.excel_import.XlsValidator.java
License:Open Source License
public boolean validateContent() { for (int i = 0; i < wb.getNumberOfSheets(); i++) { HSSFSheet sheet = wb.getSheetAt(i); String sheetName = wb.getSheetName(i); int rowCount = xlsInfo.getRowCount(sheetName); for (int j = 1; j < rowCount; j++) { HSSFRow row = sheet.getRow(j); for (int n = 0; n < xlsInfo.getColumnCount(sheetName); n++) { HSSFCell cell = row.getCell((short) n); if (cell == null) { message.append(""/*sheetName*/).append("("); message.append(n + 1).append(":"); message.append(j + 1).append(")("); message.append(""/*sheetName*/).append(""); message.append(rowCount).append("??)<br>"); return false; }// w w w .jav a 2s. c o m } } } return true; }