Skip to content

Commit b31f67c

Browse files
Merge pull request #475 from qiufeihong2018/fix/paste-date
fix:Cannot paste date value from excel to date cell #471
2 parents ceb42eb + 1c1f4bc commit b31f67c

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/lib/Components/CellRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const CellRenderer: React.FC<CellRendererProps> = ({
134134
})}
135135
>
136136
{cellTemplate.render(cellToRender, isMobile ? isInEditMode : false, onCellChanged)}
137-
{location.row.idx === 0 || (cell.type === 'header' && state.props?.enableColumnResizeOnAllHeaders)) && location.column.resizable && <ResizeColumnHandle />}
137+
{(location.row.idx === 0 || (cell.type === 'header' && state.props?.enableColumnResizeOnAllHeaders)) && location.column.resizable && <ResizeColumnHandle />}
138138
{location.column.idx === 0 && location.row.resizable && <ResizeRowHandle />}
139139
{state.enableGroupIdRender && cell?.groupId !== undefined && !(isInEditMode && isMobile) && (
140140
<span className="rg-groupId">{cell.groupId}</span>

src/lib/Functions/handlePaste.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ export function handlePaste(event: ClipboardEvent, state: State): State {
4141
.getData("text/plain")
4242
.replace(/(\r\n)$/, '')
4343
.split("\n")
44-
.map((line: string) => line.split("\t").map((t) => ({ type: "text", text: t, value: parseLocaleNumber(t) })));
44+
.map((line: string) => line.split("\t").map((t) => {
45+
const parsedDate = parseExcelDate(t);
46+
return parsedDate ? { type: "date", text: t, value: parsedDate.getTime() } : { type: "text", text: t, value: parseLocaleNumber(t) };
47+
}));
4548
}
4649
event.preventDefault();
4750
return { ...pasteData(state, pastedRows) };
4851
}
49-
52+
53+
function parseExcelDate(excelDate: string): Date | null {
54+
const timestamp = Date.parse(excelDate);
55+
return isNaN(timestamp) ? null : new Date(timestamp);
56+
}

0 commit comments

Comments
 (0)