excel forumula calculation when spreadsheet opens
excel forumula calculation when spreadsheet opens

I was playing with functions and hyper links in tables and trying to export them to excel.
I came across this question: https://datatables.net/forums/discussion/42097
that lead me to try to find how to get them to auto evaluate.
it occurred to me that in python I'm using XLSXwritter and the forumals work there, so what are they doing?
I found this tidbit:
that lead me to this: https://stackoverflow.com/questions/18355691/set-xlsx-to-recalculate-formulae-on-open
the good part is this:
so the question is do you set
<calcPr fullCalcOnLoad="1"/>
Replies
I don't see that property in xl/workbook.xml. You can view the spreadsheet XML by unzipping the file the download XLSX file. I created a simple export that uses
SUM()
in one of the columns. TheSUM()
function executes when opening the exported file.https://live.datatables.net/ninukebu/1/edit
I don't have Excel but opened it in Numbers on the Mac. Does the function automatically execute for you in Excel?
I updated the test case to add
<calcPr fullCalcOnLoad="1"/>
to theworkbook
node in xl/workbook.xml. Not sure if that is the correct place. Does this do what you want?https://live.datatables.net/rahipuvo/1/edit
Kevin
Yup, as always, Kevin is spot on. The answer is no, I don't set
fullCalcOnLoad
at all. You can see the general XML structure for the spreadsheet that is created here.Allan
it seems to work with or without that property being set for your simple example. let me do some more testing with my code. it may take me a day or two to reply, but I am very interested in getting this to work.
Works like a charm in Excel! I wasn't aware that this is possible at all. Could be very useful for some of my Excel exports as well. Thanks for this, Kevin!
As always Excel converts everything for the respective regional Excel version in use. So SUM is being converted to SUMME in my case.
Roland
does datatable use XLSXwritter?
No it uses the JSZip library that you are loading. See the
excelHtml5
docs for more details.Kevin
thanks. your example confused me.
If you need help customizing the Excel output then please post a simple test case that has an example of the data you want in the SS. My example is simplistic to show how to create functions. The specifics of wha you need to do is dependent on your specific data and how you want Excel to handle it. Feel free to update my test case with your example data.
Kevin
if i create a cell with =SUM(b2:c2) why doesn't work? what is that conversion step that you are doing? what is that "<f>" doing?
Without seeing what you are doing its impossible to say what the problem might be. Please post a simple test case showing what you are trying to do so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
I'm not sure what you mean by conversion step. Here is a snippet of the test case code I posted:
What part of this code are you asking about.
It's a formula element. See this Microsoft Open XML doc for more details about formulas.
The export buttons, using JSZip, is meant for basic export capability. It can be very complex to customize the output beyond the basics. Possibly creating a Custom Button and using SheetJS might be a better alternative for your case.
Kevin
I built a simplistic SheetJS example that shows one way of creating hyperlinks (which I think you asked about).
https://live.datatables.net/cayuguri/1/edit
It's loosely related to their Export example. I used the Hyperlinks doc to learn how to create hyperlinks and added a loop for column A to create them.
This si the only Datatables related code in the custom button:
It uses
rows().data()
to get all the rows andcolumns().titles()
to get the header titles.toArray()
is used to convert them from Datatables API results to standard Javascript arrays.The rest of the code is SheetJS specific Javascript code. Use their docs and support options to learn how to use SheetjS. We can help with any Datatables questions. Note that my SheetJS example likely won't work out of the box with your specific data. If you go this route make sure to build a simple test case with examples of your data and custom button code so we can see what you are doing.
Kevin
here's my example. I was trying to write =HYPERLINK into the excel doc.
I can see now that the customize function can do a lot more than the exportOption can.
https://live.datatables.net/ninukebu/5/edit
I think with your example I can get what I want.
That looks like a good start. I'm thinking SheetJS might be a bit easier as it looks like that is needed is to build the proper object for each element type then SheetJS will build the XML Using
customize
will require you to build the XML structure.Kevin
I'm wondering if I should perhaps have a basic SheetJS button which can then be more readily customised than the excelHtml5 button type...
Allan
in a case like this it would be useful.