Huyền điểu guitar tab (玄鸟) – Tát Cát (萨吉) Trường Nguyệt Tẫn Minh OST (长月烬明OST)

Описание к видео Huyền điểu guitar tab (玄鸟) – Tát Cát (萨吉) Trường Nguyệt Tẫn Minh OST (长月烬明OST)

from openpyxl import load_workbook

def read_cell_a1(file_path,cell):
Mở tệp Excel
workbook = load_workbook(file_path)
Chọn sheet đầu tiên trong tệp
sheet = workbook.active
Đọc giá trị từ ô A1
value = sheet[cell].value
Đóng workbook sau khi đọc xong
workbook.close()
Trả về giá trị của ô A1
return value
def format_data(input_str):
Tách các dòng và lấy dữ liệu
lines = input_str.strip().split('\n')
data = {}
single_value_case = True

for line in lines:
key, values = line.split(' = ')
values = values.split(',')

if len(values) ... 1:
single_value_case = False


data[key] = values

Xử lý trường hợp chuỗi có nhiều giá trị
if not single_value_case:
output_str = ""
num_rows = len(data[next(iter(data))])
for i in range(num_rows):
output_str += f"no {i + 1}\n{{\n"
for key in data:
output_str += f"{key} = {data[key][i]}\n"
output_str += "}\n"

Xử lý trường hợp chuỗi chỉ có một giá trị
else:
output_str = ""
for key in data:
output_str += f"exp of {key} is {data[key][0]}\n"
output_str += '\n--------------'
return output_str
def write_to_file(filename, content):
with open(filename, 'w') as file:
file.write(content)
def write_to_file(filename, content):
mode = 'a' if append else 'w'
with open(filename, 'w') as file:
file.write(content)

file_path = 'test.xlsx'
filename = 'a.txt'
temp_str = ''
for z in range(2, 6):
cell_x = 'A' + str(z)
function = read_cell_a1(file_path,cell_x)
print('----'+function+'------')
print('----tescaseNo '+str(z-1)+'------')
cell_i = 'B' + str(z)
expected_value = read_cell_a1(file_path,cell_i)
expected_value = expected_value.replace("[", "")
input_str = expected_value.replace("]", "")
print(format_data(input_str))
a = '---- '+function+' | tescaseNo == '+str(z-1)+'------\n'
temp_str += a + format_data(input_str)
write_to_file(filename, temp_str)

Комментарии

Информация по комментариям в разработке