当前位置:网站首页>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}
边栏推荐
- 组合数模板
- 上课笔记(7)(1)——#647. 找树根和孩子(root)
- In the SQL SERVER database, if the data of the table is added, deleted, or modified, will the index of the table be recorded in the ldf log?
- phpstudy starts automatically
- C# 获取PCI等设备的插槽位置信息
- dayjs-----时间格式化
- Introduction to C integer data storage
- IDLE development wordCount program (5)
- day16--The use of the packet capture tool Charles
- debezium-connector-mysql拉起docker报错:debezium启动docke
猜你喜欢
A File Online Query Display and Download Function Realized by Delphi
2022-08-01 Advanced Network Engineering (24) STP Advanced Knowledge
UGUI—事件,iTween插件
详解构建mock服务最方便的神器——Moco
模糊查询除了like+ % 还能用什么方式
90.(cesium之家)cesium高度监听事件
iwemeta metaverse: a doll sells for 9999 yuan, and Bubble Mart thinks it is not expensive at all
【一起学Rust | 进阶篇 | RMQTT库】RMQTT消息服务器——安装与集群配置
AFNetworking概述和4.0的实践
NaiveUI中看起来没啥用的组件(文字渐变)实现原来这么简单
随机推荐
同步锁synchronized追本溯源
Unity—UGUI控件
The sixteenth day & the basic operation of charles
预测股票涨跌看什么指标,如何预测明天股票走势
Johnson全源最短路
【微信小程序】一文读懂页面导航
The precise effect of network integration promotion outsourcing in the era of Internet of Things-Shenzhen Win-Win World News
Rust学习:6.2_复合类型之元组
2022-08-01 Advanced Network Engineering (24) STP Advanced Knowledge
物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
QT下载清华源配置
第十六天&charles的基本操作
VS2013-调试汇编代码-生成asm文件-结构体内存布局-函数参数压栈-调用约定
Uni applet Tencent map polygon background transparency
硬件工程师90天学习资料及笔记汇总20220730
Class Notes (7) (1) - #647. Find the root and the child (root)
基于sklearn的决策树应用实战
Go-Excelize API source code reading (11) - GetActiveSheetIndex()
Uni-app develops WeChat applet using local images as background images
phpstudy starts automatically