Observations of exoplanetary spectra are leading to unprecedented constraints on their atmospheric elemental abundances, particularly O/H, C/H, and C/O ratios. Recent studies suggest that elemental ratios could provide important constraints on formation and migration mechanisms of giant exoplanets. A fundamental assumption in such studies is that the chemical composition of the planetary envelope represents the sum-total of compositions of the accreted gas and solids during the formation history of the planet. We investigate the efficiency with which accreted planetesimals ablate in a giant planetary envelope thereby contributing to its composition rather than sinking to the core. From considerations of aerodynamic drag causing `frictional ablation and the envelope temperature structure causing `thermal ablation, we compute mass ablations for impacting planetesimals of radii 30 m to 1 km for different compositions (ice to iron) and a wide range of velocities and impact angles, assuming spherical symmetry. Icy impactors are fully ablated in the outer envelope for a wide range of parameters. Even for Fe impactors substantial ablation occurs in the envelope for a wide range of sizes and velocities. For example, iron impactors of sizes below ~0.5 km and velocities above ~30 km/s are found to ablate by ~60-80% within the outer envelope at pressures below 10^3 bar due to frictional ablation alone. For deeper pressures (~10^7 bar), substantial ablation happens over a wider range of parameters. Therefore, our exploratory study suggests that atmospheric abundances of volatile elements in giant planets reflect their accretion history during formation.