The energy in an object because of its position is called potential energy. If k is the spring constant and spring is compressed by distance x then force applied for this can be given as follows.
F = kx
Now, work done in moving the spring by distance x can be given as follows.