I discussed this a while ago here. We did not derive a general formula, but it might be possible to get one. It is certainly possible to calculate those values with a macro (and implement this macro as function in excel). Brute force, if you do not find anything better.
As alternative, you can generate a lookup table for all 1001 possible batting averages once.