Sets the value of the cell to the provided date time string.
If the date string is valid and falls after 1900-01-00 00:00:00, it will be converted and set as a date-type cell value.
Otherwise, the date is formatted as a string value in the format "yyyy-MM-dd hh:mm:ss" in the cell.
If you want to apply a different date format to the cell, you can use Core.SpreadsheetEditor.CellStyle#setDataFormatString with Core.SpreadsheetEditor.Cell#setStyle to apply the new format.
Parameters:
Name |
Type |
Description |
date |
string
|
A string representing a date in the format "yyyy-MM-dd hh:mm:ss" |
- See:
-
Example
WebViewerConstructor({
initialMode: WebViewer.Modes.SPREADSHEET_EDITOR, // ensure WebViewer starting in spreadsheet editor
...
}, ...)
.then((instance) => {
const { documentViewer, SpreadsheetEditor } = instance.Core;
const spreadsheetEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
spreadsheetEditorManager.addEventListener(spreadsheetEvents.SPREADSHEET_EDITOR_READY, () => {
spreadsheetEditorManager.setEditMode('editing');
const datetimeString = '2023-10-01 06:00:00';
const spreadsheetEditorDocument = instance.Core.documentViewer.getDocument().getSpreadsheetEditorDocument();
const cell = spreadsheetEditorDocument.getWorkbook().getSheetAt(0).getRowAt(0).getCellAt(0);
cell.setCellDateValue(datetimeString);
// To apply a different date format to the cell
const cellStyle = cell.getStyle();
cellStyle.setDataFormatString('MM/dd/yyyy');
cell.setStyle(cellStyle);
});
});