I've had a couple of problems trying to use HSSFSheet.cloneSheet(int) I'll attach a patch if I can work out how to. 1) Some of the formula Ptg records can have one of three different id's - this is done by setting the ptgClass. The clone() methods of the relevant classes do not copy the ptgClass when cloning the object. I had problems with ReferencePtg and FuncVarPtg. From a quick scan the classes affected are Area3DPtg, AreaPtg, FuncPtg, FuncVarPtg, NamePtg, NameXPtg, Ref3DPtg and ReferencePtg (I'm ignoring MemErrPtg). 2) PasswordRecord and ContinueRecord do not implement the clone() method.
Created attachment 6944 [details] Patch to correct cloning issues
Created attachment 6981 [details] Replacement Patch with additional bug fix
Thanks, will add them in soon
I probably should have given a better description of the problems this caused. Because these classes were not cloning the ptgClass attribute, when the spreadsheet is opened in Excel the cells with the affected functions have #VALUE! errors. I have also just uploaded another patch, which has all the original changes plus the following changes to the FunctionRecord class: 1) data_value is not being copied in FunctionRecord.clone(). This causes a problem when the result is a "Empty" cell - openning the file in Excel causes a message "File Error: data may have been lost" to be displayed. In actual fact Nothing had been lost and saving the file sorted this out - doesn't look good to the users though. 2) When the calculated value of a Formula is not a number the FormulaRecord.toString() just shows "NaN" - however the 8 bytes contain important information. When I used biffviewer, it took me a long time to work out the above problem because I couldn't see it. I have changed the toString() to display a hex dump if its not a number. I was just typing this in when you said your going to apply them - thanks much appreciated. Niall
Whats functionrecord? do you mean formularecord? And why is that a problem with an empty cell? Other than that, the patch itself seems fine, so i am applying now!
Sorry, yes it should have been "FormulaRecord" not "FunctionRecord". The data_value contains the results of the formula which is either 1) a number 2) an identifier for a String value (and a String record should follow) 3) a boolean value or 4) an identifier for an "empty cell". When the result of the formula is an "empty cell" and the indicator (which is in data_value) is not cloned I got the message "File Error: data may have been lost" when opening the file using excel. So my patch (which was simply adding a line in the clone() method to copy the data_value contents) sorted this out. Thanks for applying the patch, much appreciated. Niall
Thanks for the explanation... but "empty cell" as a formula result, can you give an example... will help me cook up a testcase for later!