在excel文件(带宏)到单元格中,我正在写入整数值1,3等等。比,我用这段代码将这个文件转换成csv格式:
class ExcelToCsvConvert:
@staticmethod
def makeCsv():
workbook = xlrd.open_workbook('csv_file.xlsm')
for sheet in workbook.sheets():
with open('{}.csv'.format(sheet.name), 'w', newline="") as f:
writer = csv.writer(f, delimiter=";", quoting=csv.QUOTE_MINIMAL)
for row in range(sheet.nrows):
out = []
for cell in sheet.row_values(row):
try:
out.append(cell.decode('utf-8'))
except:
out.append(cell)
#out[4] = int(out[4])
print(out[4])
writer.writerow(out)
有些值(print(out)
)打印的内容类似于:'1.0', '3.0'
我需要整数值(1 , 3
)。没有.0
如何做到这一点,或者,我做错了什么?
好的,我用这个循环解决了:
if ".0" in str(cell)[-2:]:
cell = str(cell)[:-2]