Java poi 3.17中除getCellTypeEnum()之外的getcelltype的替代项

Java poi 3.17中除getCellTypeEnum()之外的getcelltype的替代项,java,excel,apache-poi,Java,Excel,Apache Poi,我正在阅读一个excel文件,并使用ApachePOI3.17将其转换为XML文件。我正在使用getCelltype获取当前单元格的单元格类型。但是我得到了“getCellType()被折旧”。我搜索了其他问题,但我发现我应该使用“CellType getCellTypeEnum()”。但这也显示出同样的警告。我在ApachePOI文档中搜索了一下,但是上面写着“getCellTypeEnum()”被贬低了,并且“改用getCellType”。我不明白应该用什么来删除警告。如果有人能提供帮助,g

我正在阅读一个excel文件,并使用ApachePOI3.17将其转换为XML文件。我正在使用getCelltype获取当前单元格的单元格类型。但是我得到了“
getCellType()
被折旧”。我搜索了其他问题,但我发现我应该使用“
CellType getCellTypeEnum()
”。但这也显示出同样的警告。我在ApachePOI文档中搜索了一下,但是上面写着
“getCellTypeEnum()”
被贬低了,并且“改用
getCellType
”。我不明白应该用什么来删除警告。如果有人能提供帮助,
getCellType()
的其他替代方案在这种情况下可用吗

