فهرست منبع

fix: correct column header insertion in insert_column method

mrh (aider) 1 سال پیش
والد
کامیت
670d09c62b
1فایلهای تغییر یافته به همراه8 افزوده شده و 7 حذف شده
  1. 8 7
      function_calling/excel_processor.py

+ 8 - 7
function_calling/excel_processor.py

@@ -183,12 +183,6 @@ class ExcelProcessor:
             
         Returns:
             pd.DataFrame: 包含新列的DataFrame
-        
-        example:
-            processor.insert_column('B', '翻译结果')
-            ref_column_list = [match[1] for match in matches]
-            for ref_column in ref_column_list:
-                processor.insert_column(ref_column, '翻译结果')
         """
         df = self.df
         try:
@@ -206,7 +200,14 @@ class ExcelProcessor:
             # 插入新列
             df.insert(insert_index, new_column_name, '')
             
-            logger.info(f"成功在列 '{ref_column}' 的 '{position}' 插入新列 '{new_column_name}' ")
+            # 调整表头行数据
+            if self.header_row > 0:
+                # 将新列的表头行设置为空
+                df.iloc[:self.header_row, insert_index] = ''
+                # 在表头行设置新列名
+                df.iloc[self.header_row, insert_index] = new_column_name
+            
+            logger.info(f"成功在列 '{ref_column}' 的 '{position}' 插入新列 '{new_column_name}'")
             return df
             
         except Exception as e: