How to set background colour in the the Grails excel-export / apache-POI plugin? -


we using grails excel-export plugin uses apache-poi under hood.

we trying set background colour (and later font) of cell (or row).

we have tried this:

def rgb = [50,50,50] byte[] xssfcolor colour = new xssfcolor(rgb) headers.eachwithindex() {item, ->   xlsxexporter.putcellvalue(row, i, item.value.tostring())   def style = xlsxexporter.getcellat(row, i).getcellstyle()   xlsxexporter.getcellat(row, i).setcellstyle(style.setfillbackgroundcolor(colour)) }; 

but nothing changes. tried putting setcellstyle before plutcellvalue, results in null pointer exception.

we can't use template, because developing plugin, , applications can have accessible files in web-inf, not plugins, unfortunately.

-- update 1

tried this:

  def style = xlsxexporter.getcellat(row, i).getcellstyle()   style.setfillbackgroundcolor(colour)   style.setfillpattern(cellstyle.align_fill)   xlsxexporter.getcellat(row, i).setcellstyle(style) 

didn't help.

-- update 2

tried using template xlsx. in template changed whole rows have background colour. resultant output has cells data written having no background, , remaining cells having background. i.e. if write data, overwrites templates style, opposite of documentation says. raised bug plugin website.

  // convert headers list of strings exporter.   headers = response.rows[0].keyset()   list<string> headerslist = []   headers.eachwithindex() { item, ->           headerslist.add(item.value.tostring())   }    // copy raw row data list of lists exporter   def exports = []   response.rows.each {          exports <<   }    xlsxexporter = new webxlsxexporter(servletcontext.getrealpath("/reporting/report_template.xlsx")).with {          fillheader(headerslist)          add(exports, headerslist)          save(outputstream)   } 

instead of :

style.setfillbackgroundcolor(colour) 

try this:

style.setfillforegroundcolor(color) style.setfillpattern(style.solid_foreground) 

check whether helps


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -