The equation that relates the spring extension to the force applied to it is linear:

where

is the spring constant.
Hence

because

The work done when stretching the spring is

The work is negative because we stretch the spring while the string oposes to this stretching.