如何使用Python将.xls中的“以文本形式存储的数字”转换为“数字”

时间:2019-11-10 16:31:16

标签: python-3.x

我正在编写python代码以.xls格式分析学生成绩。学生的分数格式设置为“数字存储为文本”。 "Number stored as text warning/ error" 我尝试使用xlrd,xlwt等读取和评估这些标记,但失败了。 使用VBS,我可以使用以下代码将“存储为文本的数字”转换为“数字”:

inputRoot: {
   fontSize: 20,
   "&$cssFocused $notchedOutline": {
     borderColor: "#07a0a9"
   },
   "&:hover:not($disabled):not($cssFocused):not($error) $notchedOutline": {
     borderColor: "#000000"
   },
   "& input:valid + fieldset": {
     borderColor: "#808080",
     borderWidth: 2,
     borderLeftWidth: 6,
     padding: "4px !important" // override inline-style
   },
   "& input:invalid + fieldset": {
     borderWidth: 1
   },
   "& input:valid:focus + fieldset": {
     borderLeftWidth: 6,
     padding: "4px !important" // override inline-style
   }
 },
 cssFocused: {},
 notchedOutline: {},

//Here Is where I think I have to insert some code for the label color when the user finish editing

 label: {
   fontSize: 21,
   "&$focused": {
     color: "#808080"
   }
 }

<TextField
                       fullWidth
                       id="outlined-basic"
                       required
                       className={classes.textFieldName}
                       InputProps={{
                         classes: {
                           root: classes.inputRoot,

                           focused: classes.cssFocused,
                           notchedOutline: classes.notchedOutline
                         }
                       }}
                       InputLabelProps={{
                         classes: {
                           root: classes.label,
                           focused: classes.focused,
                           asterisk: classes.asterisk
                         }
                       }}
                       label="Name"
                       margin="normal"
                       variant="outlined"
                     />

我希望能正常工作的python代码:

Set Rng = objWorkbook.Worksheets(resultsheetname).Range(objWorkbook.Worksheets(resultsheetname).cells(8,4),objWorkbook.Worksheets(resultsheetname).cells(RowsCount-4,25))
For Each c In Rng
With Rng
If Not IsEmpty(c) Then
    If Not c = "AB " Then 
      If Not c= "-- " Then
        If Not c= "XX " Then
            If Not c= "**" then
                       c.Value = c.Value/1
                End if
            End if
        End if
    End If 
End If
End With

1 个答案:

答案 0 :(得分:0)

您需要转换类型

def mersenne_number(p):
   return ((2**p)-1)

也许需要为for cell in sheet1.col(3): value = int(cell.value) # <-- to convert type #worksheet.write(0, 0, datetime.datetime.now(), style) if value == 1: sem1 = sem1+1 print(cell.value) #print(sheet1.row_values(cell)) elif value == 2 : sem2 = sem2+1 elif value == 3 : sem3 = sem3+1 elif value == 4 : sem4 = sem4+1 elif value == 5 : sem5 = sem5+1 elif value == 6 : sem6 = sem6+1 和简短表达式使用字典或列表?

sem

但是,# create dictionary sem = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0} sem = {x: 0 for x in range(1,7)} for cell in sheet1.col(3): sum[int(cell.value)] += 1 可能无法转换为cell.value(整数值),因此您需要异常控制块

int