Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define cell text alignment when exporting Excel file in Angular 8 application?

I am exporting excel file from Angular 8 application using https://www.npmjs.com/package/xlsx package v 0.15.3.

Everything works fine, but I can't seem to find a way to define text alignment in the cell in the exported file.

When I export excel file, text in all cells is aligned left by default, and I want to align it right.

ColInfo and RowInfo interfaces from this package don't seem to offer options to align text in cells.

Does anyone know how to do it with this package or any other way?

like image 661
Jovan Avatar asked Sep 02 '25 10:09

Jovan


1 Answers

For reference, I'm doing an Angular 9 project.

You probably figured this out long ago, but in case someone else stumbles on this like I did...the easiest way I found was to switch from xlsx to exceljs. Older answers that suggested the use of xlsx-style took me down a rabbit hole of lots of errors. Exceljs just works, and works simply.

https://www.npmjs.com/package/exceljs

They have great documentation, and their alignment section explains it in simple terms, see image link below (sorry, I'm not allowed to post pictures yet, as this is my first post):

ExcelJs Alignment

like image 108
Kat Avatar answered Sep 05 '25 00:09

Kat