当前位置: 首页>>代码示例>>Java>>正文


Java Row.getCell方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.Row.getCell方法的典型用法代码示例。如果您正苦于以下问题:Java Row.getCell方法的具体用法?Java Row.getCell怎么用?Java Row.getCell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.Row的用法示例。


在下文中一共展示了Row.getCell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readExcel

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
public static List<String[]> readExcel(InputStream is, int sheetIndex) throws Exception {
	Workbook workbook = WorkbookFactory.create(is);
	Sheet sheet = workbook.getSheetAt(sheetIndex);
	List<String[]> data = new ArrayList<>();
	for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
		Row row = sheet.getRow(i);
		if (row == null) continue;
		int last = row.getLastCellNum();
		String[] rowData = new String[last];
		for (int j = 0; j < last; j++) {
			Cell cell = row.getCell(j);
			rowData[j] = cell == null ? null : getCellString(cell);
		}
		data.add(rowData);
	}
	return data;
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:18,代码来源:FileUtils.java

示例2: getClasses

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private List<String> getClasses(Row classRow) {
	//声明一个list,用来存放所有的字段类型
	List<String> classList = new ArrayList<String>();
	//判断这一行是否为空
	if (classRow != null) {
		//遍历这一行的所有单元格
		for (int i = 0; i < classRow.getLastCellNum(); i++) {
			//获取单元格
			Cell cell = classRow.getCell(i);
			//判断单元格是否为空
			if (cell != null) {
				//将单元格的内容存放到list中
				classList.add(cell.getStringCellValue());
			}
		}
	}
	//返回所有的字段类型
	return classList;
}
 
开发者ID:yuchaozxc,项目名称:ExcelToXml,代码行数:20,代码来源:ExcelToXml.java

