Yes, Archbishop Rummel did it in New Orleans in 1962. I believe one of the three segregationists he excommunicated is still alive and still excommunicated.

That said, excommunication of public officials has not been a particularly successful tactic for the Catholic Church since at least the sixteenth century. Depending on the political context, it can backfire.