首页 > 解决方案 > 在反应中读取/显示excel文件

问题描述

我想上传一个 excel 文件,然后首先将其所有内容显示为文本。目前,文本的格式并不重要。我正在使用 dropzone 库上传文件。该text参数是我要保存文件的文本/内容的位置。但是,目前,它给了我一个错误

Uncaught Error: Objects are not valid as a React child (found: object with keys {file, meta, cancel, remove, restart, xhr}). If you meant to render a collection of children, use an array instead.

所以,我不确定我可以在哪里处理文件的内容并使用saveText钩子保存它。我应该尝试什么?

export function Page() {
  const [text, setText] = useState<any>('hello');

  const getUploadParams = ({ meta }: any) => { return { url: 'https://httpbin.org/post' } }

  const handleChangeStatus = ({ meta, file }: any, status: any) => { console.log(status, meta, file) }

  const handleSubmit = (files: any[], allFiles: any[]) => {
    //console.log(files.map(f => f.meta))
    setText(files)
    console.log('TEXT', text)
  }

  return (
    <div>
      <main className={classes.content}>
        <Dropzone
          getUploadParams={getUploadParams}
          onChangeStatus={handleChangeStatus}
          onSubmit={handleSubmit}
        />
        {text}
        <div>
        </div>
      </main>
    </div>
  );
}

标签: javascriptreactjstypescriptreact-hooksdropzone.js

解决方案


推荐阅读