Hello
I´m coding a script for excel spreadsheets and I require different styles for some of the cells.
This is my code:
var LenguaBd=Context.getSelectedLanguage();
var Modelos=ArisData.getSelectedModels();
var modelo= Modelos[0];
var sFileName = "MatrizPuestos.xls";
var sTemplateFileName = "PlantillaMatrizPuestos.xls";
var oXlsWorkbook = Context.createExcelWorkbook(sFileName, Context.getFile(sTemplateFileName, Constants.LOCATION_SCRIPT));
var oXlsSheet = oXlsWorkbook.getSheetAt(0);
var oXlsFont = oXlsWorkbook.createFont();
var oXlsStyle1=oXlsWorkbook.createCellStyle(oXlsFont, 0, 0, 0, 0, 0, 0, 0, 0, Constants.ALIGN_LEFT, Constants.ALIGN_CENTER, 0, 0, Constants.NO_FILL);
oXlsStyle1.setFillPattern (Constants.SOLID_FOREGROUND );
oXlsStyle1.setFillForegroundColor (Constants.C_GREY_80_PERCENT);
var oXlsStyle2=oXlsWorkbook.createCellStyle(oXlsFont, 0, 0, 0, 0, 0, 0, 0, 0, Constants.ALIGN_LEFT, Constants.ALIGN_CENTER, 0, 0, Constants.NO_FILL);
oXlsStyle2.setFillPattern (Constants.SOLID_FOREGROUND);
oXlsStyle2.setFillForegroundColor(Constants.C_LIGHT_BLUE);
var oRow=oXlsSheet.createRow(0);
var oCell = oRow.createCell(0);
oCell.setCellValue("Niveles");
oCell.setCellStyle(oXlsStyle1);
oCell = oRow.createCell(1);
oCell.setCellValue("Nombre Proceso");
oCell.setCellStyle(oXlsStyle2);
Context.setSelectedFile(sFileName);
oXlsWorkbook.write();
why did the first style not used? I need a header, but the cells have no different background.
Any help would be appreciated.
Hi Francisco,
you create exactly the same cell style twice. The workbook recognizes this and returns the same internal cell style object. To get different style objects, you have to specify different parameters calling XlsWorkbook#getCellStyle(). In your case this even makes your code easier:
var oXlsStyle1=oXlsWorkbook.createCellStyle(oXlsFont, 0, 0, 0, 0, 0, 0, 0, 0, Constants.ALIGN_LEFT, Constants.ALIGN_CENTER, 0, Constants.C_GREY_80_PERCENT, Constants.SOLID_FOREGROUND);
var oXlsStyle2=oXlsWorkbook.createCellStyle(oXlsFont, 0, 0, 0, 0, 0, 0, 0, 0, Constants.ALIGN_LEFT, Constants.ALIGN_CENTER, 0, Constants.C_LIGHT_BLUE, Constants.SOLID_FOREGROUND);
BR, Torsten