1111import it .eng .spagobi .tools .dataset .bo .VersionedDataSet ;
1212import it .eng .spagobi .utilities .exceptions .SpagoBIRuntimeException ;
1313import lombok .Getter ;
14- import org .apache .commons .lang3 .StringUtils ;
1514import org .apache .logging .log4j .LogManager ;
1615import org .apache .logging .log4j .Logger ;
17- import org .apache .poi .ss .usermodel .*;
18- import org .apache .poi .xssf .streaming .SXSSFSheet ;
16+ import org .apache .poi .ss .usermodel .CellStyle ;
17+ import org .apache .poi .ss .usermodel .HorizontalAlignment ;
18+ import org .apache .poi .ss .usermodel .Sheet ;
19+ import org .apache .poi .ss .usermodel .VerticalAlignment ;
1920import org .json .JSONArray ;
2021import org .json .JSONException ;
2122import org .json .JSONObject ;
2223
2324import java .util .*;
2425
25- import static it .eng .knowage .engine .api .export .dashboard .StaticLiterals .EXCEL_ERROR ;
26-
2726@ Getter
2827public class DashboardExporter {
2928
@@ -519,23 +518,11 @@ protected String replaceWithCustomHeaderIfPresent(JSONObject settings, String co
519518 return columnName ;
520519 }
521520
522- public void adjustColumnWidth ( Sheet sheet , String imageB64 ) {
521+ protected boolean isSummaryColumnVisible ( List < String > columnsToHide , JSONObject column ) {
523522 try {
524- ((SXSSFSheet ) sheet ).trackAllColumnsForAutoSizing ();
525- Row row = sheet .getRow (sheet .getLastRowNum ());
526- if (row != null ) {
527- for (int i = 0 ; i < row .getLastCellNum (); i ++) {
528- sheet .autoSizeColumn (i );
529- if (StringUtils .isNotEmpty (imageB64 ) && (i == 0 || i == 1 )) {
530- // first or second column
531- int colWidth = 25 ;
532- if (sheet .getColumnWidthInPixels (i ) < (colWidth * 256 ))
533- sheet .setColumnWidth (i , colWidth * 256 );
534- }
535- }
536- }
537- } catch (Exception e ) {
538- throw new SpagoBIRuntimeException (EXCEL_ERROR , e );
523+ return !columnsToHide .contains (column .getString ("id" ));
524+ } catch (JSONException e ) {
525+ throw new SpagoBIRuntimeException (e );
539526 }
540527 }
541528
@@ -544,34 +531,6 @@ public void adjustColumnWidth(Sheet sheet, String imageB64) {
544531 * START OF STYLE METHODS
545532 */
546533
547- public CellStyle buildCellStyle (Sheet sheet , boolean bold , HorizontalAlignment alignment , VerticalAlignment verticalAlignment , short headerFontSizeShort ) {
548-
549- // CELL
550- CellStyle cellStyle = sheet .getWorkbook ().createCellStyle ();
551-
552- // alignment
553- cellStyle .setAlignment (alignment );
554- cellStyle .setVerticalAlignment (verticalAlignment );
555-
556- // FONT
557- Font font = sheet .getWorkbook ().createFont ();
558-
559- font .setFontHeightInPoints (headerFontSizeShort );
560-
561- font .setBold (bold );
562-
563- cellStyle .setFont (font );
564- return cellStyle ;
565- }
566-
567- protected void applyWholeRowStyle (int c , List <Boolean > styleCanBeOverriddenByWholeRowStyle , Row row , CellStyle cellStyle ) {
568- for (int previousCell = c - 1 ; previousCell >= 0 ; previousCell --) {
569- if (styleCanBeOverriddenByWholeRowStyle .get (previousCell ).equals (Boolean .TRUE )) {
570- row .getCell (previousCell ).setCellStyle (cellStyle );
571- }
572- }
573- }
574-
575534 protected JSONObject getRowStyle (JSONObject settings ) {
576535 JSONObject style = jsonObjectUtils .getStyleFromSettings (settings );
577536 if (style != null && style .has ("rows" )) {
@@ -673,16 +632,16 @@ private JSONArray getTarget(JSONArray styles, int i) throws JSONException {
673632 return target ;
674633 }
675634
676- protected JSONObject getTheRightStyleByColumnIdAndValue (Map <String , JSONArray > styles , String stringifiedValue , String columnId ) throws JSONException {
677- JSONObject customStyle = getTheStyleByValueAndColumnId (styles , stringifiedValue , columnId );
635+ protected JSONObject getTheRightStyleByColumnIdAndValue (Map <String , JSONArray > styles , String stringifiedValue , String columnId , String currentAlternateRowColor ) throws JSONException {
636+ JSONObject customStyle = getTheStyleByValueAndColumnId (styles , stringifiedValue , columnId , currentAlternateRowColor );
678637
679638 if (customStyle .has ("properties" ) && customStyle .getJSONObject ("properties" ).length () == 0 ) {
680- return getTheStyleByValueAndColumnId (styles , stringifiedValue , ALL_COLUMNS_STYLE );
639+ return getTheStyleByValueAndColumnId (styles , stringifiedValue , ALL_COLUMNS_STYLE , currentAlternateRowColor );
681640 }
682641 return customStyle ;
683642 }
684643
685- private JSONObject getTheStyleByValueAndColumnId (Map <String , JSONArray > styles , String stringifiedValue , String columnId ) {
644+ private JSONObject getTheStyleByValueAndColumnId (Map <String , JSONArray > styles , String stringifiedValue , String columnId , String currentAlternateRowColor ) throws JSONException {
686645 try {
687646 JSONObject nonConditionalProps = new JSONObject ();
688647 if (styles != null ) {
@@ -693,6 +652,12 @@ private JSONObject getTheStyleByValueAndColumnId(Map<String, JSONArray> styles,
693652 return getStyleObject (nonConditionalProps , STATIC_CUSTOM_STYLE , 0 , false );
694653 } else {
695654 columnStyles = styles .get (ALL_COLUMNS_STYLE );
655+ if (currentAlternateRowColor != null ) {
656+ for (int i = 0 ; i < columnStyles .length (); i ++) {
657+ JSONObject style = columnStyles .getJSONObject (i );
658+ style .optJSONObject ("properties" ).put ("background-color" , currentAlternateRowColor );
659+ }
660+ }
696661 }
697662 }
698663
0 commit comments