0

I would like to set up an email handler class to receive emails from a supplier with attached files in Excel format. We already have similar functionality that handles CSV attachments from another vendor.

Is it possible to parse attached Excel files in Apex, and/or convert to CSV for further processing? If so, how?

4

Short Answer: No its not posssible to read Excel in Apex.

Long Answer: Excel files(xls,xlsx etc) are not a text based file. They are binary files. Thus unlike CSV(text based) they cant be read line by line/character by character.

You would need a third party integration to convert your excel to CSV.

Meanwhile, there is an idea on Ideaxchange to provide Excel file reading and writing functionality in Apex.

https://success.salesforce.com/ideaView?id=08730000000jh1mAAA

If you still want to do that natievly in Salesforce you have to use an Outbound Integration like SQlizer which can convert your excel file into CSV file. Src: https://sqlizer.io/help/api

  • Actually, XLSX files might be readable, as there is Zippex, an Apex library for reading Zip files. Using that along with some basic XML parsing, you can do it. Files from the older XLS proprietary format, however, have no hope of being read, since there's no documentation on the format. – sfdcfox Apr 4 '18 at 22:32
  • Am trying Zippex to read XLSX files but am failing, can you guide me through? – Pranay Jaiswal Apr 5 '18 at 8:09
  • It's only a theoretical, I've never gone through the entire process, but you might look at EMCA-376, Microsoft's Open Standard Office format they introduced about a decade ago. – sfdcfox Apr 5 '18 at 14:27

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.