本文整理汇总了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) ;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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] : "");
}
示例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;
}
示例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;
}