OOXML - Spreadsheet (.XLSX) created with Ruby won't recalc
I am building a ruby class/component to use in my Rails projects for creating reports/exports based on Excel .xlsx files. With the component, I can open a "template" .xlsx file, add data in rows to a sheet, save and then download the file to the user. It has been working well for several months now.
Now I need to 开发者_JAVA技巧take a pre-existing .xlsx file (think "form"), open it as a template, insert values in several of the cells, and then save and download to the user. For the most part, the process works. The one hitch is that one of the cells I am updating with data is within a range of cells that gets a SUM function applied to it. The problem: the SUM cell doesn't have the correct sum in it.
I've checked the cell both in Excel upon download, and also the underlying xml - the cell and its data is numeric - not text. When I try to manually recalc the sheet - nada. I can update one of the other cells in the range that is getting SUM'd, and it magically starts working - the SUM cell shows the proper total.
I read a post earlier today that mentioned removing the element from the total field in order to signal to Excel when the spreadsheet is opened that it should recalc - nope.
I'd really like to open source this component once I get this further along; I think it would be a BIG help to the Ruby community. Thanks in advance for any help!
Sounds like you need to set the fullCalcOnLoad
attribute of the calcPr
element to true:
<workbook>
<calcPr fullCalcOnLoad="1"/>
</workbook>
This will cause the Excel document to perform the caluclations within all the workbooks when the file is opened.
精彩评论