Reputation: 45
I am trying to apply 'Fill' horizontal formatting to a cell but it is not working. I am using predefined Excel.HorizontalAlignment namespace to do so.
Host: Office 365, Excel
Code:
Excel.run(ctx => {
const cell = ctx.workbook.getSelectedRange().getCell(0, 0);
cell.format.fill.color = "FFFF00";
cell.format.horizontalAlignment = Excel.HorizontalAlignment.fill;
cell.format.font.size = 1;
return ctx.sync();
});
It throws with:
Unhandled promise rejection InvalidArgument: The argument is invalid or missing or has an incorrect format.
However, when I use the same code and set the alignment to 'Center' as such:
Excel.run(ctx => {
const cell = ctx.workbook.getSelectedRange().getCell(0, 0);
cell.format.fill.color = "FFFF00";
cell.format.horizontalAlignment = Excel.HorizontalAlignment.center;
cell.format.font.size = 1;
return ctx.sync();
});
Everything works just fine. What am I doing wrong?
Edit: documentation for reference: https://learn.microsoft.com/pl-pl/javascript/api/excel/excel.rangeformat?view=office-js#horizontalalignment
Upvotes: 2
Views: 1575
Reputation: 1959
I withdraw this suggestion cell.format.horizontalAlignment = xlFill; or cell.format.horizontalAlignment = Excel.HorizontalAlignment.xlFill;
I found this at horizontalAlignment doesn't work with xlFill
Upvotes: 0