CloneStyleFrom should only throw an exception if the passed in style is not HSSFCellStyle. Note that there is also an issue with XSSFCellStyle cloneStyleFrom - it appears to call itself indefinitely when the input is of XSSFCellStyle.
Created attachment 22956 [details] Patch that should solve a bug related to the cloneStyleFrom method of XSSFCellStyle class (and HSSFCellStyle as well) I'm not so familiar with open source developing, so I don't know if this is the right way to proceed. If not, please excuse me. I came across a bug in XSSFCellStyle and consequently, in this bug. Probably I managed how to solve both (a first look at the generated xlsx seems to confirm that I was able to clone the style). You can find the changes I made to the sources in the attached patch. In XSSFCellStyle.java I tried to use the style used in HSSFCellStyle.java. I'm not sure it's an efficient, elegant or complete solution but I hope this can help. Regards, Lorenzo Benvenuti
Lorenzo, The only issue I see with the patch is for the XSSFCellStyle cloneStyleFrom() method. There is only a single cloneStyleFrom method in XSSFCellStyle (while HSSFCellStyle has two), therefor the XSSFCellStyle cloneStyleFrom method will call itself recursively and never return (while in HSSFCellStyle one of the methods calls the other)
Lorenzo, My apologies. I didn't scroll down all the way on your patch. I see that you have included the second cloneStyleFrom method. Do we need to set some of the other style variables like cellStyleXf?
Patrick, actually I'm not sure that the "state" of the XSSFCellStyle is fully determined by the cellXf property. I just took a look at the copy() method and I thought the style representation was fully delegated to the cellXf bean while the other properties were just cellStyle "control" variables already set in the costructor when the current style (the one that is going to clone the source style) is created. Please notice I might be wrong, probably the author of the XSSFCellStyle class would be helpful here. Regarding the methods calling itself indefinitely, as you may have guessed, I used the overloaded method to mirror the HSSFCellStyle class implementation of the cloneStyleFrom method. At last: I think the "return" clauses I added are necessary for avoiding the exception to be always thrown; actually I don't like using a "return" in the middle of a class (in this case I could have changed the "if" condition) but this was the less invasive change. Hope this helps! Lorenzo
Should be fixed in r766755 Yegor *** This bug has been marked as a duplicate of bug 47054 ***