Jelajahi Sumber

将产品信息标题单元格改成下划线

mrh 8 bulan lalu
induk
melakukan
86c71adf7a

+ 5 - 2
src/excel_tools/file_manager.py

@@ -24,6 +24,7 @@ class ExcelFileManager:
         self.db = DbManager()
         self.wb:Workbook = self._prepare_workbook()
         logger.info(f"{self.wb.sheetnames}")
+        logger.info(f"{self.wb.worksheets}")
 
     def _prepare_workbook(self):
         """准备工作簿"""
@@ -37,8 +38,10 @@ class ExcelFileManager:
         self.wb.save(self.output_path)
         self.wb.close()
     
-    def write_competie_sheet(self, sheet_name: str = "竞品关键词调研", sheet_index: int = 0):
-        if not sheet_name in self.wb.worksheets:
+    def write_competie_sheet(self, sheet_name: str = "竞品关键词调研", sheet_index: int = 0, overwrite: bool = False):
+        if overwrite and sheet_name in self.wb.sheetnames:
+            self.wb.remove(self.wb[sheet_name])
+        if sheet_name not in self.wb.sheetnames:
             extract_data = self.load_s3_extract_data()
             competitive_sheet_writer = CompetitiveAnalysisWriter(self.wb, sheet_name=sheet_name, sheet_index=sheet_index)
             competitive_sheet_writer.add_data(extract_data)

+ 5 - 3
src/excel_tools/writers/competitive_analysis.py

@@ -159,12 +159,14 @@ class CompetitiveAnalysisWriter(ExcelWriterBase):
         start_row = self.max_data_rows + 3  # 间隔3行
         
         # 产品信息
-        self.ws.cell(start_row, self.current_col, "产品信息").font = Font(bold=True)
+        product_title_cell = self.ws.cell(start_row, self.current_col, "产品信息")
+        product_title_cell.font = Font(bold=True)
         # 从product_info提取实际存在的字段
         info_text = processor.product_info.get('main_text', '')
-        if processor.product_info.get('goto_amazon'):
-            info_text += f"\n产品链接: {processor.product_info['goto_amazon']}"
         info_cell = self.ws.cell(start_row+1, self.current_col, info_text)
+        if processor.product_info.get('goto_amazon'):
+            product_title_cell.hyperlink = processor.product_info['goto_amazon']
+            product_title_cell.font = Font(color='0000FF', underline='single')  # 添加超链接样式
         info_cell.alignment = Alignment(wrap_text=True, vertical='top')
         self.ws.column_dimensions[get_column_letter(self.current_col)].width = 35