A React component to preview document of 'pdf,xls,xlsx,docx', which can automatically identify file types.
npm install react-office-viewer
npm install react-office-viewer
`
`
import Viewer from "react-office-viewer"
//If you only want to preview a certain format, you can import them individually.
import { SheetViewer, PdfViewer, DocxViewer } from "react-office-viewer"
`
Params
`
// Pass a url that can get the file stream.
// Or, pass a File Object.
getFileObject = e => {
this.setState({ fileObject: e.target.files[0] });
}
//other optional params:
let params = {
fileName, //PropTypes.string
locale: 'en', // PropTypes.oneOf(['zh','en'])
width, //PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
height, //PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
timeout: 10000, //PropTypes.number. Timeout limit of url request, only works on sheet/docx previewer.
}
``