Work by integration

When the force changes along the way, or each layer of a load is lifted a different height, the work is the integral of force times distance over the pieces, such as $\int kx\,dx$ for a spring.

From Calculus 2.