示例3: set

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
public void set(int sheetIndex, int x_index, int y_index, String value) {
    try {
        if (wb == null) throw new Exception("未打开文件");
        Sheet sheet = wb.getSheetAt(sheetIndex);
        Row row = null;
        Cell cell = null;
        row = sheet.getRow(x_index);
        if (row == null) {
            row = sheet.createRow(x_index);
        }
        cell = row.getCell(y_index);
        if (cell == null) {
            cell = row.createCell(y_index);
        }
        cell.setCellValue(value);
        save();
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
}
 
开发者ID:BetaSummer,项目名称:sztw,代码行数:21,代码来源:HSSF.java

示例4: readRow

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
@Override
public IRow readRow() {
	SheetData vData = getLocalData();
	int vRowIndex = vData.getCurrentIndex();
	if (vRowIndex < vData.getRowCount()) {
		Row vRow = vData.getSheet().getRow(vRowIndex);
		String[] vTitles = vData.getTitles();
		Cell[] vValues = new Cell[vTitles.length];
		for (int i = 0; i < vTitles.length; ++i) {
			Cell vCell = vRow.getCell(i, MissingCellPolicy.CREATE_NULL_AS_BLANK);
			vValues[i] = vCell;
		}
		vData.setCurrentIndex(vRowIndex + 1);
		return new RowExcelImpl(vRowIndex, vTitles, vValues);
	}
	// read over, remove the local data
	removeLocalData();
	return null;
}
 
开发者ID:xinufo,项目名称:teemo,代码行数:20,代码来源:ExcelReader.java

示例5: parseRow

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * 解析行
 * @param row
 * @return
 */
protected List<Object> parseRow(Row row) {
	List<Object> rowData = new ArrayList<Object>();

	for (int i = 0; i < row.getLastCellNum(); i++) {
		Cell cell = row.getCell(i);
		Object cellObj=null;
		if(cell!=null){
			cellObj = parseCell(cell);
		}
		rowData.add(cellObj);
	}
	/*// 迭代 一行的各个单元格
	Iterator<Cell> cellIterator = row.iterator();
	// 遍历一行多列
	while (cellIterator.hasNext()) {
		Cell cell = cellIterator.next();
		Object cellObj = parseCell(cell);
		rowData.add(cellObj);
	}*/
	return rowData;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:27,代码来源:ExcelParser.java

示例6: initColumns

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * @throws EmptyDataFileContentException
 *             if data is empty
 * @throws WrongDataFileFormatException
 *             if data is wrong
 */
protected void initColumns() throws EmptyDataFileContentException, WrongDataFileFormatException {
    columns = new ArrayList<>();
    final Sheet sheet = workbook.getSheetAt(0);
    final Row row = sheet.getRow(0);
    Cell cell;
    for (int i = 0; (cell = row.getCell(i)) != null; i++) {
        columns.add(cell.getStringCellValue());
    }
    if (columns.size() < 2) {
        throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
    }
    resultColumnName = columns.get(columns.size() - 1);
    if (!isResultColumnNameAuthorized(resultColumnName)) {
        throw new WrongDataFileFormatException(String.format(Messages.getMessage(WrongDataFileFormatException.WRONG_RESULT_COLUMN_NAME_ERROR_MESSAGE), ResultColumnNames.getAuthorizedNames()));
    }
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:23,代码来源:ExcelDataProvider.java

示例7: getLastRow

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private int getLastRow(Sheet sheet) throws SheetParsingException {
	int lastRowIndex = -1;
	if (sheet.getPhysicalNumberOfRows() > 0) { // getLastRowNum() actually returns an index, not a row number
		lastRowIndex = sheet.getLastRowNum();

		// now, start at end of spreadsheet and work our way backwards until we find a
		// row having data
		for (; lastRowIndex >= 0; lastRowIndex--) {
			Row row = sheet.getRow(lastRowIndex);
			if (row != null) {
				Cell cell = row.getCell(0);
				if (cell != null && cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
					break;
			}
		}
		return lastRowIndex;
	} else
		throw new SheetParsingException(sheet.getSheetName() + " is empty");
}
 
开发者ID:NeebalLearningPvtLtd,项目名称:Excel-to-POJO,代码行数:20,代码来源:SheetParser.java

示例8: generate

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
@Override
public List<String> generate(Sheet sheet) {
    List<String> lines = new ArrayList<>();
    for (Row row : sheet) {
        Cell firstCell = row.getCell(0);
        if (firstCell != null) {
            String userId = firstCell.getStringCellValue();
            if (".".equals(userId.substring(1, 2))) {
                for (Cell cell : row) {
                    if (cell.getColumnIndex() == 0) {
                        continue;
                    }

                    if ("X".equals(cell.getStringCellValue())) {
                        switch (cell.getColumnIndex()) {
                        case 1:
                            lines.add(getInsertStatement(userId, 2237));
                            break;
                        case 2:
                            lines.add(getInsertStatement(userId, 4352));
                            break;
                        case 3:
                            lines.add(getInsertStatement(userId, 3657));
                            break;
                        case 4:
                            lines.add(getInsertStatement(userId, 5565));
                            break;
                        }
                    }
                }
            }
        }
    }

    return lines;
}
 
开发者ID:jeffgbutler,项目名称:practical-functional-java,代码行数:37,代码来源:AwfulScriptGenerator.java

示例9: parseContentBodyRow

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * Method parses a row of the body content and puts the related entry into the result list (entries).
 * If the row is invalid in any kind, no modification happens. If any of the parameters provided is null or invalid,
 * no modification happens.
 * 
 * @param entries the list of entries, where the result of the row should be put in
 * @param langKeys the language information to parse the row correctly
 * @param row the row to be processed.
 */
private void parseContentBodyRow(	List<MessageResourceEntry> entries,
									Map<Integer, Locale> langKeys,
									Row row,
									String type)
{
	if (entries == null || row == null || langKeys == null || langKeys.isEmpty())
	{
		return;
	}
	MessageResourceEntry entry = new MessageResourceEntry();
	String code = getCellStringValue(row.getCell(this.keyColumn));
	if (!StringUtils.isBlank(code))
	{
		entry.setCodeId(StringUtils.trim(code));
		for (int nameIndex = this.firstLanguageColumn; nameIndex <= langKeys.size(); nameIndex++)
		{
			Cell cell = row.getCell(nameIndex);
			String name = getCellStringValue(cell);
			if (!StringUtils.isBlank(name))
			{
				Locale lang = langKeys.get(nameIndex);
				entry.addLang(lang, name);
			}
		}
		if (entry.size() > 0)
		{
			entry.setType(type);
			entries.add(entry);
		}
	}
	if (LOG.isDebugEnabled())
	{
		LOG.debug(ToStringBuilder.reflectionToString(entry, ToStringStyle.SHORT_PREFIX_STYLE));
	}
}
 
开发者ID:namics,项目名称:spring-i18n-support,代码行数:45,代码来源:ExcelReader.java

示例10: readInfoValue

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * 读取Excel里面客户的信息
 * @param wb
 * @return
 */
private Map<String, Object> readInfoValue(Workbook wb) {
    //得到第一个shell
    Sheet sheet = wb.getSheetAt(0);
    Map<String, Object> modelMap = new HashMap<>();
    //得到Excel的行数
    this.totalRows = sheet.getPhysicalNumberOfRows();
    //得到Excel的列数(前提是有行数)
    if (totalRows >= 1 && sheet.getRow(0) != null) {
        this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
    }
    List<InfoEntity> infoList = new ArrayList<InfoEntity>();
    InfoEntity info;
    List<ErrorJson> errorList = new ArrayList<ErrorJson>();
    ErrorJson error;
    //循环Excel行数,从第二行开始。标题不入库
    for (int r = 1; r < totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row == null) continue;
        info = new InfoEntity();
        //循环Excel的列
        for (int c = 0; c < this.totalCells; c++) {
            Cell cell = row.getCell(c);
            if (null != cell) {
                if (c == 0) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setTitle(cell.getStringCellValue());//title

                } else if (c == 1) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setContext(cell.getStringCellValue());//context
                } else if (c == 2) {
                    Date ti =new Date();
                    Timestamp time = new Timestamp(ti.getTime());
                    info.setTime(time);//time
                } else if (c == 3) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setSender(cell.getStringCellValue());//sender
                }
                else if (c == 4) {
                    info.setStudentId((int) cell.getNumericCellValue());//学号

                }

            }
        }
        //添加学生
        System.out.println(info);
        if (info.getStudentId()!=0&&info.getTitle()!=""&&info.getContext()!=""&&info.getTime()!=null&&info.getSender()!="") {
            infoList.add(info);
        } else if (info.getStudentId()==0) {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("学号不能为空");
            errorList.add(error);
        } else if ( info.getTitle()=="") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("title不能为空");
            errorList.add(error);
        } else if (info.getId() != 0 && info.getContext() == "") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("内容不能为空");
            errorList.add(error);
        } else if (info.getId() != 0 && info.getSender() == "") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("发送者不能为空");
            errorList.add(error);
        }
    }
    modelMap.put("result", infoList);
    modelMap.put("error", errorList);
    return modelMap;
}
 
