I am posting data to an endpoint and in getting an excel (xlsx) file back.

More details: I am required to post a JSON string to an endpoint (this is working fine).

In turn, I get back an XLXS file in the form of a byte array.
However, when looking at the body of this response I am seeing a series of ?? (Question marks) combined with random letters.

My content-type of sending and accepting is application/JSON fyi.

Any thoughts on how I can extract the info needed?


XLSX files are binary, not text. They are a zipped archive of XML files. You will not be able to convert an XLSX binary blob into a string directly. You are seeing question mark characters because the binary content cannot be rendered as text.

Parsing XLSX files in Apex will be very challenging to say the least, and the heap size limitation may be a serious hindrance. You will have a much better time building functionality in an off-platform service. I'd strongly recommend not going down this road.

That said, there is some prior art at least for creating XLSX files in Apex. See the answers on this question, which includes discussion of the Zippex Apex library for working with zip files.

  • Thanks David for your clarification on this matter. Oct 5 '20 at 17:15
  • Also david, do you have a recommendation for any off platform services to use? Oct 5 '20 at 17:16
  • @AksharMistry Personally, I would build it on Heroku, but the best service is the one you already use or feel comfortable with!
    – David Reed
    Oct 5 '20 at 17:27
  • Hi David, is a callout from LWC a possible alternative to receiving an excel file in the form of a byte array? I ran into some issues with it, but not sure if that should technically work. Oct 7 '20 at 13:12
  • Yes, if you have appropriate libraries in JavaScript you could potentially do this well on the front end.
    – David Reed
    Oct 7 '20 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.