Hello,
Im converting an simple vba script to onlyoffice api.
Now I have the problem that I can’t add up two values correctly, it’s always just expanded like a string.
The first value is the value of the column above the current row, the second is simple +1.
This is my current Code:
`(function ()
{
function formatDate(d) {
var month = ‘’ + (d.getMonth() + 1),
day = ‘’ + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [day, month, year].join('.');
}
var currentDate = formatDate(new Date());
// Getting the active sheet
var activeSheet = Api.ActiveSheet;
// Minimum row index
var indexRowMin = 0;
// Maximum row index
var indexRowMax = 1048576;
// Column 'A'
var indexCol = 0;
// Row index for empty cell search
var indexRow = indexRowMax;
for (; indexRow >= indexRowMin; --indexRow) {
// Getting the cell
var range = activeSheet.GetRangeByNumber(indexRow, indexCol);
// Checking the value
if (range.GetValue() && indexRow !== indexRowMax) {
range = activeSheet.GetRangeByNumber(indexRow + 1, indexCol);
range.Select();
range.GetCells(1, 1).SetValue(range.GetCells(-1, 1).GetValue() + 1)
range.GetCells(1, 2).SetValue(currentDate)
break;
}
}
})();`
The Result:
I just want to have a simple ascending number row, but it needs to be added by an macro (button).
Thank you for the help in advance.
Erik