formatCells doesn't work in Dynamic Grid Template

Issue #95 resolved
Ricardo Montoya
created an issue

Hi, I've used the dynamic grid example to generate a report but I can't make the resulting Excel file to format the cells indicated in formatCells as such.

Is this a bug or am I missing something?

This is a sample code (listFields and tiempos are proper lists with headers titles and data objects. fieldsCommaSeparated is also self explanatory):

try (InputStream is = new FileInputStream(path + "ReporteExcel.xls")) {             

            ByteArrayOutputStream bos = new ByteArrayOutputStream();            

            Context context = new Context();            
            context.putVar("columnas", listFields);
            context.putVar("info", tiempos);        
            JxlsHelper.getInstance().processGridTemplateAtCell(is, bos, context, fieldsCommaSeparated,"Sheet1!A1");

            return bos.toByteArray();
        } catch (IOException e) {
            return null;

My template:

Screen Shot 2018-01-23 at 6.45.53 PM.png

My resulting file, where you can see the column T without the format being applied:

Screen Shot 2018-01-23 at 6.48.19 PM.png

Thank you in advance for your attention

Ricardo Montoya

Comments (7)

  1. leonate NA repo owner

    So I can see that your markup comment looks like this:

    jx:grid(lastCell="A3" headers="columnas" data="info" areas=[A2:A2, A3:A3] formatCells="Date:T1")

    The formatCells attribute defines from which cell to take the format for a particular data type. In your case you indicate that for any column with type java Date you get the format from cell T1. However for the T1 cell there is no format set in the template. So you need to set the format to some Excel cell first and then use it as a source format mapping. Check the original jx:grid example from jxls-demo project and check the format of the cells used in formatCells attribute in Excel.

  2. Ricardo Montoya reporter

    Thank you @leonate NA The example was not so explicit regarding this and as I was in a rush I didn't pay close attention to get to the right way of config. Maybe I could suggest to make more explicit this part in the docs.

    Thank you again! :D

  3. Log in to comment