当前位置:网站首页>js reads excel time format conversion
js reads excel time format conversion
2022-08-10 08:29:00 【cc &】
Use xlsx.full.min.js to get the date data of excel: 37858;
The integer value obtained is the number of days from the date to January 1, 1900. At this time, a function needs to be written to convert:
/*** Excel import plug-in method: excel time formatting* @param {*} numb excel time format* @param {*} format conversion delimiter* @returns standard time format*/export function formatExcelDate(numb, format) {// daysconst time = new Date((numb - 1) * 24 * 3600000 + 1)console.log(time)time.setYear(time.getFullYear() - 70)const year = time.getFullYear() + ''const month = time.getMonth() + 1 + ''const date = time.getDate() + ''// Converted format symbolif (format && format.length === 1) {return new Date(year + format + month + format + date)}return (year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date))}
Parameter: numb is the integer value converted by excel, format is the separator between the year, month and day.
Replace Chinese in excel sheet with English
/*** Excel import plug-in method: key Chinese to English* @param {*} results data to be converted* @param {*} maps Chinese-English mapping relationship of converted data* @param {*} times the excel time attribute name that needs to be formatted* @returns*/export function transformKeys(results, maps, times = []) {const newArr = []results.forEach((item) => {// Replace with a new object whose key is English and add it to the arrayconst _item = {}for (const key in item) {const enKey = maps[key]if (times.includes(enKey)) {// format excel time_item[enKey] = formatExcelDate(item[key], '-')} else {_item[enKey] = item[key]}}newArr.push(_item)})return newArr}
边栏推荐
猜你喜欢
Delphi实现的一个文件在线查询显示下载功能
PHP笔记 28 29 30 31
【NeRF】原始论文解读
【OAuth2】二十、OAuth2扩展协议 PKCE
同步锁synchronized追本溯源
The sixteenth day & the basic operation of charles
How AliExpress sellers seize product search weight
The implementation of the seemingly useless component (text gradient) in NaiveUI is so simple
UGUI - Events, iTween Plugin
Uni-app develops WeChat applet using local images as background images
随机推荐
Obtain - 65 [chances] : "soldiers, subtlety also - 7-36 meter reading - defeat
爬虫-爬取某小说网站
placeholder 1
js-----数组转换成树形结构
Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training
协同工具满足70%-90%的工作需求,成为企业香饽饽
UGUI - Events, iTween Plugin
PHP笔记 28 29 30 31
How AliExpress sellers seize product search weight
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
Pieces of TensorFlow 2.9 (1)
【转】探秘钉钉的即时消息服务DTIM
Rust learning: 6.4_ enumeration of composite types
Rust learning: 6.2_ Tuples of composite types
NPU架构与算力分析
不同的命令行风格
Go-Excelize API源码阅读(十一)—— GetActiveSheetIndex()
初使jest 单元测试
阿里云数据库 RDS SQL Server 版的服务器绑定域名www.cxsdkt.cn.的呢?
预测股票涨跌看什么指标,如何预测明天股票走势