2017-08-09 70 views
0

格式百分比pywin32更改为数字输入在Excel中要改变在python3.6我如何在python3.6

pywin32格式%到数在Excel中,这是我的代码。

def qms(self): 
    fname = QtWidgets.QFileDialog.getOpenFileName(self) 

    if fname[0]: 
     self.Filename.setText(fname[0]) 
     excel = win32com.client.gencache.EnsureDispatch("Excel.Application") 
     excel.Visible = True 
     f = excel.Workbooks.Open(fname[0]) 
     fs = f.ActiveSheet 
     lastrow = fs.UsedRange.Rows.Count 

     for i in range(lastrow, 2, -1): 
      if fs.Cells(i,5).Value == None or fs.Cells(i,5).Value == "": 
       fs.Rows(i).EntireRow.Delete() 
      elif fs.Cells(i,2).Value == "Wire sweep율": 
       for x in range(11, 21): 
        fs.Cells(i,x).Value = fs.Cells(i,x).Value * 100 
        print(fs.Cells(i,x).Value) 

if if do 4.24% -> 424%。我想4.24% -> 4.24

你能帮我吗?

在此先感谢。

回答

0
def qms(self): 
     fname = QtWidgets.QFileDialog.getOpenFileName(self) 
     if fname[0]: 
      self.Filename.setText(fname[0]) 
      excel = win32com.client.gencache.EnsureDispatch("Excel.Application") 
      excel.Visible = True 
      f = excel.Workbooks.Open(fname[0]) 
      fs = f.ActiveSheet 
      lastrow = fs.UsedRange.Rows.Count 

      for i in range(lastrow, 2, -1): 
       if fs.Cells(i,5).Value == None or fs.Cells(i,5).Value == "": 
        fs.Rows(i).EntireRow.Delete() 
       elif fs.Cells(i,2).Value == "Wire sweep율": 
        for x in range(11, 21): 
         fs.Cells(i,x).NumberFormat ="G/표준" 
         fs.Cells(i,x).Value = fs.Cells(i,x).Value * 100