setDateTime method
Set DateTime value to the range.
Workbook workbook = new Workbook();
Worksheet sheet = workbook.worksheets[0];
Range range = sheet.getRangeByName('A1');
range.setDateTime(DateTime(2011, 1, 20, 20, 37, 80));
List<int> bytes = workbook.saveAsStream();
File('DateTime.xlsx').writeAsBytes(bytes);
workbook.dispose();
Implementation
void setDateTime(DateTime? dateTime) {
if (dateTime != null) {
if (_cellStyle == null) {
_cellStyle = CellStyle(workbook);
_cellStyle!.numberFormatIndex = 14;
}
if (isSingleRange) {
_number = _toOADate(dateTime);
_dateTime = dateTime;
type = CellType.dateTime;
_cellStyle = _cellStyle;
_saveType = 'n';
_setRange();
} else {
// ignore: prefer_final_locals
for (int iRow = row, iLastRow = lastRow; iRow <= iLastRow; iRow++) {
// ignore: prefer_final_locals
for (int iCol = column, iLastCol = lastColumn;
iCol <= iLastCol;
iCol++) {
worksheet.getRangeByIndex(iRow, iCol).dateTime = dateTime;
}
}
}
}
}