try {
            log.info("Getting the path for Input Excel File");
           // String excelPath = "D:\\Tools\\BaNCS_Dictionary_Specification_1.0_Latest.xlsx";
            String excelPath=InputExcel.inputExcel();
        FileInputStream fileInputStream = new FileInputStream(new File(excelPath));

        // Create Workbook instance holding .xls file
        log.info("Creating workbook instance for XSSFWorkbook");
        XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);

        // Get the first worksheet
        log.info("Creating the sheet of XSSFSheet");
        XSSFSheet sheet = workbook.getSheet("DictionarySpecification");
        int i=InputExcelValidator.DictionarySpecificationRowsValidator(sheet);

        // Iterate through each rows
        log.info("Creating RowIterator to iterate through the rows");
        Iterator<Row> rowIterator = sheet.iterator();

        while (rowIterator.hasNext()) {
            // Get Each Row
            log.info("Getting each row one by one");
            Row row = rowIterator.next();
            log.info("Assigning the value of tempForEmptyRowCount2 to tempForEmptyRowCount1");
            int tempForEmptyRowCount2=tempForEmptyRowCount1;
            log.info("Getting the rowNumber of Current Iteration");
            tempForEmptyRowCount1=row.getRowNum();
            if(row.getRowNum()==0){
                log.info("Skipping The first row of the Excel File");
                continue;
            }
            if (row.getRowNum() <= 25 && row.getRowNum()>0) {
                log.info("Adding the Dictionary Specification Values and calling addDictionarySpecifications");
                addDictionarySpecifications(tempForEmptyRowCount2, rowIterator, row);
                continue;
            }
            if(row.getRowNum()-tempForEmptyRowCount2>2){
                log.error("Please correct the format to input table details");
                throw new TableInputFormatException("Please correct the format to input table details");
            }

            if (row.getRowNum()-tempForEmptyRowCount2>1) {
                log.info("Skipping Empty Row");
                tempForAddingValuesToTable1 = 1;
                tempForAddingValuesToTable2 = false;
                tempForTableCount++;
                continue;
            }
            log.info("Creating CellIterator inatance");
            Iterator<Cell> cellIterator = row.cellIterator();
            if (tempForAddingValuesToTable1 == 1 && tempForAddingValuesToTable2 == false) {
                log.info("Adding the table values");
                Table table = new Table();
                log.info("Creating an empty arrayList in Table for fields");
                table.setFieldList(new ArrayList<Field>());
                while (cellIterator.hasNext()) {
                    log.info("Iterating the cells for table values");
                    Cell cell = cellIterator.next();
                    int columnIndex = cell.getColumnIndex();
                    switch (columnIndex + 1) {
                        case 1:
                            log.info("Adding the table name");
                            table.setName(cell.getStringCellValue().trim());
                            break;
                        case 2:
                            log.info("Adding the table annotation");
                            table.setAnnotation(cell.getStringCellValue().trim());
                            break;
                        case 3:
                            log.info("Adding the table Identifier");
                            table.setIdentifier(cell.getStringCellValue().trim());
                            break;
                        case 4:
                            log.info("Adding the table FieldPosition");
                            switch (cell.getCellType()){
                                case Cell.CELL_TYPE_STRING:
                                    table.setFieldPosition(Integer.parseInt( cell.getStringCellValue().trim()));
                                    break;
                                case Cell.CELL_TYPE_NUMERIC:
                                    table.setFieldPosition((int) cell.getNumericCellValue());
                                    break;
                            }

                            break;
                        case 5:
                            log.info("Adding the table RecordType");
                            switch (cell.getCellType()){
                                case Cell.CELL_TYPE_STRING:
                                    table.setRecordType( cell.getStringCellValue());
                                    break;
                                case Cell.CELL_TYPE_NUMERIC:
                                    table.setRecordType( String.valueOf(cell.getNumericCellValue()));
                                    break;
                            }
                            break;
                    }
                }
                log.info("Adding the table to Tables");
                tables.getTableList().add(table);
                tempForAddingValuesToTable2=true;
                continue;
            }
            if (tempForAddingValuesToTable1 == 1 && tempForAddingValuesToTable2 == true) {
                log.info("Skipping Empty Row");
                tempForAddingValuesToTable1=0;
                continue;
            }
            if (tempForAddingValuesToTable1 == 0 && tempForAddingValuesToTable2 == true) {
                log.info("Creating Field Instance");
                Field field = new Field();
                while (cellIterator.hasNext()) {
                    log.info("Adding the field values one by one");
                    Cell cell = cellIterator.next();
                    int columnIndex = cell.getColumnIndex();
                    int tempColumnIndex = columnIndexIndicator;
                    if (tempColumnIndex - columnIndexIndicator > 1) {
                        field.setDefaultValue("null");
                    }
                    switch (columnIndex + 1) {
                        case 1:
                            log.info("Adding name for field");
                            field.setName(cell.getStringCellValue().trim());
                            break;
                        case 2:
                            log.info("Adding Annotation for field");
                            field.setAnnotation(cell.getStringCellValue().trim());
                            break;
                        case 3:
                            log.info("Adding DataType for field");
                            field.setDataType(cell.getStringCellValue());
                            break;

                        case 4:
                            log.info("Adding Size for field");
                            switch (cell.getCellType()) {
                                case Cell.CELL_TYPE_STRING:
                                    field.setSize(cell.getStringCellValue().trim());
                                    break;
                                case Cell.CELL_TYPE_NUMERIC:
                                    Double doubleValue=cell.getNumericCellValue();
                                    DecimalFormat format = new DecimalFormat("0.#");
                                    field.setSize(format.format(doubleValue));
                                    break;
                            }
                            break;

                        case 5:
                            log.info("Adding pKey for field");
                            if (cell.getCellType() == cell.CELL_TYPE_STRING) {
                                String s2 = cell.getStringCellValue();

                                if (s2.equals("Yes"))
                                    tempForAddingBooleanValuesToTable = true;
                                else
                                    tempForAddingBooleanValuesToTable = false;
                                field.setpKey(tempForAddingBooleanValuesToTable);
                            }
                            break;
                        case 6:
                            log.info("Adding Mandatory for field");
                            if (cell.getStringCellValue().equals("Yes"))
                                tempForAddingBooleanValuesToTable = true;
                            else
                                tempForAddingBooleanValuesToTable = false;
                            field.setMandatory(tempForAddingBooleanValuesToTable);
                            break;
                        case 7:
                            log.info("Adding DefaultValue for field");
                            switch (cell.getCellType()) {
                                case Cell.CELL_TYPE_STRING:
                                    field.setDefaultValue(cell.getStringCellValue().trim());

                                    break;
                                case Cell.CELL_TYPE_NUMERIC:
                                    Double doubleValue=cell.getNumericCellValue();
                                    DecimalFormat format = new DecimalFormat("0.####");
                                    field.setDefaultValue(format.format(doubleValue));
                                    break;
                            }
                            break;
                        case 8:
                            log.info("Adding Rec_Identifier for field");
                            if (cell.getCellType() == cell.CELL_TYPE_NUMERIC) {
                                int i2 = (int) cell.getNumericCellValue();
                                String s = String.valueOf(i2);
                                if (s.equals("Yes"))
                                    tempForAddingBooleanValuesToTable = true;
                                else
                                    tempForAddingBooleanValuesToTable = false;
                                field.setRec_Identifier(tempForAddingBooleanValuesToTable);
                            }
                            break;
                        case 9:
                            log.info("Adding Visible for field");
                            if (cell.getStringCellValue().equals("Yes"))
                                tempForAddingBooleanValuesToTable = true;
                            else
                                tempForAddingBooleanValuesToTable = false;
                            field.setVisible(tempForAddingBooleanValuesToTable);
                            break;

                    }
                    columnIndexIndicator = cell.getColumnIndex();


                }
                if(field.getSize()==null){
                    log.info("Setting the DateFormat");
                    field.setDateFormat("DDMMYYYY");
                }
                log.info("Adding the field to specific table");
                tables.getTableList().get(tempForTableCount).getFieldList().add(field);
            }
        }
        log.info("Setting properties to respective lists");
        recordProperties.setProperties(propertyList1);
        fileProperties.setProperties(propertyList2);
        dataDictionary.setDictionary(dictionary);
        dataDictionary.setFileProperties(fileProperties);
        dataDictionary.setRecordProperties(recordProperties);
        dataDictionary.setTables(tables);
    }
    catch (IOException ie) {
        log.error("Exception Occured: IOException");
        ie.printStackTrace();
    }
    log.info("Calling the createXML to generate the xml file");
    CreateXML.createXML(dataDictionary);
}
public static int addDictionarySpecifications(int j, Iterator<Row> rowIterator,Row row){
   log.info("Getting the CellIterator");
    Iterator<Cell> cellIterator = row.cellIterator();


    if(row.getRowNum()-j>1){
        log.info("Getting Empty Row");
        rowIndicator++;
        tempForSkippingRow=true;
        // return 0;
    }
    if(tempForSkippingRow){
        log.info("Skipping Row");
        tempForSkippingRow=false;
        return 0;

    }
    log.info("Creating instance of Property Object");
    Property property=new Property();
    while (cellIterator.hasNext()) {
        log.info("Getting Cells one by one");
        Cell cell = cellIterator.next();
        log.info("Getting the columnIndex of Current Row");
        int columnIndex = cell.getColumnIndex();

        if(rowIndicator==1) {
            log.info("Adding the Dictionary Nsme and annotation and type");
            switch (columnIndex + 1) {
                case 2:
                    dictionary.setName(cell.getStringCellValue().trim());
                    dictionary.setAnnotation(dictionary.getName());
                    dictionary.setType("DATABASE_TABLES");
                    break;
            }
        }
        if(rowIndicator>1){
            log.info("Adding the Properties for FileProperties and Record Properties");
            switch(columnIndex+1){
                case 1:
                    log.info("GEtting the annotation");
                    String annotation=cell.getStringCellValue().trim();
                    String propertyName;
                    if(annotation.equals("Record Composition")) {
                        log.info("Property is Record Composition");
                        property.setName("COMPOSITION");
                    }
                    else if(annotation.equals("Record Heirarchy")) {
                        log.info("Property is Record Heirarchy");
                        property.setName("HEIRARCHY");
                    }
                    else if(annotation.equals("Set Feed Quality Standards")) {
                        log.info("Property is Set Feed Quality Standards");
                        property.setName("FQD");
                        property.setAnnotation("FQD");
                        break;
                    }
                    else if(annotation.equals("Quality Percentage")) {
                        log.info("Property is Quality Percentage");
                        property.setName("FQD_PERCENT");
                        property.setAnnotation("FQD Percent");
                        break;
                    }
                    else if(annotation.equals("Header Record")) {
                        log.info("Property is Header Record");
                        property.setName("HEADER");
                    }
                    else if(annotation.equals("Trailer Record")) {
                        log.info("Property is Trailer Record");
                        property.setName("TRAILER");
                    }
                    else {
                        log.info("Creating exact name for Property");
                        String[] split = annotation.split("\\s+");
                        String s1=split[0].toUpperCase();
                        String s2=split[1].toUpperCase();
                        propertyName=s1+"_"+s2;
                        log.info("Property is"+propertyName);
                        property.setName(propertyName);
                    }
                    property.setAnnotation(annotation);
                    break;
                case 2:
                    log.info("Setting the valuedescription");
                    String valueDesscription=null;
                    switch (cell.getCellType()) {
                        case Cell.CELL_TYPE_STRING:
                            valueDesscription=cell.getStringCellValue().trim();

                            break;
                        case Cell.CELL_TYPE_NUMERIC:
                            try {
                                valueDesscription=String.valueOf(cell.getNumericCellValue()).trim();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            break;
                    }

                    if(valueDesscription.equals("Multiple Type of Records"))
                        property.setDefaultValue("HETEROGENOUS");
                    else if(valueDesscription.equals("Single Type of Records"))
                        property.setDefaultValue("HOMOGENOUS");
                    else if(valueDesscription.equals("Record Group Without heirarchy"))
                        property.setDefaultValue("GROUPED");
                    else if(valueDesscription.equals("Record Group With heirarchy"))
                        property.setDefaultValue("HEIRARCHY");
                    else if(valueDesscription.equals("Variable Length"))
                        property.setDefaultValue("VARIABLE_LENGTH");
                    else if(valueDesscription.equals("Carriage return line feed(CRLF)"))
                        property.setDefaultValue("CRLF");
                    else if(valueDesscription.equals("Comma(,)"))
                        property.setDefaultValue(",");
                    else if(valueDesscription.equals("Semicolon(;"))
                        property.setDefaultValue(";");
                    else if(valueDesscription.equals("Tilda(~)"))
                        property.setDefaultValue("~");
                    else if(valueDesscription.equals("Pipe(|)"))
                        property.setDefaultValue("|");
                    else if(valueDesscription.equals("Horizontal Tab(HT)"))
                        property.setDefaultValue("HT");
                    else if(valueDesscription.equals("Hash(#)"))
                        property.setDefaultValue("#");
                    else if(valueDesscription.equals("No"))
                        property.setDefaultValue("false");
                    else if(valueDesscription.equals("FAILED"))
                        property.setDefaultValue("FAILED");
                    else if(valueDesscription.equals("File Content"))
                        property.setDefaultValue("HASH_DUP");
                    else if(valueDesscription.equals("File Name"))
                        property.setDefaultValue("FILE_NAME");
                    else if(valueDesscription.equals("Yes"))
                        property.setDefaultValue("true");
                    else
                        property.setDefaultValue(valueDesscription);
                    property.setValueDescription(valueDesscription);
                    break;
                case 3:
                    log.info("Setting the annotation valueDescription and default Value");
                    property.setAnnotation("Duplicate Duration");
                    property.setName("DUPLICATE_DURATION");
                    property.setValueDescription(cell.getStringCellValue().trim());
                    property.setDefaultValue(property.getAnnotation());
                    break;
            }
        }
    }
    if(rowIndicator>1) {
        log.info("Adding the property to PropertyList");
        if (property.getDefaultValue().equals("HETEROGENOUS") || property.getDefaultValue().equals("HOMOGENOUS") || property.getDefaultValue().equals("GROUPED") || property.getDefaultValue().equals("HEIRARCHY"))
            propertyList1.add(property);
        else
            propertyList2.add(property);
    }
    return 0;
}
试试看{
log.info(“获取输入Excel文件的路径”);
//String excelPath=“D:\\Tools\\BaNCS\u Dictionary\u Specification\u 1.0\u Latest.xlsx”;
字符串excelPath=InputExcel.InputExcel();
FileInputStream FileInputStream=newfileinputstream(新文件(excelPath));
//创建包含.xls文件的工作簿实例
info(“为XSSFWorkbook创建工作簿实例”);
XSSF工作簿=新XSSF工作簿(fileInputStream);
//获取第一张工作表
log.info(“创建XSSFSheet的工作表”);
XSSFSheet sheet=workbook.getSheet(“字典规范”);
int i=InputExcelValidator.DictionarySSpecificationRowsValidator(表);
//遍历每一行
info(“创建行迭代器以遍历行”);
迭代器rowIterator=sheet.Iterator();
while(roweiterator.hasNext()){
//拿到每一行
log.info(“逐个获取每一行”);
行=行迭代器。下一步();
log.info(“将tempForEmptyRowCount2的值分配给tempForEmptyRowCount1”);
int tempForEmptyRowCount2=tempForEmptyRowCount1;
log.info(“获取当前迭代的行号”);
tempForEmptyRowCount1=row.getRowNum();
if(row.getRowNum()==0){
log.info(“跳过Excel文件的第一行”);
继续;
}
if(row.getRowNum()0){
log.info(“添加字典规范值并调用AddDictionarySSpecifications”);
addDictionarySpecifications(tempForEmptyRowCount2、行迭代器、行);
继续;
}
if(row.getRowNum()-tempForEmptyRowCount2>2){
log.error(“请更正格式以输入表格详细信息”);
抛出新的TableInputFormatException(“请更正格式以输入表详细信息”);
}
if(row.getRowNum()-tempForEmptyRowCount2>1){
log.info(“跳过空行”);
tempForAddingValuesToTable1=1;
tempForAddingValuesToTable2=假;
tempForTableCount++;
继续;
}
log.info(“创建CellIterator实例”);
迭代器cellIterator=row.cellIterator();
if(tempForAddingValuesToTable1==1&&tempForAddingValuesToTable2==false){
log.info(“添加表值”);
Table Table=新表();
info(“在表中为字段创建一个空的arrayList”);
table.setFieldList(新的ArrayList());
while(cellIterator.hasNext()){
info(“为表值迭代单元格”);
Cell=cellIterator.next();
int columnIndex=cell.getColumnIndex();
开关(列索引+1){
案例1:
log.info(“添加表名”);
table.setName(cell.getStringCellValue().trim());
打破
案例2:
log.info(“添加表注释”);
table.setAnnotation(cell.getStringCellValue().trim());
打破
案例3:
log.info(“添加表标识符”);
table.setIdentifier(cell.getStringCellValue().trim());
打破
案例4:
log.info(“添加表字段位置”);
开关(cell.getCellType()){
case Cell.Cell\u类型\u字符串:
table.setFieldPosition(Integer.parseInt(cell.getStringCellValue().trim());
打破
case Cell.Cell\u类型\u数值:
table.setFieldPosition((int)cell.getNumericCellValue());
打破
}
打破
案例5:
log.info(“添加表记录类型”);
开关(cell.getCellType()){
case Cell.Cell\u类型\u字符串:
table.setRecordType(cell.getStringCellValue());
打破
case Cell.Cell\u类型\u数值:
setRecordType(String.valueOf(cell.getNumericCellValue());
打破
}
打破
}
}
log.info(“将表添加到表中”);
tables.getTableList().add(table);
tempForAddingValuesToTable2=真;
继续;
}
if(tempForAddingValuesToTable1==1&&tempForAddingValuesToTable2==true){
                if(cell.getCellTypeEnum() == CellType.STRING){
                     //your code
                }else  if(cell.getCellTypeEnum() == CellType.NUMERIC){
                    //your code
                }
_NONE(-1),
NUMERIC(0),
STRING(1),
FORMULA(2),
BLANK(3),
BOOLEAN(4),
ERROR(5);