show the code

前提:需要mammoth包~

import React, { useState, useReducer } from 'react';
import { Button, Alert, Table, Badge, Input, Upload } from 'antd';
import CommonTable from '@cps/CommonTable';
import styles from './receive.less';
import { UploadOutlined } from '@ant-design/icons';
import mammoth from 'mammoth';
function reducer(state: any, action: any) {
return {
...state,
...action.data
};
} const NovelAnalyze = () => {
const [state, dispatch] = useReducer(reducer, {
content: ''
});
const getTextInfo = (file: any) => {
const reader = new FileReader();
reader.readAsText(file, 'gb2312');
reader.onload = (result: any) => {
console.log(result);
let targetNum = result.target.result;
console.log(targetNum);
};
return false;
};
const getWordInfo = (file: any) => {
const reader = new FileReader();
reader.onload = function(loadEvent: any) {
const arrayBuffer = loadEvent.target['result'];
mammoth
.extractRawText({ arrayBuffer: arrayBuffer })
.then(function(resultObject) {
console.log('extractRawText', resultObject.value);
})
.done();
};
reader.readAsArrayBuffer(file);
return false;
}; return (
<div>
<ul className={styles.optionBtnList}>
<li>
<Button type='primary'>导出</Button>
<Upload action='' accept='text/plain' beforeUpload={getTextInfo} showUploadList={false}>
<Button>
<UploadOutlined />
上传txt文件
</Button>
</Upload>
<Upload
action=''
accept='.doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document'
beforeUpload={getWordInfo}
showUploadList={false}
>
<Button>
<UploadOutlined />
上传word文件
</Button>
</Upload>
<Button type='primary'>导入word</Button>
</li>
</ul>
</div>
);
}; export default NovelAnalyze;

正则分割段落

原文:

第259章 这是259内容 第262章 这是262内容 第666章 测试内容

str.replace(/\s*(第\d+章)\s*/g, "@@@$1___").split("@@@").filter(item => item).map(item => ({[item.split("___")[0]]: item.split("___")[1]}))

结果:

0: {第259章: "这是259内容"}
1: {第262章: "这是262内容"}
2: {第666章: "测试内容"}

js 读取word和txt(react版) + 正则分割段落的更多相关文章

  1. js读取修改创建txt文本类型文件(.ini)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. js读取本地json/txt/xml存在跨越问题,可以用jsonp 读取本地json文件

    想自己用 js写一个原生的ajax请求,访问本地文件,json/txt.但是demo,写了一个后,发现 原来是跨域了. js 写的原生ajax 请求代码如下 html代码 <div id=&qu ...

  3. js读取文本内容,支持csv.txt

    js读取文本内容,支持csv.txt <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  4. ZK中使用JS读取客户端txt文件内容问题

    最近写一个需求时遇到一个问题,用户需要通过点击一个按钮直接读取他自己电脑上D盘的一个txt文件内容显示到页面,因为项目现在是用ZK写的.我对于ZK也是刚刚了解不就,很多都还不是很熟.起初我是想用io流 ...

  5. POI 读取word (word 2003 和 word 2007) (转)

    最近在给客户做系统的时候,用户提出需求,要能够导入 word 文件,现在 microsoft word 有好几个版本 97.2003.2007的,这三个版本存储数据的格式上都有相当大的差别,而现在 9 ...

  6. php 如何写入、读取word,excel文档

    如何在php写入.读取word文档 <? //如何在php写入.读取word文档 // 建立一个指向新COM组件的索引 $word = new COM("word.applicatio ...

  7. word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得

    word和.txt文件转html 及pdf文件, 使用poi jsoup  itext心得本人第一次写博客,有上面不足的或者需要改正的希望大家指出来,一起学习交流讨论.由于在项目中遇到了这一个问题,在 ...

  8. 使用新一代js模板引擎NornJ提升React.js开发体验

    当前的前端世界中有很多著名的开源javascript模板引擎如Handlebars.Nunjucks.EJS等等,相信很多人对它们都并不陌生. js模板引擎的现状 通常来讲,这些js模板引擎项目都有一 ...

  9. C# 添加、读取Word脚注尾注

    脚注和尾注是对文本的补充说明.脚注一般位于页面的底部,可以作为文档某处内容的注释:尾注一般位于文档的末尾,列出引文 的出处等.在本示例中将介绍如何来添加或删除Word脚注. 工具使用:Free Spi ...

随机推荐

  1. HDU 4143 A Simple Problem 题解

    题目 For a given positive integer n, please find the saallest positive integer x that we can find an i ...

  2. 「疫期集训day4」硝烟

    那真是一阵恐怖的炮击(that boomed booms),响亮的炮音(that noise),滚滚的硝烟(that smoke),熊熊的火焰在围绕着我们前进...小心前进(go and be car ...

  3. NOI 2003 逃学的小孩 (树的直径)

    [NOI2003 逃学的小孩] 题目描述 Chris家的电话铃响起了,里面传出了Chris的老师焦急的声音:"喂,是Chris的家长吗?你们的孩子又没来上课,不想参加考试了吗?"一 ...

  4. gulp-less打包后calc属性计算不准确的问题

    .step-item{ width: calc((100% - 50px) / 2); &:nth-child(2){ margin-right: 0; } } 这样直接写的话,编译时会直接给 ...

  5. 解决nginx 出现 413:Request Entity Too Large

    去网上搜了一下,说是上传文件大小超过nginx的限制大小(nginx据说默认只能上传不超过2MB的文件) 解决方法: #nginx/conf/nginx.conf http { ... client_ ...

  6. scrapy(三):post请求

    -- coding: utf-8 -- ''' QiuBai.py 爬虫文件 ''' -- coding: utf-8 -- import scrapy class PostSpider(scrapy ...

  7. 数据可视化之DAX篇(十九)值得你深入了解的函数:SUMMARIZE

    https://zhuanlan.zhihu.com/p/66424209 SUMMARIZE函数非常强大,掌握以后表面上看也非常好用,所以我专门写篇文章介绍一下这个函数,至于是否一定要使用该函数,请 ...

  8. linux专题(九):磁盘管理

    http://dwz.date/UDf 概述 Linux磁盘管理好坏直接关系到整个系统的性能问题. Linux磁盘管理常用命令为 df.du. df :列出文件系统的整体磁盘使用量 du:检查磁盘空间 ...

  9. 软件测试中的微信小程序怎么测试?

    1.没有需求文档时,如何测试小程序?现在大多数公司的开发模式是:敏捷模式(用户故事) ,即以什么身份做什么事情会出现什么样的结果.那实际测试过程中,没有需求文档时,测试可以采用以下方式更好的完成测试工 ...

  10. python环境搭建及配置

    我选择的是pycharm,这个对新手比较友好 我目前正在自学周志华的西瓜书,在做练习题3.3时需要用到python来实现,做这个练习需要numpy库和matplot库,最开始的时候忘了anaconda ...