Information sheets from Trafico on the ´canje´ of EU licences, exchange for a Spanish one, with same duration and categories. Note that if the expiration date on your licence is less than 3 months away, you need to renew (renovar), not exchange. Also for non-EU licences from countries with whom Spain has signed an agreement.
Link below with full information. Use the drop down menu for a change in language. In Spanish but once you have chosen your country and clicked on the blue box, you will find the drop down menu.

Check country of origin of your permit to see how you can make the exchange
NOTE: you should NOT be asked for a medical to exchange your EU licence for Spanish permit, only when your licence is about to expire and you are in fact renewing your licence. But, we know that some Trafico offIces do require you to have one anyway.
Expired licences can be renewed.