Ask Your Question
1

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

asked 2019-11-13 11:55:48 +0200

lonk gravatar image

updated 2019-11-13 12:02:25 +0200

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 |

image description

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2019-11-13 13:25:24 +0200

updated 2019-11-14 06:57:13 +0200

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)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-11-13 11:55:48 +0200

Seen: 59 times

Last updated: Nov 14 '19