美文网首页
Python-115 Replace row names in

Python-115 Replace row names in

作者: RashidinAbdu | 来源:发表于2021-08-26 10:17 被阅读0次
  • 先打开对应的excel文件,然后设定对应的坐标,然后进行对应字符的替换!

  • 具体代码如下:

from openpyxl import load_workbook

wb = load_workbook('D:\\USB-GCMS-FILES\\SCFA-GCMS-EXCEL-RESULT_OF_EACH_STRAIN\\SD-N-D8-16-SCFAs-结果.xlsx')
ws = wb['Sheet1']
ws.cell(row=1,column=1).value = 'Strain'
ws.cell(row=1,column=2).value = 'No'
ws.cell(row=1,column=3).value = 'RetentionTime'
ws.cell(row=1,column=4).value = 'Starting'
ws.cell(row=1,column=5).value = 'Ending'
ws.cell(row=1,column=6).value = 'm/z'
ws.cell(row=1,column=7).value = 'PeakArea'

ws.cell(row=1,column=8).value = 'Peak%'
ws.cell(row=1,column=9).value = 'PeakHight'
ws.cell(row=1,column=10).value = 'PeakHight%'
ws.cell(row=1,column=11).value = 'A/H'
ws.cell(row=1,column=12).value = 'Node'
ws.cell(row=1,column=13).value = 'Name'


wb.save('D:\\USB-GCMS-FILES\\SCFA-GCMS-EXCEL-RESULT_OF_EACH_STRAIN\\SD-N-D8-16-SCFAs-English.xlsx')

就搞定了!

  • 改良的代码:只需要输入文件名称,事前把路径放进去,标签页放进去;

from openpyxl import load_workbook

filename = 'GAM-CK-SCFAs-结果'

wb = load_workbook('D:\\USB-GCMS-FILES\\SCFA-GCMS-EXCEL-RESULT_OF_EACH_STRAIN\\' + filename+'.xlsx')
ws = wb['Sheet1']
ws.cell(row=1,column=1).value = 'Strain'
ws.cell(row=1,column=2).value = 'No'
ws.cell(row=1,column=3).value = 'RetentionTime'
ws.cell(row=1,column=4).value = 'Starting'
ws.cell(row=1,column=5).value = 'Ending'
ws.cell(row=1,column=6).value = 'm/z'
ws.cell(row=1,column=7).value = 'PeakArea'

ws.cell(row=1,column=8).value = 'Peak%'
ws.cell(row=1,column=9).value = 'PeakHight'
ws.cell(row=1,column=10).value = 'PeakHight%'
ws.cell(row=1,column=11).value = 'A/H'
ws.cell(row=1,column=12).value = 'Node'
ws.cell(row=1,column=13).value = 'Name'
ws.cell(row=1,column=14).value = 'Similarity'



wb.save('D:\\USB-GCMS-FILES\\SCFA-GCMS-EXCEL-RESULT_OF_EACH_STRAIN\\' + 'English-' + filename + '.xlsx')

  • Reference:
https://stackoverflow.com/questions/45353881/replacing-row-names-in-excel-using-python

相关文章

网友评论

      本文标题:Python-115 Replace row names in

      本文链接:https://www.haomeiwen.com/subject/qmwyiltx.html