Reputation: 169
I'm trying to access an Excel Template by a string URL from a controller.
Edit
I'm using
def wb = new WebXlsxExporter("/path/to/excel/template")
Which requires the string URL of where the file is stored.
Upvotes: 0
Views: 261
Reputation: 169
So I found the answer... ExcelTemplates folder is in the web-app folder. To get the URL without receiving a file not found error I used
request.getSession().getServletContext().getRealPath(.....)
---------
//Which looks like this when implemented
def wb = new WebXlsxExporter(request.getSession().getServletContext().getRealPath("/ExcelTemplates/testTemplate.xlsx"))
When compiled into a war and placed in the Tomcat 7 /webapp directory, everything works great!
Upvotes: 2
Reputation: 1219
You can put them under the web-app directory. Then you can get them using the following code as an InputStream.
private byte[] getLogoBytes() {
InputStream logo = servletContext.getResourceAsStream('/images/logo.png')
return logo.getBytes()
}
Upvotes: 1