本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFRow.getCell方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFRow.getCell方法的具體用法?Java HSSFRow.getCell怎麽用?Java HSSFRow.getCell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFRow
的用法示例。
在下文中一共展示了HSSFRow.getCell方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readXls
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
* Read the Excel 2003-2007
*
* @param path
* the path of the Excel
* @return
* @throws IOException
*/
public static String readXls(String path) throws IOException {
InputStream is = new FileInputStream(path);
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
StringBuffer sb = new StringBuffer("");
// Read the Sheet
for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
if (hssfSheet == null) {
continue;
}
// Read the Row
for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
HSSFRow hssfRow = hssfSheet.getRow(rowNum);
if (hssfRow != null) {
HSSFCell no = hssfRow.getCell(0);
HSSFCell name = hssfRow.getCell(1);
sb.append(no + ":" + name);
sb.append(";");
}
}
}
return sb.toString().substring(0, sb.toString().length() - 1);
}
示例2: findMatchColumn
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static Integer findMatchColumn(final HSSFRow row, final String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
final HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
continue;
}
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (cellValue.getString().matches(str)) {
return Integer.valueOf(colNum);
}
}
return null;
}
示例3: getCellValue
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
* 獲取EXCEL文件單元列值
*
* @param row
* @param point
* @return
*/
private static String getCellValue(HSSFRow row, int point) {
String reString = "";
try {
HSSFCell cell = row.getCell((short) point);
if (cell.getCellType() == 1)
reString = cell.getStringCellValue();
else if (cell.getCellType() == 0) {
reString = convert(cell.getNumericCellValue());
BigDecimal bd = new BigDecimal(reString);
reString = bd.toPlainString();
} else {
reString = "";
}
System.out.println(cell.getCellType() + ":" + cell.getCellFormula());
} catch (Exception localException) {
}
return checkNull(reString);
}
示例4: reader
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static void reader(String filePath) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filePath));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.getCell((short) 0);
int type = cell.getCellType();
String msg = getCellStringValue(cell);
System.out.println(type + ":" + msg);
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: findColumn
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static Integer findColumn(HSSFRow row, String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (str.equals(cellValue.getString())) {
return Integer.valueOf(colNum);
}
}
}
return null;
}
示例6: findCell
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static CellLocation findCell(HSSFSheet sheet, String str, int colNum) {
for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet
.getLastRowNum() + 1; rowNum++) {
HSSFRow row = sheet.getRow(rowNum);
if (row == null) {
continue;
}
HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (!Check.isEmpty(cellValue.getString())) {
if (cellValue.getString().equals(str)) {
return new CellLocation(rowNum, (short) colNum);
}
}
}
return null;
}
示例7: getIntCellValue
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static int getIntCellValue(final HSSFSheet sheet, final int r, final int c) {
final HSSFRow row = sheet.getRow(r);
if (row == null) {
return 0;
}
final HSSFCell cell = row.getCell(c);
try {
if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) {
return 0;
}
} catch (final RuntimeException e) {
System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1));
throw e;
}
return (int) cell.getNumericCellValue();
}
示例8: getBooleanCellValue
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static boolean getBooleanCellValue(final HSSFSheet sheet, final int r, final int c) {
final HSSFRow row = sheet.getRow(r);
if (row == null) {
return false;
}
final HSSFCell cell = row.getCell(c);
if (cell == null) {
return false;
}
try {
return cell.getBooleanCellValue();
} catch (final RuntimeException e) {
System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1));
throw e;
}
}
示例9: buildKeywordsValueMap
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
protected Map<String, String> buildKeywordsValueMap(HSSFSheet wordsSheet,
int columnNo, String[] keywords) {
Map<String, String> keywordsValueMap = new HashMap<String, String>();
for (String keyword : keywords) {
CellLocation location = POIUtils.findCell(wordsSheet, keyword,
columnNo);
if (location != null) {
HSSFRow row = wordsSheet.getRow(location.r);
HSSFCell cell = row.getCell(location.c + 2);
String value = cell.getRichStringCellValue().getString();
if (value != null) {
keywordsValueMap.put(keyword, value);
}
}
}
return keywordsValueMap;
}
示例10: getValueByRowCol
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static String getValueByRowCol(HSSFRow sfrow,int col){
HSSFCell cell = sfrow.getCell((short)col);
if (cell == null)
return "";
String msg = getCellStringValue(cell);
return msg;
}
示例11: getCell
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
* Convenient method to obtain the cell in the given sheet, row and column.
* <p>Creates the row and the cell if they still doesn't already exist.
* Thus, the column can be passed as an int, the method making the needed downcasts.
* @param sheet a sheet object. The first sheet is usually obtained by workbook.getSheetAt(0)
* @param row the row number
* @param col the column number
* @return the HSSFCell
*/
protected HSSFCell getCell(HSSFSheet sheet, int row, int col) {
HSSFRow sheetRow = sheet.getRow(row);
if (sheetRow == null) {
sheetRow = sheet.createRow(row);
}
HSSFCell cell = sheetRow.getCell(col);
if (cell == null) {
cell = sheetRow.createCell(col);
}
return cell;
}
示例12: assertXlsOutputCorrect
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
@SuppressWarnings("resource")
private void assertXlsOutputCorrect(byte[] output) throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook(new ByteArrayInputStream(output));
HSSFSheet sheet = workbook.getSheetAt(0);
assertNotNull("Sheet should not be null", sheet);
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.getCell((short) 1);
assertNotNull("Cell should not be null", cell);
assertEquals("Cell content should be Dear Lord!", "Dear Lord!", cell.getRichStringCellValue().getString());
}
示例13: copyRow
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
* @param srcSheet the sheet to copy.
* @param destSheet the sheet to create.
* @param srcRow the row to copy.
* @param destRow the row to create.
* @param styleMap -
*/
public static void copyRow(HSSFSheet srcSheet, HSSFSheet destSheet, HSSFRow srcRow, HSSFRow destRow, Map<Integer, HSSFCellStyle> styleMap) {
// manage a list of merged zone in order to not insert two times a merged zone
Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
destRow.setHeight(srcRow.getHeight());
// pour chaque row
for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
if(j<0){
}else{
HSSFCell oldCell = srcRow.getCell(j); // ancienne cell
HSSFCell newCell = destRow.getCell(j); // new cell
if (oldCell != null) {
if (newCell == null) {
newCell = destRow.createCell(j);
}
// copy chaque cell
copyCell(oldCell, newCell, styleMap);
// copy les informations de fusion entre les cellules
//System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());
CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());
if (mergedRegion != null) {
//System.out.println("Selected merged region: " + mergedRegion.toString());
CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
//System.out.println("New merged region: " + newMergedRegion.toString());
CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
if (isNewMergedRegion(wrapper, mergedRegions)) {
mergedRegions.add(wrapper);
destSheet.addMergedRegion(wrapper.range);
}
}
}
}
}
}
示例14: isBlankRow
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static boolean isBlankRow(HSSFRow row, int index, int rowCount){
if(row == null)
return true;
for(int i=index; i < rowCount; i++){
if(row.getCell(i) != null &&
!"".equals(row.getCell(i).getStringCellValue().trim())){
return false;
}
}
return true;
}
示例15: getCellValue
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static String getCellValue(final HSSFSheet sheet, final CellLocation location) {
final HSSFRow row = sheet.getRow(location.r);
final HSSFCell cell = row.getCell(location.c);
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
return cellValue.toString();
}