ci the do_apb_file
This commit is contained in:
parent
490fa0495f
commit
b3cefc4498
|
@ -54,7 +54,7 @@ def no_copy_workbook(file_path, sheet_name):
|
|||
break
|
||||
|
||||
|
||||
pattern_row = 0
|
||||
pattern_row = None
|
||||
if offset_col is None or regname_col is None or bits_col is None:
|
||||
print("[Error]: 未找到OffsetAddress列或RegName列或Bits列")
|
||||
return
|
||||
|
@ -75,11 +75,10 @@ def no_copy_workbook(file_path, sheet_name):
|
|||
is_in_sequence = False
|
||||
|
||||
# The cell Not copied logic
|
||||
first_pattern_row = 0
|
||||
for col in range(sheet.ncols):
|
||||
for row in range(sheet.nrows):
|
||||
# > OffsetAddress and RegName_col col not copied
|
||||
if (row >= pattern_row and (col == offset_col or col == regname_col)) or (sheet.cell(row, col).value == 'offset' or sheet.cell(row, col).value == 'regname'):
|
||||
if (pattern_row is not None and row >= pattern_row and (col == offset_col or col == regname_col)) or (sheet.cell(row, col).value == 'offset' or sheet.cell(row, col).value == 'regname'):
|
||||
continue
|
||||
# The Bits col not copied logic
|
||||
if col == bits_col:
|
||||
|
@ -124,6 +123,9 @@ def process_OffsetAddress_and_RegName_Bits_col(file_path, sheet_name):
|
|||
|
||||
# 处理OffsetAddress列
|
||||
for row in range(1, sheet.nrows): # 跳过表头
|
||||
if pattern_row is None:
|
||||
print("[Note]: No need update OffsetAddress and RegName columns")
|
||||
break
|
||||
cell_value = sheet.cell(row, offset_col).value # offset_col is the offsetAddress column
|
||||
|
||||
if row >= pattern_row and cell_value and str(cell_value).strip():
|
||||
|
@ -145,9 +147,11 @@ def process_OffsetAddress_and_RegName_Bits_col(file_path, sheet_name):
|
|||
last_valid_value = cell_value
|
||||
|
||||
last_reg = None
|
||||
|
||||
# 处理RegName列
|
||||
for row in range(1, sheet.nrows):
|
||||
if pattern_row is None:
|
||||
print("[Note]: No need update OffsetAddress and RegName columns")
|
||||
break
|
||||
cell_value = sheet.cell(row, regname_col).value
|
||||
|
||||
if row >= pattern_row and cell_value and str(cell_value).strip():
|
||||
|
@ -163,32 +167,40 @@ def process_OffsetAddress_and_RegName_Bits_col(file_path, sheet_name):
|
|||
elif cell_value and str(cell_value).startswith('reg_'):
|
||||
last_reg = cell_value # 记录最后一个有效的reg名称
|
||||
|
||||
# 处理Bits列
|
||||
prev_right = None
|
||||
counter = 0
|
||||
# 处理Bits列
|
||||
for (start, end) in row_range:
|
||||
for row in range(start, end + 1):
|
||||
cell_value = int(sheet.cell(row, offsetWidth_col).value)
|
||||
counter += cell_value
|
||||
if row == start and cell_value and str(cell_value).strip():
|
||||
left = 32 -1
|
||||
right = left - cell_value + 1
|
||||
content = f"[{left}:{right}]"
|
||||
content = f"[{left}:{right}]" if left != right else f"[{left}]"
|
||||
ws.write(row, bits_col, content)
|
||||
modified = True
|
||||
prev_right = right
|
||||
elif row == end and cell_value and str(cell_value).strip():
|
||||
left = prev_right - 1
|
||||
right = left - cell_value + 1
|
||||
content = f"[{left}:{right}]"
|
||||
content = f"[{left}:{right}]" if left != right else f"[{left}]"
|
||||
ws.write(row, bits_col, content)
|
||||
modified = True
|
||||
prev_right = None
|
||||
else:
|
||||
if prev_right is not None:
|
||||
left = prev_right - 1
|
||||
right = left - cell_value + 1
|
||||
content = f"[{left}:{right}]"
|
||||
content = f"[{left}:{right}]" if left != right else f"[{left}]"
|
||||
ws.write(row, bits_col, content)
|
||||
prev_right = right
|
||||
modified = True
|
||||
else:
|
||||
print(f"[Warning]: No previous right value for row {row} in Bits column")
|
||||
if counter != 32:
|
||||
print(f"[Warning]: Bits column total width is {counter}, expected 32 bits")
|
||||
counter = 0 # Reset counter for next sequence
|
||||
|
||||
#if row >= pattern_row and cell_value and str(cell_value).strip():
|
||||
# if cell_value == 'BitsHead':
|
||||
|
@ -291,7 +303,6 @@ if __name__ == "__main__":
|
|||
print("This is OK,sheets_num is : %d" % sheets_num)
|
||||
|
||||
|
||||
#for index in range(sheets_num):
|
||||
for index in range(1):
|
||||
sheet = book.sheet_by_index(index)
|
||||
print("Sheet Name: %s"%(sheet.name))
|
||||
|
|
BIN
Scripts/test.xls
BIN
Scripts/test.xls
Binary file not shown.
Loading…
Reference in New Issue