I have to buy a couple of ESL books and a dictionary for my daughter and I don't think any of the WHSmiths around the airport sell school books. I have a long stopover (18 hours) and I can exit the airport, but I don't want to go too far.
In general, it is absolutely pointless to try to find anything specific outside but close to Heathrow. There's roughly nothing, it's truly in the middle of nowhere (ok, charming English countryside but services are few and far inbetween) and the time to actually get to anything is roughly the same as taking the Heathrow Express into Central London where roughly everything is and then some. I mean, it's London.
The common wisdom on this site is that if you have 5-6 hours then going into Central London is possible. 18 hours is more than plenty, you do not even need the HEX, plain old cheap Piccadilly line on the Tube will do. You could even go sightseeing 18 hours is a lot.
Edit: since Gayot agrees with Foyles, let me mention that the Foyles at 107 Charing Cross Rd is less than five minutes from the Leicester Square Station which is a stop on the Piccadilly line. No need to transfer, even. From there it's even less walk to Hotel Chocolat on Old Compton Street where you can enjoy some of the best hot chocolate in London. I know you didn't ask about this but still, it'd be a waste to miss that place since you are so close. There's more: if you continued on the Picadilly line two more stops to Holborn then there's an Apostrophe very close to the station which also has very good hot chocolate at a much lower price than Hotel Chocolat. I personally fancy the latter but I believe such important matters as which place has the best hot chocolate in any major city must be decided by personal experience (except New York, because you can't beat Eataly so if you happen to be in NYC, just to go there). Let's face it, you have 18 hours, what are you going to do with it?