本文整理汇总了Java中org.apache.poi.ss.usermodel.CellType.STRING属性的典型用法代码示例。如果您正苦于以下问题:Java CellType.STRING属性的具体用法?Java CellType.STRING怎么用?Java CellType.STRING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.poi.ss.usermodel.CellType
的用法示例。
在下文中一共展示了CellType.STRING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellValue
/**
* 获取单元格的值
*
* @param cell
* @return
*/
public static Object getCellValue(Cell cell) {
Object cellValue = null;
CellType cellType = cell.getCellTypeEnum();// CellType.forInt(cell.getCellType());
if (cellType == CellType.STRING) {
cellValue = cell.getStringCellValue();
} else if (cellType == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
cellValue = cell.getDateCellValue();
} else {
cellValue = cell.getNumericCellValue();
}
} else if (cellType == CellType.BOOLEAN) {
cellValue = cell.getBooleanCellValue();
} else if (cellType == CellType.FORMULA) {
cellValue = cell.getCellFormula();
} else if (cellType == CellType.BLANK) {
cellValue = "";
}
return cellValue;
}
示例2: getCellTypeEnum
/**
* Return the cell type.
*
* @return the cell type
* Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Override
public CellType getCellTypeEnum() {
if(contentsSupplier.getContent() == null || type == null) {
return CellType.BLANK;
} else if("n".equals(type)) {
return CellType.NUMERIC;
} else if("s".equals(type) || "inlineStr".equals(type)) {
return CellType.STRING;
} else if("str".equals(type)) {
return CellType.FORMULA;
} else if("b".equals(type)) {
return CellType.BOOLEAN;
} else if("e".equals(type)) {
return CellType.ERROR;
} else {
throw new UnsupportedOperationException("Unsupported cell type '" + type + "'");
}
}
示例3: testGetCellTypeAsStr
@Test
public void testGetCellTypeAsStr() throws Exception {
//
ExpowCellLib cell = new ExpowCellLib(0, 0, CellType.STRING, "StringValue");
assertEquals("CELL_TYPE_STRING", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.BLANK, "");
assertEquals("CELL_TYPE_BLANK", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.BOOLEAN, "true");
assertEquals("CELL_TYPE_BOOLEAN", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.ERROR, "");
assertEquals("CELL_TYPE_ERROR", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.FORMULA, "");
assertEquals("CELL_TYPE_FORMULA", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.NUMERIC, "");
assertEquals("CELL_TYPE_NUMERIC", cell.getCellTypeAsStr());
}
示例4: parseRow
/**
* 行単位で解析し、必要なら改ページを挿入する
*/
protected void parseRow( Sheet sheet, SheetParser sheetParser, SheetData sheetData, Row row, int rowIndex) {
int firstColNum = row.getFirstCellNum();
int lastColNum = row.getLastCellNum() - 1;
for ( int colIndex = firstColNum; colIndex <= lastColNum; colIndex++) {
Cell cell = row.getCell( colIndex);
if ( cell != null) {
if ( cell.getCellTypeEnum() == CellType.STRING && cell.getStringCellValue().contains( BreakParamParser.DEFAULT_TAG)) {
// 改ページを挿入
if ( isInMergedRegion( sheet, row, cell)) {
setRowBreakMergedRegion( sheet, row, cell);
} else {
setRowBreak( sheet, row, cell);
}
}
}
}
}
示例5: getCachedFormulaResultTypeEnum
/**
* Not supported
*/
@Override
public CellType getCachedFormulaResultTypeEnum() {
if (type != null && "str".equals(type)) {
if(contentsSupplier.getContent() == null || cachedFormulaResultType == null) {
return CellType.BLANK;
} else if("n".equals(cachedFormulaResultType)) {
return CellType.NUMERIC;
} else if("s".equals(cachedFormulaResultType) || "inlineStr".equals(cachedFormulaResultType)) {
return CellType.STRING;
} else if("str".equals(cachedFormulaResultType)) {
return CellType.FORMULA;
} else if("b".equals(cachedFormulaResultType)) {
return CellType.BOOLEAN;
} else if("e".equals(cachedFormulaResultType)) {
return CellType.ERROR;
} else {
throw new UnsupportedOperationException("Unsupported cell type '" + cachedFormulaResultType + "'");
}
}
else {
throw new IllegalStateException("Only formula cells have cached results");
}
}
示例6: copyCellByBlankSpace
/**
* 复制单位格(空白行的复制,即只复制格式和固定文字,不填充数据)
*
* @author ZhengWei(HY)
* @createDate 2017-07-03
* @version v1.0
*
* @param i_RTemplate 模板对象
* @param i_TemplateCell 模板中的单元格对象
* @param i_DataWorkbook 数据工作薄
* @param i_DataCell 数据中的单元格对象
* @param io_RSystemValue 系统变量信息
* @param i_Datas 本行对应的数据
* @param io_RValue 小计循环的迭代器
* @return
*/
public final static void copyCellByBlankSpace(RTemplate i_RTemplate ,Cell i_TemplateCell ,RWorkbook i_DataWorkbook ,Cell i_DataCell ,RSystemValue io_RSystemValue)
{
// 复制样式
i_DataCell.setCellStyle(i_DataWorkbook.getCellStyle(i_RTemplate ,i_TemplateCell.getCellStyle().getIndex()));
// 复制评论
copyComment(i_RTemplate ,i_TemplateCell ,i_DataWorkbook ,i_DataCell);
// 复制数据类型
CellType v_CellType = i_TemplateCell.getCellTypeEnum();
// i_DataCell.setCellType(v_CellType); 不能在此统一设置,原因是:下面代码对类型是有浮动的
if ( v_CellType == CellType.NUMERIC )
{
i_DataCell.setCellType(v_CellType);
if ( HSSFDateUtil.isCellDateFormatted(i_TemplateCell) )
{
i_DataCell.setCellValue(i_TemplateCell.getDateCellValue());
}
else
{
i_DataCell.setCellValue(i_TemplateCell.getNumericCellValue());
}
}
else if ( v_CellType == CellType.STRING )
{
RichTextString v_TemplateRichText = i_TemplateCell.getRichStringCellValue();
String v_ValueName = v_TemplateRichText.toString();
if ( i_RTemplate.isExists(v_ValueName) )
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellValue("");
}
else
{
i_DataCell.setCellType(v_CellType);
copyRichTextStyle(i_RTemplate ,v_TemplateRichText ,i_DataWorkbook ,i_DataCell);
}
}
else if ( v_CellType == CellType.BOOLEAN )
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellValue(i_TemplateCell.getBooleanCellValue());
}
else if ( v_CellType == CellType.FORMULA)
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellFormula(i_TemplateCell.getCellFormula());
}
else
{
// Nothing.
i_DataCell.setCellType(v_CellType);
}
}
示例7: importDatasource
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
SubjectType subjectType = SubjectTypeUtils.getOrCreate(AbstractONSImporter.PROVIDER, OaImporter.OaType.lsoa.name(), OaImporter.OaType.lsoa.datasourceSpec.getDescription());
// Loop over years
for (int sheetId = 0; sheetId < getWorkbook().getNumberOfSheets(); sheetId++){
Sheet sheet = getWorkbook().getSheetAt(sheetId);
int year;
try {
year = Integer.parseInt(sheet.getSheetName().substring(sheet.getSheetName().length()-4, sheet.getSheetName().length()));
}catch (NumberFormatException e){
// Sheetname does not end in a year
continue;
}
// Create extractors for each timed value
List<TimedValueExtractor> timedValueExtractors = new ArrayList<>();
RowCellExtractor subjectExtractor = new RowCellExtractor(0, CellType.STRING);
ConstantExtractor timestampExtractor = new ConstantExtractor(String.valueOf(year));
// Get the attribute label row and create TimedValueExtractors
Row attributeLabelRow = sheet.getRow(5);
for (int columnId = 0; columnId < attributeLabelRow.getLastCellNum(); columnId++){
RowCellExtractor tmpAttributeLabelExtractor = new RowCellExtractor(columnId, CellType.STRING);
tmpAttributeLabelExtractor.setRow(attributeLabelRow);
Attribute attribute = AttributeUtils.getByProviderAndLabel(getProvider(), tmpAttributeLabelExtractor.extract());
if (attribute != null){
ConstantExtractor attributeExtractor = new ConstantExtractor(attribute.getLabel());
RowCellExtractor valueExtractor = new RowCellExtractor(columnId, CellType.NUMERIC);
timedValueExtractors.add(new TimedValueExtractor(getProvider(), subjectType, subjectExtractor, attributeExtractor, timestampExtractor, valueExtractor));
}
}
// Extract timed values
excelUtils.extractAndSaveTimedValues(sheet, this, timedValueExtractors);
}
getWorkbook().close();
}
示例8: importDatasource
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
// Choose the apppropriate workbook sheet
Workbook workbook = excelUtils.getWorkbook(
downloadUtils.fetchInputStream(new URL(DATASOURCE), getProvider().getLabel(), DATASOURCE_SUFFIX));
Sheet sheet = workbook.getSheet("Active People Survey");
String year = "2013";
List<TimedValueExtractor> timedValueExtractors = new ArrayList<>();
RowCellExtractor subjectExtractor = new RowCellExtractor(0, CellType.STRING);
ConstantExtractor timestampExtractor = new ConstantExtractor(year);
SubjectType subjectType = SubjectTypeUtils.getOrCreate(AbstractONSImporter.PROVIDER,
OaImporter.OaType.localAuthority.name(), OaImporter.OaType.localAuthority.datasourceSpec.getDescription());
for (AttributeLabel attributeLabel : AttributeLabel.values()){
ConstantExtractor attributeExtractor = new ConstantExtractor(attributeLabel.name());
RowCellExtractor valueExtractor
= new RowCellExtractor(getAttributeColumnId(attributeLabel), CellType.NUMERIC);
timedValueExtractors.add(new TimedValueExtractor(
getProvider(),
subjectType,
subjectExtractor,
attributeExtractor,
timestampExtractor,
valueExtractor));
}
excelUtils.extractAndSaveTimedValues(sheet, this, timedValueExtractors);
}
示例9: getTimedValueAttributes
@Override
public List<Attribute> getTimedValueAttributes(String datasourceID) throws Exception {
RowCellExtractor attributeNameExtractor = new RowCellExtractor(0, CellType.STRING);
if (null == getWorkbook()) {
setWorkbook(excelUtils.getWorkbook(
downloadUtils.fetchInputStream(new URL(DATAFILE), getProvider().getLabel(), DATAFILE_SUFFIX)));
}
Map<String, Attribute> attributes = new HashMap<>();
Sheet sheet = workbook.getSheetAt(3);
Iterator<Row> rowIterator = sheet.iterator();
Row header = rowIterator.next();
while (rowIterator.hasNext()){
Row row = rowIterator.next();
attributeNameExtractor.setRow(row);
String attributeLabel = attributeNameExtractor.extract();
if (!attributes.containsKey(attributeLabel))
attributes.put(
attributeLabel,
new Attribute(getProvider(), attributeLabel, attributeLabel)
);
}
workbook.close();
return new ArrayList<>(attributes.values());
}
示例10: importDatasource
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
// Choose the apppropriate workbook sheet
Workbook workbook = excelUtils.getWorkbook(
downloadUtils.fetchInputStream(new URL(DATASOURCE), getProvider().getLabel(), DATASOURCE_SUFFIX));
Sheet sheet = workbook.getSheetAt(1);
String year = "2014";
List<TimedValueExtractor> timedValueExtractors = new ArrayList<>();
RowCellExtractor subjectExtractor = new RowCellExtractor(1, CellType.STRING);
ConstantExtractor timestampExtractor = new ConstantExtractor(year);
SubjectType subjectType = SubjectTypeUtils.getOrCreate(AbstractONSImporter.PROVIDER,
OaImporter.OaType.localAuthority.name(), OaImporter.OaType.localAuthority.datasourceSpec.getDescription());
for (AttributeLabel attributeLabel : AttributeLabel.values()){
ConstantExtractor attributeExtractor = new ConstantExtractor(attributeLabel.name());
RowCellExtractor valueExtractor
= new RowCellExtractor(getAttributeColumnId(attributeLabel), CellType.NUMERIC);
timedValueExtractors.add(new TimedValueExtractor(
getProvider(),
subjectType,
subjectExtractor,
attributeExtractor,
timestampExtractor,
valueExtractor));
}
excelUtils.extractAndSaveTimedValues(sheet, this, timedValueExtractors);
}
示例11: importDatasource
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
SubjectType subjectType = SubjectTypeUtils.getOrCreate(AbstractONSImporter.PROVIDER,
OaImporter.OaType.localAuthority.name(), OaImporter.OaType.localAuthority.datasourceSpec.getDescription());
ExcelUtils excelUtils = new ExcelUtils();
File localFile = downloadUtils.fetchFile(new URL(DATAFILE), getProvider().getLabel(), ".zip");
ZipFile zipFile = new ZipFile(localFile);
for (AttributePrefix attributePrefix : AttributePrefix.values()){
ZipArchiveEntry zipEntry = zipFile.getEntry(bookNames[attributePrefix.ordinal()]);
Workbook workbook = excelUtils.getWorkbook(zipFile.getInputStream(zipEntry));
for (String sheetName : sheetNames) {
RowCellExtractor subjectLabelExtractor = new RowCellExtractor(1, CellType.STRING);
ConstantExtractor timestampExtractor = new ConstantExtractor("2016"); // FIXME: Need to generalise when we update Datasource to be time aware
List<TimedValueExtractor> extractors = new ArrayList<>();
for (String metricName : metricNames) {
ConstantExtractor attributeLabelExtractor = new ConstantExtractor(getAttributeLabel(attributePrefix, sheetName, metricName));
RowCellExtractor valueExtractor;
switch (metricName){
case "Mean":
valueExtractor = new RowCellExtractor(5, CellType.NUMERIC);
break;
case "Median":
valueExtractor = new RowCellExtractor(3, CellType.NUMERIC);
break;
default:
throw new Error("Unknown metric name: " + metricName);
}
extractors.add(new TimedValueExtractor(getProvider(), subjectType, subjectLabelExtractor, attributeLabelExtractor, timestampExtractor, valueExtractor));
}
Sheet sheet = workbook.getSheet(sheetName);
excelUtils.extractAndSaveTimedValues(sheet,this,extractors);
}
}
}
示例12: setUp
@Before
public void setUp() throws Exception {
//
int rowIndex = 0;
int columnIndex = 0;
CellType cellType = CellType.STRING;
rowWithSingleCell = new ExpowRowLib(rowIndex);
rowWithSingleCell.addCell(ExpowCellLib.getSample());
rowWithMultiCells = new ExpowRowLib(rowIndex);
rowWithMultiCells.addCell(new ExpowCellLib(rowIndex, columnIndex++, cellType, "Hello"));
rowWithMultiCells.addCell(new ExpowCellLib(rowIndex, columnIndex++, cellType, "My"));
rowWithMultiCells.addCell(new ExpowCellLib(rowIndex, columnIndex++, cellType, "Friends"));
}
示例13: setUp
@Before
public void setUp() throws Exception {
//
int columnIndex = 0;
CellType cellType = CellType.STRING;
this.columnWithSingleCell = new ExpowColumnLib(columnIndex);
this.columnWithSingleCell.addCell(ExpowCellLib.getSample());
this.columnWithMultiCells = new ExpowColumnLib(columnIndex);
this.columnWithMultiCells.addCell(new ExpowCellLib(0,0,cellType, "Hello"));
this.columnWithMultiCells.addCell(new ExpowCellLib(1,0,cellType, "Hey"));
this.columnWithMultiCells.addCell(new ExpowCellLib(2,0,cellType, "Hi"));
}
示例14: testExpowCellWithNullValueWithIllegalArgumentException
@Test(expected=IllegalArgumentException.class)
public void testExpowCellWithNullValueWithIllegalArgumentException() {
//
int rowIndex = 0;
int columnIndex = 0;
CellType cellType = CellType.STRING;
new ExpowCellLib(rowIndex, columnIndex, cellType, null);
}
示例15: isParse
/**
* パース処理を行うか否かの判定
*
* @param sheet 対象シート
* @param tagCell 対象セル
* @return 処理対象の場合はTrue、処理対象外の場合はFalse
* @throws ParseException
*/
public boolean isParse( Sheet sheet, Cell tagCell) throws ParseException {
if ( tagCell == null) {
return false;
}
// 文字列かつ、タグを含むセルの場合は処理対象
if ( tagCell.getCellTypeEnum() == CellType.STRING) {
if ( tagCell.getStringCellValue().contains( tag)) {
return true;
}
}
return false;
}