瀏覽代碼

优化表格显示逻辑,增加超宽表格列数阈值配置

zhch158_admin 1 月之前
父節點
當前提交
0d50311967
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      streamlit_ocr_validator.py

+ 4 - 3
streamlit_ocr_validator.py

@@ -184,6 +184,7 @@ class StreamlitOCRValidator:
     def display_html_table_as_dataframe(self, html_content: str, enable_editing: bool = False):
         """将HTML表格解析为DataFrame显示 - 增强版本支持横向滚动"""
         tables = parse_html_tables(html_content)
+        wide_table_threshold = 15  # 超宽表格列数阈值
         
         if not tables:
             st.warning("未找到可解析的表格")
@@ -228,7 +229,7 @@ class StreamlitOCRValidator:
                 st.metric("列数", len(table.columns))
             with col_info3:
                 # 检查是否有超宽表格
-                is_wide_table = len(table.columns) > 8
+                is_wide_table = len(table.columns) > wide_table_threshold
                 st.metric("表格类型", "超宽表格" if is_wide_table else "普通表格")
             with col_info4:
                 # 表格操作模式选择
@@ -294,7 +295,7 @@ class StreamlitOCRValidator:
             """, unsafe_allow_html=True)
             
             # 根据表格宽度选择显示容器
-            container_class = "wide-table-container" if len(table.columns) > 8 else "dataframe-container"
+            container_class = "wide-table-container" if len(table.columns) > wide_table_threshold else "dataframe-container"
             
             if enable_editing:
                 st.markdown(f'<div class="{container_class}">', unsafe_allow_html=True)
@@ -313,7 +314,7 @@ class StreamlitOCRValidator:
                 st.dataframe(
                     filtered_table, 
                     # use_container_width=True,
-                    width =400 if len(table.columns) > 8 else "stretch"
+                    width =400 if len(table.columns) > wide_table_threshold else "stretch"
                 )
                 st.markdown('</div>', unsafe_allow_html=True)