本文整理匯總了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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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()));
}
}
示例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");
}
示例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;
}
示例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));
}
}
示例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;
}
示例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());
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}