#!/bin/bash # 定义Excel文件路径和Sheet名称 EXCEL_FILE="example.xlsx" SHEET_NAME="Sheet1" # 读取Excel文件内容 echo "Reading Excel file ${EXCEL_FILE}" python - <<END import openpyxl # 打开Excel文件 wb = openpyxl.load_workbook('${EXCEL_FILE}') # 获取指定Sheet sheet = wb['${SHEET_NAME}'] # 获取Sheet的行数和列数 max_row = sheet.max_row max_col = sheet.max_column # 遍历Sheet的所有单元格,并输出内容 for i in range(1, max_row+1): for j in range(1, max_col+1): cell_value = sheet.cell(row=i, column=j).value if cell_value: print(f'Cell({i},{j}): {cell_value}') END # 写入Excel文件内容 echo "Writing to Excel file ${EXCEL_FILE}" python - <<END import openpyxl # 打开Excel文件 wb = openpyxl.load_workbook('${EXCEL_FILE}') # 获取指定Sheet sheet = wb['${SHEET_NAME}'] # 写入内容到指定单元格 sheet.cell(row=1, column=1, value='Hello, world!') sheet.cell(row=2, column=1, value='This is a test.') # 保存Excel文件 wb.save('${EXCEL_FILE}') END
标签:execl,文件,shell,读入,EXCEL,Excel,FILE From: https://www.cnblogs.com/hanwei666/p/17158872.html