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


Java HSSFRow.getFirstCellNum方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: loadColumnTemplate

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
protected ColumnTemplate loadColumnTemplate(final HSSFWorkbook workbook, final HSSFSheet templateSheet, final CellLocation location) {
    if (location == null) {
        return null;
    }

    final ColumnTemplate columnTemplate = new ColumnTemplate();

    final HSSFRow row = templateSheet.getRow(location.r);
    final HSSFRow bottomRow = templateSheet.getRow(location.r + 1);

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

        final HSSFCell cell = row.getCell(colNum);

        if (cell != null) {
            columnTemplate.columnTemplateMap.put(colNum, cell.getRichStringCellValue().getString());
        }
    }

    columnTemplate.topRowCellStyleList = POIUtils.copyCellStyle(workbook, row);
    columnTemplate.middleRowCellStyleList = POIUtils.copyCellStyle(workbook, row);
    columnTemplate.bottomRowCellStyleList = POIUtils.copyCellStyle(workbook, row);

    for (short i = 0; i < columnTemplate.middleRowCellStyleList.size(); i++) {
        final HSSFCellStyle middleRowCellStyle = columnTemplate.middleRowCellStyleList.get(i);
        if (middleRowCellStyle != null) {
            final HSSFCellStyle topRowCellStyle = columnTemplate.topRowCellStyleList.get(i);
            final HSSFCellStyle bottomRowCellStyle = columnTemplate.bottomRowCellStyleList.get(i);

            final HSSFCell bottomCell = bottomRow.getCell(row.getFirstCellNum() + i);

            topRowCellStyle.setBorderBottom(bottomCell.getCellStyle().getBorderTop());
            middleRowCellStyle.setBorderTop(bottomCell.getCellStyle().getBorderTop());
            middleRowCellStyle.setBorderBottom(bottomCell.getCellStyle().getBorderTop());
            bottomRowCellStyle.setBorderTop(bottomCell.getCellStyle().getBorderTop());
            bottomRowCellStyle.setBorderBottom(bottomCell.getCellStyle().getBorderBottom());
        }
    }

    return columnTemplate;
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:42,代碼來源:AbstractSheetGenerator.java

示例13: loadColumnTemplate

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
protected ColumnTemplate loadColumnTemplate(HSSFWorkbook workbook,
		HSSFSheet templateSheet, CellLocation location) {
	if (location == null) {
		return null;
	}

	ColumnTemplate columnTemplate = new ColumnTemplate();

	HSSFRow row = templateSheet.getRow(location.r);
	HSSFRow bottomRow = templateSheet.getRow(location.r + 1);

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

		HSSFCell cell = row.getCell(colNum);

		if (cell != null) {
			columnTemplate.columnTemplateMap.put(colNum, cell
					.getRichStringCellValue().getString());
		}
	}

	columnTemplate.topRowCellStyleList = POIUtils.copyCellStyle(workbook,
			row);
	columnTemplate.middleRowCellStyleList = POIUtils.copyCellStyle(
			workbook, row);
	columnTemplate.bottomRowCellStyleList = POIUtils.copyCellStyle(
			workbook, row);

	for (short i = 0; i < columnTemplate.middleRowCellStyleList.size(); i++) {
		HSSFCellStyle middleRowCellStyle = columnTemplate.middleRowCellStyleList
				.get(i);
		if (middleRowCellStyle != null) {
			HSSFCellStyle topRowCellStyle = columnTemplate.topRowCellStyleList
					.get(i);
			HSSFCellStyle bottomRowCellStyle = columnTemplate.bottomRowCellStyleList
					.get(i);

			HSSFCell bottomCell = bottomRow.getCell(row.getFirstCellNum()
					+ i);

			topRowCellStyle.setBorderBottom(bottomCell.getCellStyle()
					.getBorderTop());
			middleRowCellStyle.setBorderTop(bottomCell.getCellStyle()
					.getBorderTop());
			middleRowCellStyle.setBorderBottom(bottomCell.getCellStyle()
					.getBorderTop());
			bottomRowCellStyle.setBorderTop(bottomCell.getCellStyle()
					.getBorderTop());
			bottomRowCellStyle.setBorderBottom(bottomCell.getCellStyle()
					.getBorderBottom());
		}
	}

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


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