AG

Hello Everyone, 

I output report to an Excel file and I need to set background color for the cells. But no matter how hard I try, I can't do anything - background color remains white. I ask you to help me with advice on how to solve this problem? Here is a fragment of my code:
 

.....

    var orderCellStyle = oO.createCellStyle(orderFont, 0, 0, 0, 0, 0, 0, 0, 0, Constants.ALIGN_LEFT, Constants.ALIGN_CENTER, 0, 0, Constants.NO_FILL);
    orderCellStyle.setVerticalAlignment(Constants.VERTICAL_TOP);
    orderCellStyle.setWrapText(true);
    orderCellStyle.setBorderBottom(Constants.BORDER_THIN);
    orderCellStyle.setBorderTop(Constants.BORDER_THIN);
    orderCellStyle.setBorderLeft(Constants.BORDER_THIN);
    orderCellStyle.setBorderRight(Constants.BORDER_THIN);
    orderCellStyle.setFillBackgroundColor(10); //10 - for example
......
    sheet1.cell(0,0).setCellValue("Example");
    sheet1.cell(0,0).setCellStyle(orderCellStyle);


All cell appearance settings are applied except for the background color :(  I've also tried changing the parameters in oO.createCellStyle(....), but that doesn't work either.

I hope for your help.

by Robert Goldenbaum
Badge for 'Question Solver' achievement
Posted on Wed, 01/11/2023 - 11:38

Hi,

you have to create a cell style and then set it to the cell:

oStyle = _oWorkbook.createCellStyle(_fStyle, lTopBorder, lRightBorder, lBottomBorder, lLeftBorder, lTopBorderColor, lRightBorderColor, lBottomBorderColor, lLeftBorderColor, lHorizontalAlignment, lVerticalAlignment, lBackgroundColor, lForegroundColor, lFillPattern) 

oCell = _oOutSheet.cell(i, j); 

oCell.setCellValue("blabla"); 

oCell.setCellStyle(oStyle); 

 

BR Robert

0
by Anton Golovanov Author
Posted on Mon, 01/16/2023 - 06:08

Robert Goldenbaum, thank you so much for your reply!

0
by Anton Golovanov Author
Posted on Tue, 01/17/2023 - 10:11

Hi,

Unfortunately, it didn't work for me anyway. Below is the edited code. I do all the same things, but not through objects. And still the color of the cell in Excel does not change. Remains white.But all other cell settings work, the script is executed without errors.

 

var oO = Context.createExcelWorkbook("Example filename.xls");

var sheet1 = oO.createSheet("Sheet 1");

var orderFont = oO.createFont();
orderFont.setFontName("Arial");

var orderNewCellStyle = oO.createCellStyle(orderFont,1,1,1,1,0,0,0,0,Constants.ALIGN_LEFT,Constants.VERTICAL_TOP,Constants.C_RED,Constants.C_RED,Constants.NO_FILL,Constants.XL_CELL_DATAFORMAT_D_MMM_YY,false,0,false,0,true);

sheet1.cell(i,j).setCellValue("Example value");
sheet1.cell(i,j).setCellStyle(orderNewCellStyle);  

 

0
by Kay Fischbach
Posted on Tue, 01/17/2023 - 13:37

In reply to by Mangol

Constants.NO_FILL

There is your problem, right in your createCellStyle method call. Set that to

Constants.SOLID_FOREGROUND

or some other acceptable fill pattern and it'll have a background color. (Foreground is a bit missleading here - backgrounds have a foreground and background color, none of them will be in front of the cell content)

0
by Anton Golovanov Author
Posted on Wed, 01/18/2023 - 05:46

Kay Fischbach, thank you very much! It's working!
I tried changing this parameter earlier, but the cell became completely black. Apparently I made a mistake somewhere else. But now I have combined your answer and Robert Goldenbaum's answer - and everything worked out.

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock