In underlay device-to-device (D2D) communication, a D2D pair reuses the cellular spectrum and creates interference to regular cellular users. Optimal operation requires joint consideration for the achieved D2D rate and the added interference to cellular users. Most existing work on D2D rate maximization concerns only the simplified scenario where the D2D pair has access to a single channel or resource block. In this work, we present an optimization solution to allocate the D2D transmission power over multiple channels, to maximize the sum rate between D2D and cellular users, under a sum-power constraint on the D2D transmitter and minimum SINR guarantees at each RB for all cellular users. The proposed optimization is applicable to both uplink and downlink cellular spectrum sharing. Our simulation studies further shed light into how the maximum sum rate is impacted by the available D2D power and the SINR guarantees.