python – 使用openpyxl获取特定单元格的值

我有以下Openpyxl代码.此代码获取范围中每个单元格的值.然而,我只想要每行的A,B,C,M,W和X列的值.我怎么做到这一点?谢谢大家.

from openpyxl import load_workbook
wb = load_workbook('C:\\Users\\RileyJ\\Documents\\Luci\\ASquad.xlsx', read_only=True, data_only=True)
ws = wb.get_active_sheet()
ws_ranges = ws['A4:X45']

for row in ws_ranges:
    html_data += "\t\t\t<tr>\n"
    for cell in row:
        if cell.value is None:
            html_data += "\t\t\t\t<td>" + ' ' + "</td>\n"
        else:
            html_data += "\t\t\t\t<td>" + str(cell.value) + "</td>\n"
    html_data += "\t\t\t</tr>\n"
html_data += "\t\t</table>\n"
html_data += "\t</body>\n"
html_data += "</html>"

with open("C:\\Users\\RileyJ\\Documents\\Luci\\Luci.html", "w") as html_fil:
    html_fil.write(html_data)
最佳答案
for row in range(4, 46):
    for column in "ABCMWX":  
        cell_name = "{}{}".format(column, row)
        print ws[cell_name].value
点击查看更多相关文章

转载注明原文:python – 使用openpyxl获取特定单元格的值 - 乐贴网