Jump to content

Create excel template with fixed formulas with Jasper Reports


mhn_1

Recommended Posts

I have a report with two columns and when exporting it to excel, in the cells (A1, A2, A3,..) I have a field obtained by database, in column two (B1,B2,B3,..) I need the formula '=A1*0,5'... and that Jasper does not perform the calculation and presents it as another number. So that I can change the value of A2 by hand and automatically update B2.

Also, the cell must change in the formula. I'm passing an image of what I need to get when exporting in excel.

Thanks in advance.

converted-file.png.fd9de6427e3f0f4aa80d1b3ede3ba95b.png

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images


It is possible to embed Excel formulas by using the property 'net.sf.jasperreports.export.xls.formula'.

http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.xls.formula

 

Ex.)
net.sf.jasperreports.export.xls.formula="=A1*0.5"

w20220121_calc.png.ef778f50dd4ff321e95869351701f26c.png

 


However, we had to be creative to meet your requirements.
That is because it is difficult to make the referenced cell in the formula variable, like 'A1' or 'A2'.
So, I thought I could solve the problem by devising a way to write the formula.

Ex.)
net.sf.jasperreports.export.xls.formula="=OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())), 0, -1)*0.5"

w20220121_calc2.png.2723eeaed48551f063b43839fbd39f87.png

 

This is an image of the result displayed in Excel.

 

w20220121_calc3.png.b5401b6be715e24b50ca61ea271974c1.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...