本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getLastRowNum方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFSheet.getLastRowNum方法的具體用法?Java HSSFSheet.getLastRowNum怎麽用?Java HSSFSheet.getLastRowNum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.getLastRowNum方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readXls
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的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: 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) ;
}
示例3: 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;
}
示例4: findMatchCell
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static CellLocation findMatchCell(final HSSFSheet sheet, final String regexp) {
for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum() + 1; rowNum++) {
final HSSFRow row = sheet.getRow(rowNum);
if (row == null) {
continue;
}
final Integer colNum = findMatchColumn(row, regexp);
if (colNum != null) {
return new CellLocation(rowNum, colNum.shortValue());
}
}
return null;
}
示例5: findCell
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static CellLocation findCell(HSSFSheet sheet, String[] strs) {
for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet
.getLastRowNum() + 1; rowNum++) {
HSSFRow row = sheet.getRow(rowNum);
if (row == null) {
continue;
}
for (int i = 0; i < strs.length; i++) {
Integer colNum = findColumn(row, strs[i]);
if (colNum != null) {
return new CellLocation(rowNum, colNum.shortValue());
}
}
}
return null;
}
示例6: 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;
}
示例7: 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;
}
示例8: getNumRows
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
@Override
public int getNumRows(FormFile fileItem) throws IOException {
HSSFSheet sheet = getSheet(fileItem);
int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
return endRow - startRow;
}
示例9: getRowSize
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static int getRowSize(HSSFSheet sheet){
return sheet.getLastRowNum();
}
示例10: 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;
}
示例11: copySheets2CSV
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static void copySheets2CSV(HSSFSheet sheet, String csvfile) {
int maxColumnNum = 0;
try {
FileWriter fw = new FileWriter(csvfile);
String str = "";
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
HSSFRow srcRow = sheet.getRow(i);
if (srcRow != null) {
for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
if (j != srcRow.getLastCellNum()) {
str = str +srcRow.getCell(j).getStringCellValue()+ ",";
} else {
str = str +srcRow.getCell(j).getStringCellValue()+ "\r\n";
}
}
fw.append(str);
}
str = "";
}
fw.flush();
fw.close();
} catch (IOException ex) {
}
//Util.copyPictures(newSheet,sheet) ;
}
示例12: readSheetBody
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
/**
* 讀取excel到JsonArray
* @param sheet
* @param map 列對應的column
* @param rowNumber
* @param array
* @return 當前的rowNumber
*/
private static int readSheetBody(HSSFSheet sheet, Map<Integer, String> map, int rowNumber, JSONArray array) {
if (logger.isDebugEnabled()) {
logger.debug("readSheetBody(HSSFSheet, Map<Integer,String>, int, JSONArray) - start"); //$NON-NLS-1$
}
if(sheet!=null){
int end = sheet.getLastRowNum();//獲取最後一行
for (; rowNumber<=end;rowNumber++) {
HSSFRow row = sheet.getRow(rowNumber);
if (row!=null) {
JSONObject jsonObject = new JSONObject();
Iterator<Cell> iterator = row.cellIterator();
while (iterator.hasNext()) {
Cell cell = iterator.next();
if (cell!=null) {
int cellIndex = cell.getColumnIndex();
String key = map.get(cellIndex);
String cellValue = getStringValue(cell);
if (key!=null&&cellValue!=null&&!cellValue.equals("null")) {
readSheetCell(jsonObject,key,cellValue);
}
}
}
array.add(jsonObject);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("readSheetBody(HSSFSheet, Map<Integer,String>, int, JSONArray) - end"); //$NON-NLS-1$
}
return rowNumber;
}
示例13: initLoopDefinitionMap
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
private void initLoopDefinitionMap(final HSSFSheet loopsSheet) {
for (int i = 2; i <= loopsSheet.getLastRowNum(); i++) {
final String templateSheetName = POIUtils.getCellValue(loopsSheet, i, 0);
if (templateSheetName == null) {
break;
}
final int firstLine = POIUtils.getIntCellValue(loopsSheet, i, 1);
final int spaceLine = POIUtils.getIntCellValue(loopsSheet, i, 2);
final String sheetName = POIUtils.getCellValue(loopsSheet, i, 3);
loopDefinitionMap.put(templateSheetName, new LoopDefinition(firstLine, spaceLine, sheetName));
}
}
示例14: initLoopDefinitionMap
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
private void initLoopDefinitionMap(HSSFSheet loopsSheet) {
for (int i = 2; i <= loopsSheet.getLastRowNum(); i++) {
String templateSheetName = POIUtils.getCellValue(loopsSheet, i, 0);
if (templateSheetName == null) {
break;
}
int firstLine = POIUtils.getIntCellValue(loopsSheet, i, 1);
int spaceLine = POIUtils.getIntCellValue(loopsSheet, i, 2);
String sheetName = POIUtils.getCellValue(loopsSheet, i, 3);
this.loopDefinitionMap.put(templateSheetName, new LoopDefinition(
firstLine, spaceLine, sheetName));
}
}
示例15: rowSpan
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
/**
* 合並單元格(行合並),合並規則:內容相同則合並
*
* @param sheet 合並的sheet
* @param colindex 合並列索引
* @return
*/
@SuppressWarnings("deprecation")
public static HSSFSheet rowSpan(HSSFSheet sheet, int colindex, int contentBeginIndex) {
// 總行數
int rowNum = sheet.getLastRowNum();
HSSFRow row = sheet.getRow(1);
// 正文內容應該從第二行開始,第一行為表頭的標題
int startRow = contentBeginIndex;
String startValue = "";
for (int i = contentBeginIndex; i <= rowNum; i++) {
row = sheet.getRow(i);
String value = row.getCell(colindex).getRichStringCellValue().getString();
if (i == contentBeginIndex) {
startValue = value;
continue;
}
if (StrUtil.isNotBlank(startValue) && StrUtil.isNotBlank(value) && startValue.equals(value)) {
if (i == rowNum)
sheet.addMergedRegion(new CellRangeAddress(startRow, i , colindex, colindex));
else
continue;
} else {
if((i-1)>startRow)
sheet.addMergedRegion(new CellRangeAddress(startRow, i - 1, colindex, colindex));
startRow = i;
}
startValue=value;
}
return sheet;
}