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


Java HSSFRow.getLastCellNum方法代碼示例

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


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

示例1: copySheets

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

示例3: findColumn

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static Integer findColumn(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) {
            final HSSFRichTextString cellValue = cell.getRichStringCellValue();

            if (str.equals(cellValue.getString())) {
                return Integer.valueOf(colNum);
            }
        }
    }

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

示例4: copyRow

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static void copyRow(final HSSFSheet oldSheet, final HSSFSheet newSheet, final int oldStartRowNum, final int oldEndRowNum, final int newStartRowNum) {
    final HSSFRow oldAboveRow = oldSheet.getRow(oldStartRowNum - 1);

    int newRowNum = newStartRowNum;

    for (int oldRowNum = oldStartRowNum; oldRowNum <= oldEndRowNum; oldRowNum++) {
        POIUtils.copyRow(oldSheet, newSheet, oldRowNum, newRowNum++);
    }

    final HSSFRow newTopRow = newSheet.getRow(newStartRowNum);

    if (oldAboveRow != null) {
        for (int colNum = newTopRow.getFirstCellNum(); colNum <= newTopRow.getLastCellNum(); colNum++) {
            final HSSFCell oldAboveCell = oldAboveRow.getCell(colNum);
            if (oldAboveCell != null) {
                final HSSFCell newTopCell = newTopRow.getCell(colNum);
                newTopCell.getCellStyle().setBorderTop(oldAboveCell.getCellStyle().getBorderBottom());
            }
        }
    }
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:22,代碼來源:POIUtils.java

示例5: copyCellStyle

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static List<HSSFCellStyle> copyCellStyle(final HSSFWorkbook workbook, final HSSFRow row) {
    final List<HSSFCellStyle> cellStyleList = new ArrayList<HSSFCellStyle>();

    for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {

        final HSSFCell cell = row.getCell(colNum);
        if (cell != null) {
            final HSSFCellStyle style = cell.getCellStyle();
            final HSSFCellStyle newCellStyle = copyCellStyle(workbook, style);
            cellStyleList.add(newCellStyle);
        } else {
            cellStyleList.add(null);
        }
    }

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

示例6: 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;
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:20,代碼來源:POIUtils.java

示例7: findMatchColumn

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static Integer findMatchColumn(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) {
			continue;
		}

		HSSFRichTextString cellValue = cell.getRichStringCellValue();

		if (cellValue.getString().matches(str)) {
			return Integer.valueOf(colNum);
		}
	}

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

示例8: copyRow

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static void copyRow(HSSFSheet oldSheet, HSSFSheet newSheet,
		int oldStartRowNum, int oldEndRowNum, int newStartRowNum) {
	HSSFRow oldAboveRow = oldSheet.getRow(oldStartRowNum - 1);

	int newRowNum = newStartRowNum;

	for (int oldRowNum = oldStartRowNum; oldRowNum <= oldEndRowNum; oldRowNum++) {
		POIUtils.copyRow(oldSheet, newSheet, oldRowNum, newRowNum++);
	}

	HSSFRow newTopRow = newSheet.getRow(newStartRowNum);

	if (oldAboveRow != null) {
		for (int colNum = newTopRow.getFirstCellNum(); colNum <= newTopRow
				.getLastCellNum(); colNum++) {
			HSSFCell oldAboveCell = oldAboveRow.getCell(colNum);
			if (oldAboveCell != null) {
				HSSFCell newTopCell = newTopRow.getCell(colNum);
				newTopCell.getCellStyle().setBorderTop(
						oldAboveCell.getCellStyle().getBorderBottom());
			}
		}
	}
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:25,代碼來源:POIUtils.java

示例9: copyCellStyle

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static List<HSSFCellStyle> copyCellStyle(HSSFWorkbook workbook,
		HSSFRow row) {
	List<HSSFCellStyle> cellStyleList = new ArrayList<HSSFCellStyle>();

	for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {

		HSSFCell cell = row.getCell(colNum);
		if (cell != null) {
			HSSFCellStyle style = cell.getCellStyle();
			HSSFCellStyle newCellStyle = copyCellStyle(workbook, style);
			cellStyleList.add(newCellStyle);
		} else {
			cellStyleList.add(null);
		}
	}

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

示例10: parseGroupSpreadsheet

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的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

示例11: copySheets2CSV

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的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) ;
}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:32,代碼來源:Excel2csv.java

示例12: 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);
                }
            }
        }
    }
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:43,代碼來源:Util.java

示例13: getExcelListMap

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
 * 獲取上傳文件(Excel)
 * 
 * @param inputStream
 *            輸入流,導入的excel數據流
 * @return 返回列表,key為標題列名,value為單元格值
 */
public static List<Map<String, String>> getExcelListMap(InputStream inputStream) {
	try {
		POIFSFileSystem poiFs = new POIFSFileSystem(inputStream);
		HSSFWorkbook wb = new HSSFWorkbook(poiFs);
		HSSFSheet sheet = wb.getSheetAt(0);
		int lastRowNumber = sheet.getLastRowNum();

		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		Map<String, String> map = new HashMap<String, String>();
		int firstColsNum = 0;
		for (int i = 0; i <= lastRowNumber; i++) {
			if (sheet != null) {
				HSSFRow row = sheet.getRow(i);
				Map<String, String> tempMap = new HashMap<String, String>();
				if (row != null) {
					if (firstColsNum == 0) {
						firstColsNum = row.getLastCellNum();
					}
					int nullCount = 0;
					for (int k = 0; k < firstColsNum; k++) {
						if (i == 0) {
							map.put(String.valueOf(k), checkNull(getCellValue(row, k)).toUpperCase());
						} else {
							String cellValue = getCellValue(row, k);
							if (cellValue == null || "".equals(cellValue) || "null".equals(cellValue)) {
								nullCount++;
							}
							tempMap.put(map.get(String.valueOf(k)), checkNull(getCellValue(row, k)));
						}
					}
					if (tempMap.size() > 0 && nullCount != firstColsNum) {
						list.add(tempMap);
					}
				}
			}
		}
		return list;
	} catch (Exception e) {
		e.printStackTrace();
	}

	return null;
}
 
開發者ID:fellyvon,項目名稱:wasexport,代碼行數:51,代碼來源:ExcelUtil.java

示例14: xlsToHtml

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的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();
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:82,代碼來源:OfficeConverter.java

示例15: getCellSize

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static int getCellSize(HSSFRow sfRow){
	return sfRow.getLastCellNum();
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:4,代碼來源:ReadExcelUtil.java


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