The binding energy, electronic structures, optical absorption and reflection spectra of the formaldehyde (HCHO) adsorption on B-doped single-walled (8,0) carbon nanotubes have been investigated using density functional theory based on first principles. The calculated results show that the B-doped SWCNT is sensitive to HCHO, the binding energy increases, peaks in absorption and reflection spectra increase, the peak height decreases and shows blue shift in the lower energy region, and there appears a distinct peak in HCHO adsorption on B-doped carbon nanotubes at the energy of E=172 eV. The results have been discussed theoretically. B-doped single-walled carbon nanotubes are expected to be used to design sensors and photoelectric device for monitoring formaldehyde.