當前位置: 首頁>>代碼示例>>Java>>正文


Java HSSFSheet.getRow方法代碼示例

本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getRow方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFSheet.getRow方法的具體用法?Java HSSFSheet.getRow怎麽用?Java HSSFSheet.getRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.hssf.usermodel.HSSFSheet的用法示例。


在下文中一共展示了HSSFSheet.getRow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copySheets

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
/**
 * @param newSheet the sheet to create from the copy.
 * @param sheet the sheet to copy.
 * @param copyStyle true copy the style.
 */
public static void copySheets(HSSFSheet newSheet, HSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, HSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, HSSFCellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        HSSFRow srcRow = sheet.getRow(i);
        HSSFRow destRow = newSheet.createRow(i);
        if (srcRow != null) {
            Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
   //Util.copyPictures(newSheet,sheet) ;
}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:24,代碼來源:Util.java

示例2: findCell

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static CellLocation findCell(final HSSFSheet sheet, final String[] strs) {
    for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum() + 1; rowNum++) {
        final HSSFRow row = sheet.getRow(rowNum);
        if (row == null) {
            continue;
        }

        for (int i = 0; i < strs.length; i++) {
            final Integer colNum = findColumn(row, strs[i]);

            if (colNum != null) {
                return new CellLocation(rowNum, colNum.shortValue());
            }
        }
    }

    return null;
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:19,代碼來源:POIUtils.java

示例3: reader

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的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();
	}
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:15,代碼來源:ReadExcelUtil.java

示例4: findCell

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的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;
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:25,代碼來源:POIUtils.java

示例5: findMatchCell

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static CellLocation findMatchCell(HSSFSheet sheet, String regexp) {
	for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet
			.getLastRowNum() + 1; rowNum++) {
		HSSFRow row = sheet.getRow(rowNum);
		if (row == null) {
			continue;
		}

		Integer colNum = findMatchColumn(row, regexp);

		if (colNum != null) {
			return new CellLocation(rowNum, colNum.shortValue());
		}
	}

	return null;
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:18,代碼來源:POIUtils.java

示例6: readExcel

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static void readExcel(String filePth) throws Exception {
	InputStream is = new FileInputStream(filePth);
	//創建工作薄
	//XSSFWorkbook hwb = new XSSFWorkbook(is);
	HSSFWorkbook hwb = new HSSFWorkbook(new POIFSFileSystem(is));
	//得到sheet
	for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
		HSSFSheet sheet = hwb.getSheetAt(i);
		int rows = sheet.getPhysicalNumberOfRows();
		//遍曆每一行
		for (int j = 0; j < rows; j++) {
			HSSFRow hr = sheet.getRow(j);
			Iterator<?> it = hr.iterator();
			while(it.hasNext()){
				String context = it.next().toString();
				System.out.println(context);
			}
		}
	}
	hwb.close();
}
 
開發者ID:tank2140896,項目名稱:JavaWeb,代碼行數:22,代碼來源:FileUtil.java

示例7: getBooleanCellValue

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static boolean getBooleanCellValue(HSSFSheet sheet, int r, int c) {
	HSSFRow row = sheet.getRow(r);

	if (row == null) {
		return false;
	}

	HSSFCell cell = row.getCell(c);

	if (cell == null) {
		return false;
	}

	try {
		return cell.getBooleanCellValue();
	} catch (RuntimeException e) {
		System.err.println("Exception at sheet name:"
				+ sheet.getSheetName() + ", row:" + (r + 1) + ", col:"
				+ (c + 1));
		throw e;
	}
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:23,代碼來源:POIUtils.java

示例8: getIntCellValue

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的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();
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:19,代碼來源:POIUtils.java

示例9: parseGroupSpreadsheet

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public int parseGroupSpreadsheet(FormFile fileItem, Long groupingID, Map<String, Set<String>> groups)
    throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(fileItem.getInputStream());
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);

int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
int skipped = 0;

for (int i = startRow + 1; i < (endRow + 1); i++) {
    HSSFRow row = sheet.getRow(i);
    String login = parseStringCell(row.getCell(0));
    if (login != null) {
	login = login.trim();
	if (login.length() > 0) {
	    String groupName = row.getLastCellNum() > 3 ? parseStringCell(row.getCell(3)) : null;
	    groupName = groupName != null ? groupName.trim() : null;
	    if (groupName == null || groupName.length() == 0) {
		skipped++;
		GroupingUploadAJAXAction.log.warn("Unable to add learner " + login
			+ " for group in related to grouping " + groupingID + " as group name is missing.");
	    } else {
		Set<String> users = groups.get(groupName);
		if (users == null) {
		    users = new HashSet<String>();
		    groups.put(groupName, users);
		}
		users.add(login);
	    }
	}
    }
}
return skipped;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:36,代碼來源:GroupingUploadAJAXAction.java

