add read excel file

dev
FrozenArcher 2024-03-14 20:25:45 +08:00
parent 7ee06b9901
commit 3187c7be28
6 changed files with 145 additions and 3 deletions

98
package-lock.json generated
View File

@ -8,6 +8,7 @@
"name": "notify-admin", "name": "notify-admin",
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"@ant-design/icons": "^5.3.1",
"@types/node": "^16.18.88", "@types/node": "^16.18.88",
"@types/react": "^18.2.65", "@types/react": "^18.2.65",
"@types/react-dom": "^18.2.21", "@types/react-dom": "^18.2.21",
@ -16,7 +17,8 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-router-dom": "^6.22.3", "react-router-dom": "^6.22.3",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"typescript": "^4.9.5" "typescript": "^4.9.5",
"xlsx": "^0.18.5"
}, },
"devDependencies": { "devDependencies": {
"eslint-plugin-prettier": "^5.1.3", "eslint-plugin-prettier": "^5.1.3",
@ -4485,6 +4487,14 @@
"node": ">=8.9" "node": ">=8.9"
} }
}, },
"node_modules/adler-32": {
"version": "1.3.1",
"resolved": "https://registry.npmmirror.com/adler-32/-/adler-32-1.3.1.tgz",
"integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/agent-base": { "node_modules/agent-base": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmmirror.com/agent-base/-/agent-base-6.0.2.tgz", "resolved": "https://registry.npmmirror.com/agent-base/-/agent-base-6.0.2.tgz",
@ -5516,6 +5526,18 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/cfb": {
"version": "1.2.2",
"resolved": "https://registry.npmmirror.com/cfb/-/cfb-1.2.2.tgz",
"integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==",
"dependencies": {
"adler-32": "~1.3.0",
"crc-32": "~1.2.0"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/chalk": { "node_modules/chalk": {
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmmirror.com/chalk/-/chalk-2.4.2.tgz",
@ -5747,6 +5769,14 @@
"node": ">= 4.0" "node": ">= 4.0"
} }
}, },
"node_modules/codepage": {
"version": "1.15.0",
"resolved": "https://registry.npmmirror.com/codepage/-/codepage-1.15.0.tgz",
"integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/collect-v8-coverage": { "node_modules/collect-v8-coverage": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmmirror.com/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", "resolved": "https://registry.npmmirror.com/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz",
@ -5961,6 +5991,17 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/crc-32": {
"version": "1.2.2",
"resolved": "https://registry.npmmirror.com/crc-32/-/crc-32-1.2.2.tgz",
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
"bin": {
"crc32": "bin/crc32.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.3.tgz", "resolved": "https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.3.tgz",
@ -8162,6 +8203,14 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/frac": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/frac/-/frac-1.1.2.tgz",
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/fraction.js": { "node_modules/fraction.js": {
"version": "4.3.7", "version": "4.3.7",
"resolved": "https://registry.npmmirror.com/fraction.js/-/fraction.js-4.3.7.tgz", "resolved": "https://registry.npmmirror.com/fraction.js/-/fraction.js-4.3.7.tgz",
@ -16063,6 +16112,17 @@
"resolved": "https://registry.npmmirror.com/sprintf-js/-/sprintf-js-1.0.3.tgz", "resolved": "https://registry.npmmirror.com/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g=="
}, },
"node_modules/ssf": {
"version": "0.11.2",
"resolved": "https://registry.npmmirror.com/ssf/-/ssf-0.11.2.tgz",
"integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==",
"dependencies": {
"frac": "~1.1.2"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/stable": { "node_modules/stable": {
"version": "0.1.8", "version": "0.1.8",
"resolved": "https://registry.npmmirror.com/stable/-/stable-0.1.8.tgz", "resolved": "https://registry.npmmirror.com/stable/-/stable-0.1.8.tgz",
@ -18014,6 +18074,22 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/wmf": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/wmf/-/wmf-1.0.2.tgz",
"integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/word": {
"version": "0.3.0",
"resolved": "https://registry.npmmirror.com/word/-/word-0.3.0.tgz",
"integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/word-wrap": { "node_modules/word-wrap": {
"version": "1.2.5", "version": "1.2.5",
"resolved": "https://registry.npmmirror.com/word-wrap/-/word-wrap-1.2.5.tgz", "resolved": "https://registry.npmmirror.com/word-wrap/-/word-wrap-1.2.5.tgz",
@ -18431,6 +18507,26 @@
} }
} }
}, },
"node_modules/xlsx": {
"version": "0.18.5",
"resolved": "https://registry.npmmirror.com/xlsx/-/xlsx-0.18.5.tgz",
"integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==",
"dependencies": {
"adler-32": "~1.3.0",
"cfb": "~1.2.1",
"codepage": "~1.15.0",
"crc-32": "~1.2.1",
"ssf": "~0.11.2",
"wmf": "~1.0.1",
"word": "~0.3.0"
},
"bin": {
"xlsx": "bin/xlsx.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/xml-name-validator": { "node_modules/xml-name-validator": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmmirror.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "resolved": "https://registry.npmmirror.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz",

View File

@ -6,6 +6,7 @@
"name": "EVA Tech" "name": "EVA Tech"
}, },
"dependencies": { "dependencies": {
"@ant-design/icons": "^5.3.1",
"@types/node": "^16.18.88", "@types/node": "^16.18.88",
"@types/react": "^18.2.65", "@types/react": "^18.2.65",
"@types/react-dom": "^18.2.21", "@types/react-dom": "^18.2.21",
@ -14,7 +15,8 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-router-dom": "^6.22.3", "react-router-dom": "^6.22.3",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"typescript": "^4.9.5" "typescript": "^4.9.5",
"xlsx": "^0.18.5"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@ -0,0 +1,24 @@
import { Button, Upload } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import { FC } from 'react';
import { readExcelFile } from '../utils/excel';
const DutyTablePage: FC = () => {
return (
<Upload
name='file'
action=''
beforeUpload={(file) => {
let data = readExcelFile(file, 0);
data
.then((d) => console.log('read data', d))
.catch((e) => console.log('got error', e));
return false;
}}
>
<Button icon={<UploadOutlined />} />
</Upload>
);
};
export default DutyTablePage;

View File

@ -1,5 +1,6 @@
import { Routes, Route } from 'react-router-dom'; import { Routes, Route } from 'react-router-dom';
import Todo from './components/Todo'; import Todo from './components/Todo';
import DutyTablePage from './pages/DutyTable';
export const routes = { export const routes = {
main: '/', main: '/',
@ -25,7 +26,7 @@ export const AppRouter: React.FC = () => {
return ( return (
<Routes> <Routes>
<Route path={routes.main} element={<Todo />} /> <Route path={routes.main} element={<Todo />} />
<Route path={routes.admin.dutyTable} element={<Todo />} /> <Route path={routes.admin.dutyTable} element={<DutyTablePage />} />
<Route path={routes.admin.userControl} element={<Todo />} /> <Route path={routes.admin.userControl} element={<Todo />} />
<Route path={routes.admin.dutyInfo} element={<Todo />} /> <Route path={routes.admin.dutyInfo} element={<Todo />} />
<Route path='/duty/hi1' element={<Todo />} /> <Route path='/duty/hi1' element={<Todo />} />

10
src/utils/excel.ts 100644
View File

@ -0,0 +1,10 @@
import { read as xlsxRead, utils as xlsxUtils } from 'xlsx';
import { readFile } from './readfile';
export async function readExcelFile(file: File, sheetIndex: number) {
let data = await readFile(file);
let workbook = xlsxRead(data, { type: 'binary' });
let worksheet = workbook.Sheets[workbook.SheetNames[sheetIndex]];
data = xlsxUtils.sheet_to_json(worksheet);
return data;
}

View File

@ -0,0 +1,9 @@
export function readFile(file: File) {
return new Promise((resolve) => {
let reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = (ev) => {
resolve(ev.target?.result);
};
});
}