当前位置:网站首页>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
}
边栏推荐
- Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
- 2022-08-01 网工进阶(二十四) STP进阶知识
- iwemeta元宇宙:一个娃娃卖9999元,泡泡玛特认为一点也不贵
- 神经网络的三种训练方法,神经网络训练全过程
- 上课笔记(7)(1)——#647. 找树根和孩子(root)
- How AliExpress sellers seize product search weight
- Rust learning: 6.3_ Tuples of composite types
- 第十六天&charles的基本操作
- ATH10 sensor reads temperature and humidity
- PLSQL学习第一天
猜你喜欢
【NeRF】原始论文解读
Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training
A File Online Query Display and Download Function Realized by Delphi
navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server
每日一题,数组字符串的匹配问题
速卖通卖家如何抓住产品搜索权重
TensorFlow 2.9的零零碎碎(一)
同步锁synchronized追本溯源
【一起学Rust | 进阶篇 | RMQTT库】RMQTT消息服务器——安装与集群配置
Synchronization lock synchronized traces the source
随机推荐
PLSQL学习第三天
自动化测试框架Pytest(三)——自定义allure测试报告
神经网络样本太少怎么办,神经网络训练样本太少
The sixteenth day & the basic operation of charles
UGUI - Events, iTween Plugin
phpstudy开机自启
Unity—UGUI控件
NPU architecture and force analysis
90.(cesium之家)cesium高度监听事件
Summary of ctfshow SSTI knowledge points
关于数据中心的设计方案,数据中心网络规划设计
[机缘参悟-65]:《兵者,诡道也》-7-三十六计解读-败战计
菜鸟、小白在autojs和冰狐智能辅助之间如何选择?
人工神经网络工作原理,神经网络的工作原理
解决win10win7win8系统找不到指定的模块,注册不了大漠插件的问题
第十六天&charles的基本操作
Ask next CDC mysql to Doris. Don't show the specific number of lines, how to do?
编程老手如何在autojs和冰狐智能辅助之间选择?
【Unity入门计划】Collision2D类&Collider2D类
初使jest 单元测试