As for complexity SQL query we have two solutions as below, I will discuss #2 in this article.
To generate excel by query content, and download through any controller. You also can bind cssClass to header/odd/even rows. As for header, you even can set cssClass for each column.
in your controller.
1. Create Extension in yii2.