You should not use a custom number format if you have a mix of eight and twelve digit numbers and you are "converting" the data into another program. These data are not numbers (even though they are composed of numeric digits), they are strings (text), and should be stored as such in Excel. Excel automatically converts values composed of numeric digits into numers unless you tell it otherwise. The best way to do this, as mentioned above, is to preformat the cells as Text. That's how you direct Excel to "leave the zeros alone."
If you cannot re-import the values into a Text range, you can insert a (temporary) column next to your column of numbers and use a formula like this copied down the rows:
Then Copy that range of formulas and Paste Special, Formats over your original column (D, in this example). Then delete the temporary column with the formulas.
If you have some other algorithm to distinguish the eight-digit values from the twelve-digit values, i.e. a value from another column, use that instead of the predicate I used above, as my algorithm will convert what was 000012345678 to 12345678.
To convert an existing range from numbers to text, you can select the range, format the cells as Text, and then use Alt+d, e, Enter, Enter, Enter (Text to columns), but the leading zeros were lost when Excel converted the values into numbers and would need to be replaced.