Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
7519c700
Commit
7519c700
authored
Sep 08, 2025
by
weiw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:处理预览excel文件的样式问题
parent
3102a879
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
26 deletions
+35
-26
src/components/FilePreviewModal/ExcelPreview.tsx
+14
-9
src/components/FilePreviewModal/index.tsx
+21
-17
No files found.
src/components/FilePreviewModal/ExcelPreview.tsx
View file @
7519c700
...
...
@@ -42,11 +42,17 @@ export const ExcelPreview: React.FC<ExcelPreviewProps> = ({
editable
:
false
,
})
// 添加基本样式使表格更美观并
避免
横向滚动
// 添加基本样式使表格更美观并
支持
横向滚动
const
styledHtml
=
htmlString
.
replace
(
'<table'
,
'<table style="width: 100%; table-layout: fixed; border-collapse: collapse;"'
)
.
replace
(
/<td/g
,
'<td style="border: 1px solid #d1d5db; padding: 4px 8px; word-wrap: break-word; overflow-wrap: break-word;"'
)
.
replace
(
/<th/g
,
'<th style="border: 1px solid #d1d5db; padding: 4px 8px; background-color: #f3f4f6; font-weight: bold; word-wrap: break-word; overflow-wrap: break-word;"'
)
.
replace
(
'<table'
,
'<table style="width: auto; min-width: 100%; border-collapse: collapse;"'
)
.
replace
(
/<td/g
,
'<td style="border: 1px solid #d1d5db; padding: 4px 8px; word-wrap: break-word; overflow-wrap: break-word; white-space: nowrap;"'
,
)
.
replace
(
/<th/g
,
'<th style="border: 1px solid #d1d5db; padding: 4px 8px; background-color: #f3f4f6; font-weight: bold; word-wrap: break-word; overflow-wrap: break-word; white-space: nowrap;"'
,
)
setHtml
(
styledHtml
)
onRendered
?.()
...
...
@@ -62,11 +68,10 @@ export const ExcelPreview: React.FC<ExcelPreviewProps> = ({
},
[
src
,
options
,
onRendered
,
onError
])
return
(
<
div
className=
{
`${className} overflow-auto p-4 bg-white`
}
>
<
div
dangerouslySetInnerHTML=
{
{
__html
:
html
||
'<p>无法加载 Excel 内容</p>'
}
}
style=
{
{
minWidth
:
'100%'
}
}
/>
<
div
className=
{
`${className} flex flex-col h-full`
}
>
<
div
className=
"overflow-auto flex-grow p-4 bg-white"
>
<
div
dangerouslySetInnerHTML=
{
{
__html
:
html
||
'<p>无法加载 Excel 内容</p>'
}
}
style=
{
{
minWidth
:
'100%'
}
}
/>
</
div
>
</
div
>
)
}
src/components/FilePreviewModal/index.tsx
View file @
7519c700
...
...
@@ -115,28 +115,32 @@ export const FilePreviewModal: React.FC<FilePreviewModalProps> = ({ isOpen, onCl
case
'xls'
:
return
(
<
div
className=
"h-[70vh] max-h-[70vh] overflow-auto"
>
<
ExcelPreview
key=
{
docUrl
}
// 添加key确保组件重新挂载
src=
{
docUrl
}
options=
{
{
xls
:
true
}
}
className=
"w-full min-h-full"
onRendered=
{
handleDocumentRendered
}
onError=
{
handleDocumentError
}
/>
<
div
className=
"h-[70vh] max-h-[70vh] flex flex-col"
>
<
div
className=
"flex-grow overflow-hidden"
>
<
ExcelPreview
key=
{
docUrl
}
// 添加key确保组件重新挂载
src=
{
docUrl
}
options=
{
{
xls
:
true
}
}
className=
"h-full"
onRendered=
{
handleDocumentRendered
}
onError=
{
handleDocumentError
}
/>
</
div
>
</
div
>
)
case
'xlsx'
:
return
(
<
div
className=
"h-[70vh] max-h-[70vh] overflow-auto"
>
<
ExcelPreview
key=
{
docUrl
}
// 添加key确保组件重新挂载
src=
{
docUrl
}
className=
"w-full min-h-full"
onRendered=
{
handleDocumentRendered
}
onError=
{
handleDocumentError
}
/>
<
div
className=
"h-[70vh] max-h-[70vh] flex flex-col"
>
<
div
className=
"flex-grow overflow-hidden"
>
<
ExcelPreview
key=
{
docUrl
}
// 添加key确保组件重新挂载
src=
{
docUrl
}
className=
"h-full"
onRendered=
{
handleDocumentRendered
}
onError=
{
handleDocumentError
}
/>
</
div
>
</
div
>
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment