What does setBuiltInFormatCode() do?

Topics: Developer Forum, User Forum
Jul 22, 2013 at 6:54 PM
I'm a PHPExcel newbie. I was trying to format a cell with the Percentage format ("0%"), and my IDE helpfully displayed the methods available on getNumberFormat()->... ., one of them was "setBuiltInFormatCode()", which I assumed would let me set it to one of the predefined number formats.

Turns out I was able to use setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE) to do what I needed. So what's the point of setBuildInFormatCode()?

PHP version 5.4.6
PHPExcel version 1.7.9
Jul 23, 2013 at 9:59 AM
When you call setFormatCode, the buildInFormatCode is automatically set.
AFAIK, it is mainly used by the writer when he wrote the styles in the file.
Coordinator
Jul 23, 2013 at 11:52 AM
It's similar to setFormatCode, but instead of specifying the code as a string, you can identify one of the built-in codes by its ID value
Jul 23, 2013 at 1:37 PM
MarkBaker wrote:
It's similar to setFormatCode, but instead of specifying the code as a string, you can identify one of the built-in codes by its ID value
Mark, well I thought that might be the case, but as I said in my previous post, I was able to use:
 ...->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
So that's why I was confused.

@LWol, it seems that if it's just used internally, it should be defined as private or protected, not public. grr.
Coordinator
Jul 23, 2013 at 3:30 PM
There's a of of alternative methods to achieve the same objective (look at the number of different methods to set a cell value, for example).
This isn't an internal method because it's perfectly acceptable for userland coding to access it; though the basic setFormatCode() mthod is more flexible because you can use it to set any numberformat mask, whether built-in or not.
Jul 23, 2013 at 3:50 PM
The methods may not be private or protected because called from other classes (that are not extensions).

Call setFormatCode with [...]FORMAT_PERCENTAGE sets buildInCode to 9