当前位置:网站首页>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}边栏推荐
猜你喜欢

DGIOT supports industrial equipment rental and remote control

Rust learning: 6.1_Slices of composite types

Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training

ARM结构体系3:ARM指令的寻址和异常中断处理

day16--抓包工具Charles的使用

【Unity入门计划】制作RubyAdventure03-使用碰撞体&触发器实现世界交互

How AliExpress sellers seize product search weight

PHP笔记 28 29 30 31

mySQL增删改查进阶

Quickly enter the current date and time
随机推荐
NPU架构与算力分析
机器人控制器编程实践指导书旧版-实践一 LED灯(数字量)
Rust学习:6.1_复合类型之切片
The sixteenth day & the basic operation of charles
明明加了唯一索引,为什么还是产生重复数据?
ShardingSphere入门
Add spark related dependencies and packaging plugins (sixth bullet)
初使jest 单元测试
解决win10win7win8系统找不到指定的模块,注册不了大漠插件的问题
.NET-7.WPF learning experience summary
Rust学习:6.5_复合类型之数组
Process management (dynamic)
CV+Deep Learning - network architecture Pytorch recurrence series - classification (3: MobileNet, ShuffleNet)
Rust学习:6.4_复合类型之枚举
UGUI - Events, iTween Plugin
第十六天&charles的基本操作
协同工具满足70%-90%的工作需求,成为企业香饽饽
day16--抓包工具Charles的使用
2022-08-01 网工进阶(二十三) VLAN高级技术-VLAN聚合、MUX VLAN
如何远程调试对方的H5页面