当前位置:网站首页>js读取excel时间格式转换
js读取excel时间格式转换
2022-08-10 08:22:00 【cc&】
使用xlsx.full.min.js 获取excel的日期数据为:37858;
拿到的整数值是日期距离1900年1月1日的天数,这时需要写一个函数转换:
/**
* excel导入插件方法:excel时间格式化
* @param {*} numb excel时间格式
* @param {*} format 转换分隔符
* @returns 标准时间格式
*/
export function formatExcelDate(numb, format) {
// 天数
const 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() + ''
// 转换的格式符号
if (format && format.length === 1) {
return new Date(year + format + month + format + date)
}
return (
year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
)
}参数:numb是excel转换出来的整数值,format是年月日之间分隔符号。
将excel表格中的中文替换英文
/**
* excel导入插件方法:key中文转英文
* @param {*} results 需要转换的数据
* @param {*} maps 转换数据的中英映射关系
* @param {*} times 需要格式化的excel时间属性名
* @returns
*/
export function transformKeys(results, maps, times = []) {
const newArr = []
results.forEach((item) => {
// 替换为key是英文的新对象,添加进数组
const _item = {}
for (const key in item) {
const enKey = maps[key]
if (times.includes(enKey)) {
// 格式化excel时间
_item[enKey] = formatExcelDate(item[key], '-')
} else {
_item[enKey] = item[key]
}
}
newArr.push(_item)
})
return newArr
}
边栏推荐
- 【Rust指南】使用Cargo工具高效创建Rust项目 | 理解Rust特别的输入输出语句
- SQL建表问题,帮我看看好吗朋友们~大家人。!
- Day36 LeetCode
- Add spark related dependencies and packaging plugins (sixth bullet)
- 时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)
- phpstudy开机自启
- Johnson全源最短路
- VS2013-debug assembly code-generate asm file-structure memory layout-function parameter stack-calling convention
- 自动化测试框架Pytest(二)——前后置处理
- Uni applet Tencent map polygon background transparency
猜你喜欢

iwemeta元宇宙:一个娃娃卖9999元,泡泡玛特认为一点也不贵

时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)

Uni-app开发微信小程序使用本地图片做背景图

js函数聚合的三种实现方式

ABAP Data Types 和XSD Type 映射关系以及XSD Type属性

UGUI - Events, iTween Plugin

解决win10win7win8系统找不到指定的模块,注册不了大漠插件的问题

2022-08-01 Advanced Network Engineering (24) STP Advanced Knowledge

Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in

PLSQL学习第二天
随机推荐
If the data of the oracle business table is added, deleted, or modified, will the index of the table write redo and undo?
如何设计神经网络结构,神经网络设计与实现
【一起学Rust | 进阶篇 | RMQTT库】RMQTT消息服务器——安装与集群配置
解决win10win7win8系统找不到指定的模块,注册不了大漠插件的问题
uni 小程序腾讯地图polygon背景透明度
[机缘参悟-65]:《兵者,诡道也》-7-三十六计解读-败战计
Using the color picker
CV-人脸识别-2018:ArcFace
Process management (dynamic)
DGIOT 30 million meters set pressure reading
The implementation of the seemingly useless component (text gradient) in NaiveUI is so simple
每日一题,二叉树中增加一行
自动化测试框架Pytest(三)——自定义allure测试报告
模糊查询除了like+ % 还能用什么方式
nrm 使用详解
TensorFlow 2.9的零零碎碎(一)
每日一题,数组字符串的匹配问题
Introduction to the delta method
2022-08-01 Advanced Network Engineering (24) STP Advanced Knowledge
90. (cesium house) cesium height monitoring events