开发者ID:junrui-zhao,项目名称:Educational-Management-System,代码行数:81,代码来源:ReadInfoExcel.java

示例11: rowParse

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * @param row
 * @param suiteAction
 */
private void rowParse(Row row, SuiteAction suiteAction)
{
    Cell nameCell = row.getCell(0);
    Cell actionCell = row.getCell(1);
    
    if(nameCell == null || actionCell == null)
    {
        return;
    }
    
    suiteAction.setField(nameCell.getStringCellValue());
    suiteAction.setName(actionCell.getStringCellValue());
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.suite.runner,代码行数:18,代码来源:ExcelSuiteParser.java

示例12: writeValue

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * @param column
 * @param line
 * @param value
 * @param style
 */
private void writeValue(String column, int line, String value, CellStyle style) {
    logger.debug("Writing: [{}] at line [{}] in column [{}]", value, line, column);
    final int colIndex = columns.indexOf(column);
    final Sheet sheet = workbook.getSheetAt(0);
    final Row row = sheet.getRow(line);
    Cell cell = row.getCell(colIndex);
    if (cell != null) {
        row.removeCell(cell);
    }
    cell = row.createCell(colIndex);
    cell.setCellStyle(style);
    cell.setCellValue(value);
    saveOpenExcelFile();
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:21,代码来源:ExcelDataProvider.java

示例13: getDate

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
public Date getDate (int index) {
	Sheet sheet =  getOrCreateSummary();
	Row row = sheet.getRow(index);
	Cell cell = row.getCell(DATE_FORMAT_COLUMN_INDEX);
	return cell.getDateCellValue();
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:7,代码来源:XLTestSummarySheet.java

示例14: determineTestDataFrame

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
 * Iterates through the sheet and determines the cells that are between START_TEST_CASE and END_TEST_CASE comments.
 * Also determines if the data table is to be returned as a Cartesian product of the rows.
 * @param sheet
 * @throws DataProviderException
 */
private void determineTestDataFrame(
                                     Sheet sheet ) throws DataProviderException {

    int rows = sheet.getLastRowNum() + 1;
    int columns = sheet.getRow(sheet.getLastRowNum()).getLastCellNum();
    // iterate throughout the spreadsheet's cells
    for (int x = 0; x < columns; x++) {
        for (int y = 0; y < rows; y++) {
            Row rowValue = sheet.getRow(y);
            if (rowValue != null) {

                if (rowValue.getLastCellNum() > columns) {
                    columns = rowValue.getLastCellNum();
                }

                Cell current = rowValue.getCell(x, Row.CREATE_NULL_AS_BLANK);
                if (hasComments(current)) {
                    if (isStartingCell(current)) {
                        this.startingCell = current;
                    }
                    if (isEndingCell(current)) {
                        this.endingCell = current;
                    }
                    if (isMultiplyCell(current)) {
                        this.isMultipliable = true;
                    }
                }
            }
        }
    }

    if (this.startingCell == null) {
        throw new DataProviderException(ERROR_LOCATING_STARTING_CELL);
    } else if (this.endingCell == null) {
        throw new DataProviderException(ERROR_LOCATING_ENDING_CELL);
    }

    if (this.startingCell.getRowIndex() <= this.endingCell.getRowIndex()) {
        if (this.startingCell.getColumnIndex() <= this.endingCell.getColumnIndex()) {
            return;
        }
    }

    throw new DataProviderException(WRONG_ORDER);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:52,代码来源:ExcelParser.java

示例15: getValue

import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private String getValue(int index, int column) {
	Sheet sheet =  getOrCreateSummary();
	Row row = sheet.getRow(index);
	Cell cell = row.getCell(column);
	return cell.getStringCellValue();
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:7,代码来源:XLTestSummarySheet.java


注:本文中的org.apache.poi.ss.usermodel.Row.getCell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。