Apache poi xssf file Mailing

Hi,

We have excel sheets created in webMethods and stored in linux file structure. In linux the file opens as binary content but in windows OS the same opens perfect as excel workbook.

My requirement is to now mail this file.
However when I am trying to pass the workbook object (xssf object) as input to attachment/content in pub.client.smtp , My email receives a corrupted file , ie, it opens with binary content.

Also, I tried converting xssf Workbook object to byte but its not working for me.

Could anybody help here ?

thanks,
Priya

Did you set the proper Content-Type in the smtp service so the attachment is valid?

Try this ContentType = “application/vnd.ms-excel” or application/csv

HTH,
RMG

Hi RMG,

Thanks for your reply.

I did try with the following content types:

application/vnd.ms-excel
application/csv
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml.

Can u pls suggest what should be the content type? For ex: I am opening the org.apache.poi.xssf.usermodel.XSSFWorkbook and get the workbook object opened. What should be the best way to pass the content ?

If I try to convert the workbook object to string it just gives : Name: /xl/workbook.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml

I tried passing the workbook object directly and also after converting to string.

Thanks,
Priya

Hi RMG,

It happened to work out with some more trying…thanks for ur inputs! :slight_smile:

Following is the config :

content-type: application/csv
Encoding: base64.

I used pub.file.getFile to load the excel file from drive as a stream and it gave the correct attachment in the email.

Thanks,
Priya