org.apache.poi.ss.usermodel.Cell.getStringCellValue()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(419)

本文整理了Java中org.apache.poi.ss.usermodel.Cell.getStringCellValue()方法的一些代码示例,展示了Cell.getStringCellValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.getStringCellValue()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:getStringCellValue

Cell.getStringCellValue介绍

[英]Get the value of the cell as a string

For numeric cells we throw an exception. For blank cells we return an empty string. For formulaCells that are not string Formulas, we throw an exception.
[中]以字符串形式获取单元格的值
对于数值单元格,我们抛出一个异常。对于空白单元格,我们返回一个空字符串。对于不是字符串公式的FormulaCell,我们抛出一个异常。

代码示例

代码示例来源:origin: kiegroup/optaplanner

protected String readStringCell(Cell cell) {
  return cell.getStringCellValue();
}

代码示例来源:origin: stackoverflow.com

import com.monitorjbl.xlsx.StreamingReader;

InputStream is = new FileInputStream(new File("/path/to/workbook.xlsx"));
StreamingReader reader = StreamingReader.builder()
    .rowCacheSize(100)    // number of rows to keep in memory (defaults to 10)
    .bufferSize(4096)     // buffer size to use when reading InputStream to file (defaults to 1024)
    .sheetIndex(0)        // index of sheet to use (defaults to 0)
    .read(is);            // InputStream or File for XLSX file (required)

for (Row r : reader) {
 for (Cell c : r) {
  System.out.println(c.getStringCellValue());
 }
}

代码示例来源:origin: kiegroup/optaplanner

protected String readStringParameter(Row row, String key) {
  Cell keyCell = row.getCell(0);
  if (!key.equals(keyCell.getStringCellValue())) {
    throw new IllegalArgumentException("The keyCell (" + keyCell.getRow().getRowNum() + ","
        + keyCell.getColumnIndex() + ") with value (" + keyCell.getStringCellValue()
        + ") is expected to have the key (" + key + ")");
  }
  Cell valueCell = row.getCell(1);
  return valueCell.getStringCellValue();
}

代码示例来源:origin: stackoverflow.com

Cell cell = sheet.getRow(i).getCell(0);
 cell.setCellType ( Cell.CELL_TYPE_STRING );
 String j_username = cell.getStringCellValue();

代码示例来源:origin: stackoverflow.com

InputStream inp = new FileInputStream("wb.xls");
 Workbook wb = WorkbookFactory.create(inp);
 Sheet sheet = wb.getSheetAt([sheet index]);
 Row row = sheet.getRow([row index]);
 Cell cell = row.getCell([cell index]);
 String cellContents = cell.getStringCellValue(); 
 //Modify the cellContents here
 // Write the output to a file
 cell.setCellValue(cellContents); 
 FileOutputStream fileOut = new FileOutputStream("wb.xls");
 wb.write(fileOut);
 fileOut.close();

代码示例来源:origin: kiegroup/optaplanner

protected void assertCellConstant(Cell cell, String constant) {
  if (!constant.equals(cell.getStringCellValue())) {
    throw new IllegalArgumentException("The cell (" + cell.getRow().getRowNum() + ","
        + cell.getColumnIndex() + ") with value (" + cell.getStringCellValue()
        + ") is expected to have the constant (" + constant + ")");
  }
}

代码示例来源:origin: kiegroup/optaplanner

protected double readDoubleParameter(Row row, String key) {
    Cell keyCell = row.getCell(0);
    if (!key.equals(keyCell.getStringCellValue())) {
      throw new IllegalArgumentException("The keyCell (" + keyCell.getRow().getRowNum() + ","
          + keyCell.getColumnIndex() + ") with value (" + keyCell.getStringCellValue()
          + ") is expected to have the key (" + key + ")");
    }
    Cell valueCell = row.getCell(1);
    return valueCell.getNumericCellValue();
  }
}

代码示例来源:origin: org.apache.poi/poi

public boolean isValidValue(Cell cell, DataValidationContext context) {
    if (! isType(cell, CellType.STRING)) return false;
    String v = cell.getStringCellValue();
    return isValidNumericValue(Double.valueOf(v.length()), context);
  }
},

代码示例来源:origin: kiegroup/optaplanner

