Forum Discussion

jpolvino's avatar
Occasional Contributor
2 years ago

Reading long int from Excel, showing up in TC as a float

TL;DR I want to get exactly what appears in the Excel cell.


I have code that reads a number of fields from an Excel file. At least a few of the fields have integers with a large number of digits, and they are coming over as floats.

excelFileAbsolutePath = "\\\\path\\to\\file\\input.xlsx"
excelFile = Excel.Open(excelFileAbsolutePath)
excelSheet = excelFile.SheetByTitle[worksheetName]
worksheetObjValue = excelSheet.Cell[2,2].Value


In cell 2,2 Excel has the value 20220829. When I debug the Python script, it is showing up as 20220829.0. I tried casting to str, but all that does is make it "20220829.0" I even tried on the Excel side to format the column to be text and that had no impact. So far, the workaround I found is to set the cell in Excel to be something like ="20220829" but that is awfully kludgy IMHO.


Is there a way to get the text of the cell, as opposed to the value? I recall VBA had methods to get the bare text for this reason, but I am not aware of an analogous method through TestComplete. Doing Python magic, such as trimming off the ".0" at the end is not preferable because some of my data may legitimately want those characters.