React-file-viewer 预览 xlsx、csv 文件踩坑记录

303 阅读1分钟

Q: csv,xlsx和图像的高度和宽度问题默认为96px,有什么解决方案吗?

A: 如果希望图像缩放满足尺寸要求,只需在周围的 div 中设置 height=100% 即可。

<div style={{ height: '100%' }}>
   <ReactFileViewer />
</div>

如果你根本不想缩放图像,那就有点困难了。那不得不求助于一些凌乱的 CSS 来覆盖容器的宽度和高度设置

.pg-viewer-wrapper {
    overflow-y: unset !important;
}

.photo-viewer-container {
    width: unset !important;
    height: unset !important;
}

.photo-viewer-container > img {
    width: unset !important;
    height: unset !important;
}

不过此库已经长期不进行维护了,只能用于显示预览,如果后续有其他功能的加入,建议使用xlsx