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