am_mehra - 2012-01-13

Hi,

I am new for jxl API. I wrote a very basic code just to print label and set the background colour to white.

Although excel sheet is getting generated and Label is also coming properly but it’s not changing the background colour.

Please help.

Code:-
      private static  String inputFile;

      public  void setOutputFile(String inputFile) {
            this.inputFile = inputFile;
      }
     
      public static void main(String args){
           
            try{
           
            String fileName = "C:\\dev\\Test.xls";
            CreateXLS objCreateXLS = new CreateXLS();
            objCreateXLS.setOutputFile(fileName);
            File file = new File(inputFile);
           
            WorkbookSettings wbSettings = new WorkbookSettings();
            wbSettings.setLocale(new Locale("en", "EN"));
           
            WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
            workbook.createSheet("TEST REPORT", 0);
            WritableSheet excelSheet = workbook.getSheet(0);

            workbook.setColourRGB(Colour.RED, 12, 50, 200);
           
            WritableFont writableFont = new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD);
            WritableCellFormat cellFormat = new WritableCellFormat(writableFont);
            CellView cv = new CellView();
            cv.setFormat(cellFormat);
            Label label;
            label = new Label(4, 4, "HI", cellFormat);
            label.setCellFormat(cellFormat);
            excelSheet.addCell(label);

            workbook.write();
            workbook.close();
           
            }catch (Exception e) {
                  e.printStackTrace();
            }
           
      }