示例10: isUserSpreadsheet

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
@Override
   public boolean isUserSpreadsheet(FormFile fileItem) throws IOException {
HSSFSheet sheet = getSheet(fileItem);
HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
String string = parseStringCell(row.getCell(ImportService.PASSWORD));
return (StringUtils.equals(string, "* password")) ? true : false;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:ImportService.java

示例11: isRolesSpreadsheet

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
@Override
   public boolean isRolesSpreadsheet(FormFile fileItem) throws IOException {
HSSFSheet sheet = getSheet(fileItem);
HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
String string = parseStringCell(row.getCell(ImportService.ORGANISATION));
return (StringUtils.equals(string, "* organisation")) ? true : false;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:ImportService.java

示例12: createEmptyRow

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
/**
 * 創建空行
 *
 * @param sheet
 * @param rowIndex
 */
private static int createEmptyRow(HSSFSheet sheet, int rowIndex) {
    setRegionBorder(sheet, rowIndex, 2, 7);
    HSSFRow row = sheet.getRow(rowIndex);
    getCell(row, 0, -1, "");
    getCell(row, 1, -1, "");
    getCell(row, 8, -1, "");
    getCell(row, 9, -1, "");
    sheet.getRow(rowIndex++);
    return rowIndex;
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:17,代碼來源:FileUtil.java

示例13: setData

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
/**
 * 設置單元格數據
 *
 * @param sheet
 * @param rowIndex
 * @param data
 */
private static void setData(HSSFSheet sheet, int rowIndex, String... data) {
    setRegionBorder(sheet, rowIndex, 3, 8);
    HSSFRow row = sheet.getRow(rowIndex) == null ? sheet.createRow(rowIndex) : sheet.getRow(rowIndex);
    getCell(row, 0, -1, data.length > 0 ? data[0] : "");
    getCell(row, 1, -1, data.length > 1 ? data[1] : "");
    getCell(row, 2, -1, data.length > 2 ? data[2] : "");
    getCell(row, 3, -1, data.length > 3 ? data[3] : "");
    getCell(row, 9, -1, data.length > 4 ? data[4] : "");
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:17,代碼來源:FileUtil.java

示例14: buildMaxColumn

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
private int buildMaxColumn(HSSFSheet sheet){
	int rowCount=sheet.getPhysicalNumberOfRows();
	int maxColumnCount=0;
	for(int i=0;i<rowCount;i++){
		HSSFRow row=sheet.getRow(i);
		if(row==null){
			continue;
		}
		int columnCount=row.getPhysicalNumberOfCells();
		if(columnCount>maxColumnCount){
			maxColumnCount=columnCount;
		}
	}
	return maxColumnCount;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:16,代碼來源:HSSFExcelParser.java

示例15: getMsgListFromExcel

import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
@Override
public ArrayList<MsgEntity> getMsgListFromExcel(File targetFile) throws IOException {
	ArrayList<MsgEntity> list = new ArrayList<MsgEntity>();
	POIFSFileSystem fs = new POIFSFileSystem(targetFile);
	HSSFWorkbook workBook = new HSSFWorkbook(fs);
	try {
		System.out.println("開始解析");
		HSSFSheet sheet = workBook.getSheetAt(0);
		int rows = sheet.getLastRowNum() + 1;
		for (int r = 1; r < rows; r++) {
			HSSFRow row = sheet.getRow(r);
			if (row == null) {
				continue;
			}
			MsgEntity msg = new MsgEntity();
			String number = getStringVal(row.getCell(0));
			if(StringUtils.isEmpty(number)){
				continue;
			}
			msg.setTelNumber(number);
			
			String templateId = getStringVal(row.getCell(1));
			if (!StringUtils.isEmpty(templateId) && StringUtils.isNumeric(templateId)
					&& templateId.indexOf(".") == -1) {
				msg.setTemplateId(Long.parseLong(templateId));
			}
			msg.setContent(getStringVal(row.getCell(2)));
			if (HSSFDateUtil.isCellDateFormatted(row.getCell(3))) {
				msg.setSendTime(row.getCell(3).getDateCellValue());
			}
			list.add(msg);
		}
		
	} finally {
		workBook.close();
	}
	return list;

}
 
開發者ID:gyp220203,項目名稱:renren-msg,代碼行數:40,代碼來源:ParseExcelServiceImpl.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFSheet.getRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。