用python操作excel(读写)
import xlrd
import random
from xlutils.copy import copy
import xlutils
def test1():
file = xlrd.open_workbook(filename=r'1.xlsx')
print(file.sheet_names())
table = file.sheets()[0]
table = file.sheet_by_index(sheetx=0)
table = file.sheet_by_name(sheet_name='Sheet1')
print("{0} {1} {2}".format(table.name, table.nrows, table.ncols))
print("Cell A18 is {0}".format(table.cell_value(rowx=17, colx=0)))
def test2():
x = random.random()
x = round(number=x, ndigits=1)
print(x)
def main():
file = xlrd.open_workbook(filename=r'1.xlsx')
table = file.sheets()[0]
wb = copy(wb=file)
for i in range(1, table.nrows):
x = random.uniform(0.1, 0.5) + 29
wb.get_sheet(0).write(i, 2, round(number=x, ndigits=1))
wb.save('2.xlsx')
if __name__ == '__main__':
main()