Studies of extinction curves provide insights into the properties of interstellar dust. Until recently, however, very few extinction curves existed outside the local group. GRB afterglows are well suited to extinction studies due to their brightness, simple power-law spectra and their occurrence in distant star forming galaxies. In this paper we present results from the SED analysis of a sample of 41 GRB afterglows, from X-ray to NIR wavelengths. The sample is based on spectra from VLT-FORS, with additional data primarily from Swift. This is the largest sample of extinction curves outside the Local Group and, to date, the only extragalactic sample of absolute extinction curves based on spectroscopy. Estimates of the distribution of restframe visual extinctions, the extinction curves, and the intrinsic spectral shapes of GRB afterglows are obtained. Their correlation with H i column density as well as total and gas-phase metal column density are examined. The line-of-sight gas-to-dust and metals-to-dust ratios are determined and examined as a function of total column density, ISM metallicity and redshift. The intrinsic SEDs of the afterglows show that approximately half the sample require a cooling break between the optical and X-ray ranges. The broken power-law SEDs show an average change in the spectral index of Δβ = 0.51 with a very small standard deviation of 0.02 (excluding the outlier GRB 080210). This is consistent with the expectations from a simple synchrotron model. Such a close convergence of values suggests that the X-ray afterglows of GRBs may be used with considerably more confidence to set the absolute flux level and intrinsic spectral indices in the optical and UV. Of the sample, 63% are well described by a featureless (SMC-type) extinction curve. Almost a quarter of our sample is consistent with no significant extinction (typically A V 0.1). The 2175 Å extinction bump is detected unequivocally in 7% of our sample (3 GRBs), which all have A V > 1.0, while one afterglow has a very unusual extinction curve with a sharp UV rise. However, we can only say that the bump is not present in about a quarter of our sample because of low extinction or lack of coverage of the 2200 Å region. All the afterglows well fit with SMC type curves have moderate or low extinction, with A V < 0.65. This suggests that the SMC extinction curve is not as nearly-universal as previously believed and that extinction curves more similar to those found in the Galaxy and the LMC may be quite prevalent. We find an anti-correlation between gas-to-dust ratio and metallicity consistent with the Local Group relation; we find, however, no correlation between the metals-to-dust ratios and the metallicities, redshift and visual extinction; we find no strong correlation of the extinction column with metallicity either. Our metals-to-dust ratios derived from the soft X-ray absorption are always larger (3-30 times) than the Local Group value, which may mean that GRB hosts may be less efficient at turning their metals into dust. Howe...