Commit 7519c700 by weiw

fix:处理预览excel文件的样式问题

parent 3102a879
......@@ -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>
)
}
......@@ -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>
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment