Home > other >  Ctype judgment cell while reading excel data type error, text judgment for floating point value
Ctype judgment cell while reading excel data type error, text judgment for floating point value

Time:09-17

 # coding=utf-8 
The import OS
The import XLRD
The import win32ui
Import a datetime
Def xls_txt () :
"" "
: excel file into a TXT file
: param xls_name excel file name
: param txt_name TXT file name
"" "
Num=1
Try:
Values="";
DLG=win32ui. CreateFileDialog (1) # 1
open file dialog boxDLG. SetOFNInitialDir (') # set the initial display of the open file dialog box directory
DLG. DoModal ()
Filename=DLG. GetPathName ()
Data=https://bbs.csdn.net/topics/xlrd.open_workbook (filename)
L=STR (OS. Path. The basename (filename))
L=l (0-4)
Now=datetime. Datetime. Now (). The strftime (' % Y % m % d ')
D=STR (l) + "_" + STR (now) + ". TXT "
Sqlfile=open (d, "a")
Table=data sheets () [0] # header
Nrows=table. # nrows rows
# if you don't need to skip the header, will in the next line 1 to 0
For ronum in range (0, nrows) :
The row=table. Row_values (ronum)
Article # # values=STRS (row) with the function, the row data splicing into string
For I in range (len (row)) :
Ctype=table. The cell (num, I). The ctype
Print (ctype)
Cell=table. Cell_value (num, I)
If ctype====2 and the cell % 1:0.0 # ctype for 2 and for floating point
The row=int (row [I]) # floating into integer
Values=values + STR (row) + "
"Elif ctype==1:
Values=values + STR (row [I]) + "" use" "# TABLE as a delimiter
Print (values)
Sqlfile. Writelines (values + "\ r") # to write the string into the new file
Sqlfile. Close () # close written file
Except:
Raise
If __name__=="__main__ ':
Xls_txt ()

Tabular data is as follows:

Running results suggest Numerator to float?

CodePudding user response:

The row=int (row [I]) # floating into integer
Values=values + STR (row) + "
"
Instead of
Values=values + STR (row [I]) + "
"
Line not

CodePudding user response:

reference 1st floor weixin_45903952 response:
row=int (row) [I] # floating into integer
Values=values + STR (row) + "
"
Instead of
Values=values + STR (row [I]) + "
"
Line not

Not tried, as an error, the key to this question is why the text of a cell will be identified for floating point Numbers

CodePudding user response:

STR (row)

Print (row) and see what is,
Feel there should be a STR (cell)
  • Related