I have the following Openpyxl code. This code gets the value of every cell in the range. I however only want the values from columns A,B,C,M,W and X for each row. How on earth do I do this? Thank you all in advance.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With