BASIC+Calc : The result of date calculation is in long format

From the code

.
.
oCell = ThisComponent.CurrentController.ActiveSheet.GetCellByPosition(1, 0)
.
.
.
oCell.Value = DateSerial(2019, 1, 1)
For i = 2 To 365 ' Create a calendar
     oCell = ThisComponent.CurrentController.ActiveSheet.GetCellByPosition(1, i-1)
     oCell.Formula = "=B" & (i - 1) & "+1"
Next

Around first 50 cells are in DATE format and the rest are in LONG format.

I have to use PgDn on my keyboard to move up and down, then some more cells become in DATE format but not all cells.

If I click Save menu icon, all cells refresh and display in DATE format.

Do I have to add any statement in the code ?

| LibreOffice 6.2.8.2-2 |

Hello @lonk

You can try add ThisComponent.CalculateAll at the end. And, of course, doublecheck if cells format is set to date for all the range needed. But I would advice not to iterate over all cells in the loop, but to use fillAuto() method of the CellRange object. For example:

oCell = ThisComponent.CurrentController.ActiveSheet.GetCellByPosition(1, 0)
oCell.Value = DateSerial(2019, 1, 1)
oCellsToFill = ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(1,0,1,364)
oCellsToFill.fillAuto(0,1)
1 Like