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


Java XSSFRow.getFirstCellNum方法代碼示例

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


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

示例1: readXlsx

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
public static ArrayList readXlsx(String path) throws IOException {
    XSSFWorkbook xwb = new XSSFWorkbook(path);
    XSSFSheet sheet = xwb.getSheetAt(0);
    XSSFRow row;
    String[] cell = new String[sheet.getPhysicalNumberOfRows() + 1];
    ArrayList<String> arrayList = new ArrayList<>();
    for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        cell[i] = "";
        row = sheet.getRow(i);
        for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
            cell[i] += row.getCell(j).toString();
            cell[i] += " | ";
        }
        arrayList.add(cell[i]);
    }
    return arrayList;
}
 
開發者ID:inkss,項目名稱:hotelbook-JavaWeb,代碼行數:18,代碼來源:ExportExcel.java

示例2: XSLXSource

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
public XSLXSource(Resource resource, XSSFWorkbook workbook) {
    this.resource = resource;
    this.workbook = workbook;
    String fragment = resource.getFragment();
    XSSFSheet sheet;
    if (fragment == null) {
        sheet = workbook.getSheetAt(0);
    } else {
        sheet = workbook.getSheet(fragment);
        if (sheet == null) {
            throw new IllegalArgumentException("Unable to find Sheet named '" + fragment + "'");
        }
    }
    this.sheet = sheet;
    this.rows = this.sheet.iterator();
    if (!rows.hasNext()) {
        throw new IllegalArgumentException(sheet.getSheetName() + " is empty");
    }
    XSSFRow row = nextRow();
    this.firstColumn = row.getFirstCellNum();
    this.headers = readHeaders(row, this.firstColumn);

}
 
開發者ID:theysay,項目名稱:preceive-batch,代碼行數:24,代碼來源:XLSXSourceProvider.java

