From a7fd657c82d9fc290f671b1d9f74e169daaee7c0 Mon Sep 17 00:00:00 2001 From: dojyorin Date: Thu, 1 Feb 2024 19:41:24 +0900 Subject: [PATCH] update date and excel. --- src/pure/time.ts | 6 ++++-- src/pure_ext/excel.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pure/time.ts b/src/pure/time.ts index da43da1..e86e1c8 100644 --- a/src/pure/time.ts +++ b/src/pure/time.ts @@ -63,8 +63,10 @@ export async function delay(time:number):Promise{ * const format = dtSerial(); * ``` */ -export function dtSerial(date?:Date):string{ +export function dtSerial(date?:Date, split?:boolean):string{ const d = date ?? new Date(); + const ss = split ? "/" : ""; + const sc = split ? ":" : ""; - return `${d.getFullYear()}${pad0(d.getMonth() + 1)}${pad0(d.getDate())}${pad0(d.getHours())}${pad0(d.getMinutes())}${pad0(d.getSeconds())}`; + return `${d.getFullYear()}${ss}${pad0(d.getMonth() + 1)}${ss}${pad0(d.getDate())}${split ? " " : ""}${pad0(d.getHours())}${sc}${pad0(d.getMinutes())}${sc}${pad0(d.getSeconds())}`; } \ No newline at end of file diff --git a/src/pure_ext/excel.ts b/src/pure_ext/excel.ts index c12c65c..8d3a4de 100644 --- a/src/pure_ext/excel.ts +++ b/src/pure_ext/excel.ts @@ -1,5 +1,6 @@ import {type RawWorkBook, type RawWorkSheet, type RawWorkCell, xlsxcp, set_cptable, xlsxRead, xlsxWrite, xlsxUtil} from "../../deps.pure_ext.ts"; import {deepClone} from "../pure/deep.ts"; +import {dtSerial} from "../pure/time.ts"; export type {RawWorkBook, RawWorkSheet, RawWorkCell}; @@ -19,6 +20,8 @@ export function excelEncodeRaw(book:RawWorkBook, cp?:number, pw?:string):Uint8Ar const buf = xlsxWrite(book, { type: "array", compression: true, + cellStyles: true, + cellDates: true, codepage: cp, password: pw }); @@ -81,6 +84,8 @@ export function excelDecodeRaw(data:Uint8Array, cp?:number, pw?:string):RawWorkB type: "array", dense: true, raw: true, + cellStyles: true, + cellDates: true, codepage: cp, password: pw }); @@ -107,7 +112,16 @@ export function excelDecode(data:Uint8Array, cp?:number, pw?:string):Recordrow ?? []){ - columns.push(!column || column.t === "e" ? "" : column.w ?? ""); + if(!column || column.t === "e" || column.v === undefined){ + columns.push(""); + } + else if(column.v instanceof Date){ + column.v.setMinutes(new Date().getTimezoneOffset()); + columns.push(dtSerial(column.v, true)); + } + else{ + columns.push(`${column.v}`); + } } rows.push(columns);