protected boolean currentRowIsEmpty() {
  if (currentRow.getPhysicalNumberOfCells() == 0) {
    return true;
  }
  for (Cell cell : currentRow) {
    if (cell.getCellTypeEnum() == CellType.STRING) {
      if (!cell.getStringCellValue().isEmpty()) {
        return false;
      }
    } else if (cell.getCellTypeEnum() != CellType.BLANK) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: pentaho/pentaho-kettle

public Object getValue() {
 try {
  switch ( getType() ) {
   case BOOLEAN_FORMULA:
   case BOOLEAN:
    return Boolean.valueOf( cell.getBooleanCellValue() );
   case DATE_FORMULA:
   case DATE:
    // Timezone conversion needed since POI doesn't support this apparently
    //
    long time = cell.getDateCellValue().getTime();
    long tzOffset = TimeZone.getDefault().getOffset( time );
    return new Date( time + tzOffset );
   case NUMBER_FORMULA:
   case NUMBER:
    return Double.valueOf( cell.getNumericCellValue() );
   case STRING_FORMULA:
   case LABEL:
    return cell.getStringCellValue();
   case EMPTY:
   default:
    return null;
  }
 } catch ( Exception e ) {
  throw new RuntimeException( "Unable to get value of cell ("
   + cell.getColumnIndex() + ", " + cell.getRowIndex() + ")", e );
 }
}

代码示例来源:origin: stackoverflow.com

break;
case Cell.CELL_TYPE_STRING:
  System.out.println(cell.getStringCellValue());
  break;
case Cell.CELL_TYPE_BLANK:

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings("resource")
public void testXls() throws Exception {
  View excelView = new AbstractXlsView() {
    @Override
    protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
      Sheet sheet = workbook.createSheet("Test Sheet");
      Row row = sheet.createRow(0);
      Cell cell = row.createCell(0);
      cell.setCellValue("Test Value");
    }
  };
  excelView.render(new HashMap<>(), request, response);
  Workbook wb = new HSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
  assertEquals("Test Sheet", wb.getSheetName(0));
  Sheet sheet = wb.getSheet("Test Sheet");
  Row row = sheet.getRow(0);
  Cell cell = row.getCell(0);
  assertEquals("Test Value", cell.getStringCellValue());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings("resource")
public void testXlsxView() throws Exception {
  View excelView = new AbstractXlsxView() {
    @Override
    protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
      Sheet sheet = workbook.createSheet("Test Sheet");
      Row row = sheet.createRow(0);
      Cell cell = row.createCell(0);
      cell.setCellValue("Test Value");
    }
  };
  excelView.render(new HashMap<>(), request, response);
  Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
  assertEquals("Test Sheet", wb.getSheetName(0));
  Sheet sheet = wb.getSheet("Test Sheet");
  Row row = sheet.getRow(0);
  Cell cell = row.getCell(0);
  assertEquals("Test Value", cell.getStringCellValue());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings("resource")
public void testXlsxStreamingView() throws Exception {
  View excelView = new AbstractXlsxStreamingView() {
    @Override
    protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
      Sheet sheet = workbook.createSheet("Test Sheet");
      Row row = sheet.createRow(0);
      Cell cell = row.createCell(0);
      cell.setCellValue("Test Value");
    }
  };
  excelView.render(new HashMap<>(), request, response);
  Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
  assertEquals("Test Sheet", wb.getSheetName(0));
  Sheet sheet = wb.getSheet("Test Sheet");
  Row row = sheet.getRow(0);
  Cell cell = row.getCell(0);
  assertEquals("Test Value", cell.getStringCellValue());
}

代码示例来源:origin: kiegroup/optaplanner

private void readTimeslotHours() {
    columnIndexToStartTimeMap.clear();
    columnIndexToEndTimeMap.clear();
    StreamSupport.stream(currentRow.spliterator(), false)
        .forEach(cell -> {
          if (!cell.getStringCellValue().isEmpty() && !cell.getStringCellValue().equals("Room")) {
            String[] startAndEndTimeStringArray = cell.getStringCellValue().split("-");
            try {
              columnIndexToStartTimeMap.put(cell.getColumnIndex(),
                  LocalTime.parse(startAndEndTimeStringArray[0], TIME_FORMATTER));
              columnIndexToEndTimeMap.put(cell.getColumnIndex(), LocalTime.parse(startAndEndTimeStringArray[1],
                  TIME_FORMATTER));
            } catch (DateTimeParseException e) {
              throw new IllegalStateException(currentPosition() + ": The startTime (" + startAndEndTimeStringArray[0]
                  + ") or endTime (" + startAndEndTimeStringArray[1]
                  + ") doesn't parse as a time.", e);
            }
          }
        });
  }
}

代码示例来源:origin: org.apache.poi/poi

|| isType(cell, CellType.BLANK)  
|| (isType(cell,CellType.STRING) 
  && (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty())

代码示例来源:origin: org.apache.poi/poi

private ValueAndFormat getCellValue(Cell cell) {
  if (cell != null) {
    final String format = cell.getCellStyle().getDataFormatString();
    CellType type = cell.getCellType();
    if (type == CellType.FORMULA) {
      type = cell.getCachedFormulaResultType();
    }
    switch (type) {
      case NUMERIC:
        return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), format, decimalTextFormat);
      case STRING:
      case BOOLEAN:
        return new ValueAndFormat(cell.getStringCellValue(), format);
      default:
        break;
    }
  }
  return new ValueAndFormat("", "");
}
/**

代码示例来源:origin: looly/hutool

break;
default:
  value = cell.getStringCellValue();

代码示例来源:origin: looly/hutool

break;
default:
  value = cell.getStringCellValue();

代码示例来源:origin: org.apache.poi/poi

return apply(label, c.getStringCellValue());
default:
  return apply(label, "?");

相关文章