示例3: copyRow

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的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(XSSFSheet srcSheet, XSSFSheet destSheet, XSSFRow srcRow, XSSFRow destRow, Map<Integer, XSSFCellStyle> 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{
            XSSFCell oldCell = srcRow.getCell(j);   // ancienne cell  
        XSSFCell 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,代碼行數:44,代碼來源:Util.java

示例4: readRow

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
private Row readRow(XSSFRow poiRow, int rowNo) {
	row = new Row();

	row.setHeight((int) poiRow.getHeightInPoints());
	int firstCellNum = poiRow.getFirstCellNum();
	if (firstCellNum >= 0) {
		for (int i = 0; i < firstCellNum; i++) {
			Cell defaultCell = createDefaultCell(rowNo, i);
			row.addCell(defaultCell);
		}

		int lastCellNum = poiRow.getLastCellNum();
		for (int i = firstCellNum; i < lastCellNum; i++) {
			poiCell = poiRow.getCell(i);
			if (poiCell == null) {
				cell = createDefaultCell(rowNo, i);
			} else {
				cell = readCell(poiCell);
			}
			row.addCell(cell);
		}
	}

	return row;
}
 
開發者ID:legend0702,項目名稱:excelUtils,代碼行數:26,代碼來源:XSSFExcelReader.java

示例5: compareTwoRows

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
public static boolean compareTwoRows(XSSFRow row1, XSSFRow row2) {
    if ((row1 == null) && (row2 == null)) {
        return true;
    } else if ((row1 == null) || (row2 == null)) {
        return false;
    }

    int firstCell1 = row1.getFirstCellNum();
    int lastCell1 = row1.getLastCellNum();
    boolean equalRows = true;

    // Compare all cells in a row
    for (int i = firstCell1; i <= lastCell1; i++) {
        XSSFCell cell1 = row1.getCell(i);
        XSSFCell cell2 = row2.getCell(i);
        if (!compareTwoCells(cell1, cell2)) {
            equalRows = false;
            break;
        }
    }
    return equalRows;
}
 
開發者ID:Talend,項目名稱:data-prep,代碼行數:23,代碼來源:ExcelComparator.java

示例6: copySheets2CSV

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
public static void copySheets2CSV(XSSFSheet sheet, String csvfile) {
        int maxColumnNum = 0;
        Map<Integer, XSSFCellStyle> styleMap = null;

        try {
            FileWriter fw = new FileWriter(csvfile);

            String str = "";
            for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
                XSSFRow srcRow = sheet.getRow(i);
                if (srcRow != null) {
                    System.out.println(srcRow.getLastCellNum());
                    System.out.println(srcRow.getFirstCellNum());
//                    System.out.println(srcRow.getCell(srcRow.getLastCellNum()).toString());
                    for (int j = srcRow.getFirstCellNum(); j < srcRow.getLastCellNum(); j++) {
                        
                        if (srcRow.getCell(j)!=null&&j != srcRow.getLastCellNum()-1) {
                            srcRow.getCell(j).setCellType(1);
                            
                            str = str +srcRow.getCell(j).getReference()+ ",";
                        } else if(srcRow.getCell(j)!=null){
                            srcRow.getCell(j).setCellType(1);
                            
                            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,代碼行數:39,代碼來源:Excel2csv.java

示例7: parse

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
 * 解析導出的視頻excel文件
 */
public static void parse(File file) {
	try {
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
		XSSFSheet sheet = xwb.getSheetAt(0);

		System.out.println(String.format("準備解析:%s, 表格:%s", file.getAbsolutePath(), sheet.getSheetName()));

		XSSFRow row = null;
		String cell = null;

		// 遍曆行(從0開始)
		for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
			row = sheet.getRow(i);

			// 忽略空行:真實
			if (row.getFirstCellNum() < 0) {
				continue;
			}

			// 遍曆行-列
			for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
				if (row.getCell(j) == null) {
					continue;
				}
				cell = row.getCell(j).toString();
				if (StringUtil.isEmpty(cell)) {
					continue;
				}
				System.out.println(String.format("解析 行 %d 列 %d\t>>\t%s", i + 1, j, cell));
				appendSql(new Vi(cell));
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:bdceo,項目名稱:bd-codes,代碼行數:40,代碼來源:VidParser.java

示例8: validateSheet

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
public List<ValidationResult> validateSheet(XSSFSheet sheet) {
	List<ValidationResult> results = new LinkedList<ValidationResult>();

	List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
	for (XSSFDataValidation xssfDataValidation : dataValidations) {
		DataValidationConstraint validationConstraint = xssfDataValidation.getValidationConstraint();
		CellRangeAddressList regions = xssfDataValidation.getRegions();
		CellRangeAddress[] cellRangeAddresses = regions.getCellRangeAddresses();
		Validator validator = buildValidator(sheet, validationConstraint);
		for (CellRangeAddress cellRangeAddress : cellRangeAddresses) {
			int firstRow = Math.max(cellRangeAddress.getFirstRow(), sheet.getFirstRowNum());
			int lastRow = Math.min(cellRangeAddress.getLastRow(), sheet.getLastRowNum());

			for (int i = firstRow; i <= lastRow; i++) {
				XSSFRow row = sheet.getRow(i);
				if (row == null || row.getFirstCellNum() < 0) {
					continue;
				}

				int firstColumn = Math.max(cellRangeAddress.getFirstColumn(), row.getFirstCellNum());
				int lastColumn = Math.min(cellRangeAddress.getLastColumn(), row.getLastCellNum());

				for (int j = firstColumn; j <= lastColumn; j++) {
					XSSFCell cell = row.getCell(j);
					if (cell == null) {
						continue;
					}
					boolean inRange = cellRangeAddress.isInRange(cell.getRowIndex(), cell.getColumnIndex());
					if (inRange) {
						ValidationResult result = validator.validate(cell);
						if (result != null) {
							results.add(result);
						}
					}
				}
			}
		}
	}
	return results;
	/*
	 * TODO think about splitting this function into 2 parts: 1.
	 * getAllValidators 2. validate with all validators
	 */
}
 
開發者ID:ykaragol,項目名稱:poi-data-validation,代碼行數:45,代碼來源:DataValidator.java

示例9: readExcelDocument

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
private void readExcelDocument() {
	try {
		FileInputStream fs = new FileInputStream(f);
		XSSFWorkbook wb = new XSSFWorkbook(fs);
		XSSFSheet sh;
		String text = "";
		for (int i = 0; i < wb.getNumberOfSheets(); i++) {
			sh = wb.getSheetAt(i);
			for (int j = sh.getFirstRowNum(); j <= sh.getLastRowNum(); j++) {
				XSSFRow currRow = sh.getRow(j);
				if (currRow == null || currRow.getFirstCellNum() == -1) {
					continue;
				} else {
					for (int k = currRow.getFirstCellNum(); k < currRow
							.getLastCellNum(); k++) {
						if (currRow.getCell(k, Row.RETURN_BLANK_AS_NULL) == null) {
							continue;
						} else {
							text += currRow.getCell(k) + "; ";
						}
					}
					text += System.lineSeparator();
				}
			}
		}
		fs.close();
		wb.close();
		String[] xlsxLines = text.split(System.lineSeparator());
		for (String line : xlsxLines) {
			lines.add(line);
		}
	} catch (IOException e) {
		JOptionPane.showMessageDialog(null, "Fehler in readExcelDocument",
				"Fehler", JOptionPane.ERROR_MESSAGE);
		e.printStackTrace();
	}
}
 
開發者ID:Steffen93,項目名稱:filterit,代碼行數:38,代碼來源:FileObject.java

示例10: copyRow

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
 * Copy a row from a sheet to another sheet
 * 
 * 
 * @param srcSheet the sheet to copy
 * @param destSheet the sheet to copy into
 * @param parentSheetRow the row inside destSheet where we start to copy
 * @param parentSheetColumn the column inside destSheet where we start to copy
 * @param srcRow the row to copy
 * @param destRow the row to create
 * @param styleMap style map
 *       
 */
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, int parentSheetRow, int parentSheetColumn, XSSFRow srcRow, XSSFRow destRow,
		Map<Integer, CellStyle> 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++) {
		XSSFCell oldCell = srcRow.getCell(j); // ancienne cell			
		if (oldCell != null) {				
			XSSFCell newCell = destRow.createCell(parentSheetColumn + j);				
			copyCell(oldCell, newCell, styleMap);
			
			CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());

			if (mergedRegion != null) {
				
				CellRangeAddress newMergedRegion = new CellRangeAddress(parentSheetRow + mergedRegion.getFirstRow(),
						parentSheetRow + mergedRegion.getLastRow(), 
						parentSheetColumn + mergedRegion.getFirstColumn(), 
						parentSheetColumn + mergedRegion.getLastColumn());
				
				CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
				if (isNewMergedRegion(wrapper, mergedRegions)) {
					mergedRegions.add(wrapper);
					destSheet.addMergedRegion(wrapper.range);
				}
			}
		}
	}

}
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:46,代碼來源:XlsxUtil.java

示例11: main

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
 * 解析Excel-2007 參考:http://kxjhlele.iteye.com/blog/321392
 * 
 */
public static void main(String[] args) {
    String excelPath = "D:/Download/全國匯編(物化).xlsx";

    try {
        XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(excelPath));
        XSSFSheet sheet = xwb.getSheetAt(0);

        XSSFRow row = null;
        String cell = null;

        Map<String, String> peOrderMap = new TreeMap<String, String>();
        int porder = 0, eorder = 0;
        // 遍曆所有行
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            row = sheet.getRow(i);
            // 遍曆每一行的所有列
            for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
                cell = row.getCell(j).toString();
                if (j == 0 && !cell.isEmpty()) { // 試卷序號
                    porder = new Double(Double.parseDouble(cell)).intValue();
                }
                if (j == 2) { // 試卷下試題序號
                    eorder = new Double(Double.parseDouble(cell)).intValue();
                }
                if (j == 3) {// 錄製老師姓名
                    peOrderMap.put(porder + "#" + eorder, cell);
                }
                System.out.print(cell + "\t");
            }
            System.out.println("");
        }

        for (Entry<String, String> en : peOrderMap.entrySet()) {
            System.out.println(en.getKey() + " - " + en.getValue());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
開發者ID:bdceo,項目名稱:bd-codes,代碼行數:46,代碼來源:TestPOI.java

示例12: parseKaoQinExcel

import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
 * 解析考勤Excel表
 * 
 * @param file
 *            考勤文件
 */
public static void parseKaoQinExcel(File file) {
	try {
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
		XSSFSheet sheet = xwb.getSheetAt(0);

		System.out.println(String.format("準備解析:%s, 表格:%s",
				file.getAbsolutePath(), sheet.getSheetName()));

		XSSFRow dayRow = null; // 日期-周幾
		XSSFRow timeRow = null;// 打卡時間

		String dayCell = null;
		String timeCell = null;

		// 遍曆行(從0開始),從第3行開始
		for (int i = 9; i < sheet.getPhysicalNumberOfRows(); i = i + 2) {
			dayRow = sheet.getRow(i);
			timeRow = sheet.getRow(i + 1);

			// 忽略空行:真實
			if (dayRow.getFirstCellNum() < 0) {
				continue;
			}

			// 遍曆行-列
			for (int j = dayRow.getFirstCellNum(); j < dayRow
					.getPhysicalNumberOfCells(); j++) {
				if (dayRow.getCell(j) == null) {
					continue;
				}
				dayCell = dayRow.getCell(j).toString();
				timeCell = timeRow.getCell(j).toString();
				if (StringUtil.isEmpty(dayCell)) {
					continue;
				}
				System.out.println(String.format(
						"解析 行=%d 列=%d\t>>\t日期=%s\t打卡=%s", i + 1, j,
						dayCell, timeCell));
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
開發者ID:bdceo,項目名稱:bd-codes,代碼行數:52,代碼來源:KQParseer.java


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