Skip to content

Commit d4d1a82

Browse files
committed
fix: resolve issue with incorrect numbers in numeric cells during copy-paste
1 parent eeef7ba commit d4d1a82

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib/Functions/handlePaste.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,21 @@ export function handlePaste(event: ClipboardEvent, state: State): State {
5050
return { ...pasteData(state, pastedRows) };
5151
}
5252

53-
function parseExcelDate(excelDate: string): Date | null {
53+
function parseExcelDate(excelDate: string): Date | null {
54+
/*
55+
Regular expression to match various date formats:
56+
- YYYY-MM-DD
57+
- MM/DD/YYYY
58+
- DD.MM.YYYY
59+
- DD-MM-YYYY
60+
- YYYY.MM.DD
61+
*/
62+
const dateRegex = /^\d{4}-\d{2}-\d{2}$|^\d{2}\/\d{2}\/\d{4}$|^\d{2}\.\d{2}\.\d{4}$|^\d{2}-\d{2}-\d{4}$|^\d{4}\.\d{2}\.\d{2}$/;
63+
64+
if (!dateRegex.test(excelDate)) {
65+
return null;
66+
}
67+
5468
const timestamp = Date.parse(excelDate);
5569
return isNaN(timestamp) ? null : new Date(timestamp);
5670
}

0 commit comments

Comments
 (0)