本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getFirstRowNum方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFSheet.getFirstRowNum方法的具体用法?Java HSSFSheet.getFirstRowNum怎么用?Java HSSFSheet.getFirstRowNum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.getFirstRowNum方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例4: 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;
}
示例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: 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;
}
示例7: 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;
}
示例8: 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) ;
}
示例9: xlsToHtml
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private void xlsToHtml() throws Throwable {
FileOutputStream output = new FileOutputStream(new File(htmlPath));
StringBuffer htmlHeaderSB = new StringBuffer();
htmlHeaderSB.append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' "
+ "xmlns='http://www.w3.org/TR/REC-html40'>");
htmlHeaderSB.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'><meta name=ProgId content=Excel.Sheet>"
+ "</head><body>");
output.write(htmlHeaderSB.toString().getBytes());
HSSFSheet sheet;
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); // 获整个Excel
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
if (workbook.getSheetAt(sheetIndex) != null) {
sheet = workbook.getSheetAt(sheetIndex);// 获得不为空的这个sheet
if (sheet != null) {
int firstRowNum = sheet.getFirstRowNum(); // 第一行
int lastRowNum = sheet.getLastRowNum(); // 最后一行
// 构造Table
output.write(("<table width=\"100%\" style=\"border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;"
+ "border-collapse:collapse;\">").getBytes());
for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
if (sheet.getRow(rowNum) != null) {// 如果行不为空,
HSSFRow row = sheet.getRow(rowNum);
short firstCellNum = row.getFirstCellNum(); // 该行的第一个单元格
short lastCellNum = row.getLastCellNum(); // 该行的最后一个单元格
int height = (int) (row.getHeight() / 15.625); // 行的高度
output.write(("<tr height=\"" + height + "\" style=\"border:1px solid #000;border-width:0 1px 1px 0;"
+ "margin:2px 0 2px 0;\">").getBytes());
for (short cellNum = firstCellNum; cellNum <= lastCellNum; cellNum++) { // 循环该行的每一个单元格
HSSFCell cell = row.getCell(cellNum);
if (cell != null) {
if (cell.getCellType() != HSSFCell.CELL_TYPE_BLANK) {
StringBuffer tdStyle = new StringBuffer("<td style=\"border:1px solid #000; border-width:0 1px 1px 0;"
+ "margin:2px 0 2px 0; ");
HSSFCellStyle cellStyle = cell.getCellStyle();
HSSFPalette palette = workbook.getCustomPalette(); // 类HSSFPalette用于求颜色的国际标准形式
HSSFColor hColor = palette.getColor(cellStyle.getFillForegroundColor());
HSSFColor hColor2 = palette.getColor(cellStyle.getFont(workbook).getColor());
String bgColor = convertToStardColor(hColor);// 背景颜色
short boldWeight = cellStyle.getFont(workbook).getBoldweight(); // 字体粗细
short fontHeight = (short) (cellStyle.getFont(workbook).getFontHeight() / 2); // 字体大小
String fontColor = convertToStardColor(hColor2); // 字体颜色
if (bgColor != null && !"".equals(bgColor.trim())) {
tdStyle.append(" background-color:");
tdStyle.append(bgColor);
tdStyle.append("; ");
}
if (fontColor != null && !"".equals(fontColor.trim())) {
tdStyle.append(" color:");
tdStyle.append(fontColor);
tdStyle.append("; ");
}
tdStyle.append(" font-weight:");
tdStyle.append(boldWeight);
tdStyle.append("; ");
tdStyle.append(" font-size: ");
tdStyle.append(fontHeight);
tdStyle.append("%;");
output.write((tdStyle + "\"").getBytes());
int width = (int) (sheet.getColumnWidth(cellNum) / 35.7); //
int cellRegionCol = getMergerCellRegionCol(sheet, rowNum, cellNum); // 合并的列(solspan)
int cellRegionRow = getMergerCellRegionRow(sheet, rowNum, cellNum);// 合并的行(rowspan)
String align = convertAlignToHtml(cellStyle.getAlignment()); //
String vAlign = convertVerticalAlignToHtml(cellStyle.getVerticalAlignment());
output.write((" align=\"" + align + "\" valign=\"" + vAlign + "\" width=\"" + width + "\" ").getBytes());
output.write((" colspan=\"" + cellRegionCol + "\" rowspan=\"" + cellRegionRow + "\"").getBytes());
output.write((">" + getCellValue(cell) + "</td>").getBytes());
}
}
}
output.write("</tr>".getBytes());
}
}
output.write(("</table>").getBytes());
}
}
}
output.write(("</body></html>").getBytes());
output.close();
}
示例10: parseGroupSpreadsheet
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Override
public List parseGroupSpreadsheet(FormFile fileItem) throws IOException {
results = new ArrayList<ArrayList>();
parentOrg = service.getRootOrganisation();
HSSFSheet sheet = getSheet(fileItem);
int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
ImportService.log.debug("Parsing spreadsheet rows " + startRow + " through " + endRow);
HSSFRow row;
Organisation org = null;
int successful = 0;
for (int i = startRow + 1; i < (endRow + 1); i++) {
emptyRow = true;
hasError = false;
rowResult = new ArrayList<String>();
row = sheet.getRow(i);
if (row != null) {
org = parseGroup(row, i);
}
// an empty row signifies a new group
if (emptyRow) {
ImportService.log.debug("Row " + i + " is empty.");
parentOrg = service.getRootOrganisation();
continue;
}
if (hasError) {
ImportService.log.debug("Row " + i + " has an error which has been sent to the browser.");
results.add(rowResult);
continue;
} else {
org = service.saveOrganisation(org, getCurrentUserId());
successful++;
rowResult.add(org.getOrganisationId().toString());
rowResult.add(org.getName());
rowResult.add(org.getParentOrganisation().getOrganisationId().toString());
rowResult.add(org.getOrganisationType().getOrganisationTypeId().toString());
writeOrgAuditLog(org);
// if we just added a group, then the rows under it become it's subgroups
if (parentOrg.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.ROOT_TYPE)) {
parentOrg = org;
}
results.add(rowResult);
}
}
ImportService.log.debug("Found " + results.size() + " orgs in spreadsheet.");
writeSuccessAuditLog(successful, null, "audit.successful.organisation.import");
return results;
}
示例11: parseUserSpreadsheet
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Override
public List parseUserSpreadsheet(FormFile fileItem, String sessionId) throws IOException {
results = new ArrayList<ArrayList>();
HSSFSheet sheet = getSheet(fileItem);
int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
setupImportStatus(sessionId, endRow - startRow);
UserDTO userDTO = (UserDTO) SessionManager.getSession(sessionId).getAttribute(AttributeNames.USER);
ImportService.log.debug("Parsing spreadsheet rows " + startRow + " through " + endRow);
HSSFRow row;
User user = null;
int successful = 0;
for (int i = startRow + 1; i < (endRow + 1); i++) {
emptyRow = true;
hasError = false;
rowResult = new ArrayList<String>();
row = sheet.getRow(i);
user = parseUser(row, i);
if (emptyRow) {
ImportService.log.debug("Row " + i + " is empty.");
break;
}
if (hasError) {
ImportService.log.debug("Row " + i + " has an error which has been sent to the browser.");
results.add(rowResult);
writeErrorsAuditLog(i + 1, rowResult, userDTO);
updateImportStatus(sessionId, results.size());
continue;
} else {
try {
service.saveUser(user);
successful++;
writeAuditLog(user, userDTO);
ImportService.log.debug("Row " + i + " saved user: " + user.getLogin());
} catch (Exception e) {
ImportService.log.debug(e);
rowResult.add(messageService.getMessage("error.fail.add"));
}
if (rowResult.size() > 0) {
if (ImportService.log.isDebugEnabled()) {
ImportService.log.debug("Row " + i + " has " + rowResult.size() + " messages.");
}
writeErrorsAuditLog(i + 1, rowResult, userDTO);
}
results.add(rowResult);
updateImportStatus(sessionId, results.size());
}
}
ImportService.log.debug("Found " + results.size() + " users in spreadsheet.");
writeSuccessAuditLog(successful, userDTO, "audit.successful.user.import");
return results;
}
示例12: parseRolesSpreadsheet
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Override
public List parseRolesSpreadsheet(FormFile fileItem, String sessionId) throws IOException {
results = new ArrayList<ArrayList>();
HSSFSheet sheet = getSheet(fileItem);
int startRow = sheet.getFirstRowNum();
int endRow = sheet.getLastRowNum();
ImportService.log.debug("Parsing spreadsheet rows " + startRow + " through " + endRow);
setupImportStatus(sessionId, endRow - startRow);
UserDTO userDTO = (UserDTO) SessionManager.getSession(sessionId).getAttribute(AttributeNames.USER);
HSSFRow row;
List<String> roles;
int successful = 0;
for (int i = startRow + 1; i < (endRow + 1); i++) {
emptyRow = true;
hasError = false;
rowResult = new ArrayList<String>();
row = sheet.getRow(i);
String login = parseStringCell(row.getCell(ImportService.LOGIN));
String orgId = parseStringCell(row.getCell(ImportService.ORGANISATION));
roles = parseRolesCell(row.getCell(ImportService.ROLES));
if (emptyRow) {
ImportService.log.debug("Row " + i + " is empty.");
break;
}
if (hasError) {
ImportService.log.debug("Row " + i + " has an error which has been sent to the browser.");
results.add(rowResult);
writeErrorsAuditLog(i + 1, rowResult, userDTO);
updateImportStatus(sessionId, results.size());
continue;
} else {
try {
saveUserRoles(isSysadmin(sessionId), login, orgId, roles, row);
successful++;
} catch (Exception e) {
ImportService.log.error("Unable to assign roles to user: " + login, e);
rowResult.add(messageService.getMessage("error.fail.add"));
}
if (rowResult.size() > 0) {
if (ImportService.log.isDebugEnabled()) {
ImportService.log.debug("Row " + i + " has " + rowResult.size() + " messages.");
}
writeErrorsAuditLog(i + 1, rowResult, userDTO);
}
results.add(rowResult);
updateImportStatus(sessionId, results.size());
}
}
ImportService.log.debug("Found " + results.size() + " users in spreadsheet.");
writeSuccessAuditLog(successful, userDTO, "audit.successful.role.import");
return results;
}