Skip to Main Content
  • Questions
  • How to export .xls file with table data as a attachment from Plsql block

Breadcrumb

XMAS_TREE

The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.

Question and Answer

Connor McDonald

Thanks for the question, Harshad.

Asked: October 05, 2016 - 6:59 am UTC

Last updated: October 05, 2016 - 11:45 am UTC

Version: Oracle 10g

Viewed 1000+ times

You Asked

We are using below code for excel property

p_file_name:='demo.xls';
UTL_TCP.
write_line (v_tcp_connection,
'Content-Type: application/ms-excel;'); ----- 2ND BODY PART.

UTL_TCP.
write_line (v_tcp_connection, 'Content-Disposition: attachment;'); ----- INDICATES THAT THIS IS AN ATTACHMENT
Rc := UTL_TCP.write_line (v_tcp_connection, ' filename=' || p_file_name); ----- SUGGESTED FILE NAME FOR ATTACHMENT
Rc := UTL_TCP.write_line(v_tcp_connection,'Content-Transfer-Encoding: base64' || p_file_name);
Rc := UTL_TCP.write_line (v_tcp_connection, '');

but when we are opening xls file in email that file opening with error saying

"The file format and extension of "demo.xls" don't match. The file could be corrupted or unsafe. Unless you trust its source,dont open it.Do you want to open it anyway? "

Please suggest how to fix this issue?


Thanks,
Harshad.

and Connor said...

Well - you need to write out the data in xls format, not just mention its filename.

And writing out xls is not trivial - its a proprietary Microsoft format.

It might be easier to write out CSV.

Alternatively, check out the AMIS routine to create xlsx files.

https://technology.amis.nl/tag/as_xlsx/



We're not taking comments currently, so please try again later if you want to add a comment.