In Barcelona we don't speak only Spanish, but also Catalan, although this won't be a problem for foreign people to study at our School.
Papers and exams can be done in Spanish, if the student wants to. The lecturer chooses the language in which he or she is going to give the class, but don't worry, because statistically only 50% of the lessons are taught in Catalan. Besides, every teacher has certain office hours for student services for you to ask any doubt you have.
The Servei de Llengües i Terminologia (SLT) of the Universitat Politècnica de Catalunya offers a linguistic and cultural welcome program which includes free Catalan courses during the whole academic year. If you are interested in getting more information, visit its website.
Apart from that, the Consorci per a la Normalització Lingüística gives you the opportunity to learn Catalan. More information here.
If you are interested in Spanish courses, the Merit School, which is a language school that has an agreement with the UPC, offers them at a reduced price for UPC Erasmus students.