1、xlwt
import xlwt
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('My sheet1')
worksheet.write(0, 0, 'My cell Contents')
worksheet.col(0).width = 256 * 20
worksheet.col(2).width = 8888
workbook.save('E:\\test\\xls_xlwt\Excel_cell_width.xls')
1.1 设置行高
import xlwt
workbook = xlwt.Workbook(encoding='utf-8')
sheet = workbook.add_sheet('My sheet1')
first_col = sheet.col(0)
sec_col = sheet.col(1)
first_col.width = 256 * 20
tall_style = xlwt.easyxf('font:height 720')
first_row = sheet.row(0)
first_row.set_style(tall_style)
workbook.save('E:\\test\\xls_xlwt\Excel_row_height.xls')
2、openpyxl
import openpyxl
workbook = openpyxl.load_workbook("C:\\Users\\Wu Xi\\Desktop\\KePuZhongGuo_0-1000_full.xlsx")
sheet = workbook.active
rows = sheet.max_row
column = sheet.max_column
print('rows', rows, 'column', column)
for row_index in range(2, rows + 1):
try:
pdb.set_trace()
cell_title = str(sheet.cell(row_index, 2).value)
cell_is_original = bool(sheet.cell(row_index, 6).value)
3、Pandas
3、1数据读取
pd.read_excel('path_to_file.xls', sheet_name='Sheet1')
with pd.ExcelFile('path_to_file.xls') as xls:
names=xls.sheet_names
df1 = pd.read_excel(xls, 'Sheet1')
df2 = pd.read_excel(xls, 'Sheet2')
data = pd.read_excel('path_to_file.xls', ['Sheet1', 'Sheet2'],
index_col=None, na_values=['NA'])
pd.read_excel('path_to_file.xls', sheet_name=None)
3、1数据写入
df.to_excel('path_to_file.xlsx', sheet_name='Sheet1')
with pd.ExcelWriter('path_to_file.xlsx') as writer:
df1.to_excel(writer, sheet_name='Sheet1')
df2.to_excel(writer, sheet_name='Sheet2')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)