Number formatted as text recognized as a number

Hi,


I have excel file with two numbers in two different cells, both formatted as text, but second one have warning regarding number formatted as text. Aspose Cell for Java 8.2.2 API method Cell.getType() returns for cell without warning numeric type, and string type for the other cell with warning. That is unexpected behavior for me (it should return string type for both of them), so could You please check that?

You can use following code for that.

Workbook workbook = new Workbook(“number_as_text.xls”);

System.out.println(workbook.getWorksheets().get(“Sheet1”).getCells()
.get(“A2”).getType() == CellValueType.IS_NUMERIC);

System.out.println(workbook.getWorksheets().get(“Sheet1”).getCells()
.get(“A3”).getType() == CellValueType.IS_STRING);

Kind regards,
Zeljko

Hi Zeljko,


Thanks for the template file and sample code.

After an initial test, I observed the issue as you mentioned by using your sample code with your template file. I found that the number formatted as text in A2 cell
is recognized as a number where it should be retrieved as Text.

e.g


Sample code:



Workbook workbook = new Workbook("number_as_text.xls");

System.out.println(workbook.getWorksheets().get("Sheet1").getCells()
.get("A2").getType() == CellValueType.IS_NUMERIC); //true

System.out.println(workbook.getWorksheets().get("Sheet1").getCells()
.get("A3").getType() == CellValueType.IS_STRING);//true

I have logged a ticket with an id "CELLSJAVA-41237" for your issue. We will investigate and look into it if this is expected behavior due to some reason or a bug.

Once we have any update on it, we will let you know here.

Thank you.

Thanks Amjad!


Zeljko

Hi,


We have evaluated your issue further.
Well, Cell.Type is mainly designed for getting the object type of cell’s inner value. For your situation, you can try the following sample code for your needs:
e.g
Sample code:

if(cell.getType() == CellValueType.IS_NUMERIC)
{
if(cell.getNumberCategoryType() == NumberCategoryType.TEXT)
{
//do with the values formatted as Text
}
}

Hopefully, it will fix your issue.

Thank you.

Hi Amjad,


code that You provided does the job for me.

Thanks, Zeljko

Hi,


Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.