Home » SQL & PL/SQL » SQL & PL/SQL » generate xls file through pl/sql
generate xls file through pl/sql [message #610642] Sat, 22 March 2014 06:45 Go to next message
tisekofti
Messages: 21
Registered: February 2008
Junior Member
I have created a store procedure in order to display data results into an excel file.
the file is generated in the specify location but when i try to open the file, it states that the file might be corrupted.
When i click "Yes" and open the excel file i can see all my data correctly there, except from the format of my second column (please refer to the attachment). This is what is actually causing the problem with the error message, because i have tried to generate it with a static character and it worked.
the field's datatype is set to varchar2(17) but when the excel is generated the formatting is not corrected.
So my question is, what else can i do in order to "force" the result to be shown as a string?
Thank you
Re: generate xls file through pl/sql [message #610644 is a reply to message #610642] Sat, 22 March 2014 07:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Fix your code that generates the file.
If you have posted it we could tell you what is wrong but as you didn't we can't.

Re: generate xls file through pl/sql [message #610653 is a reply to message #610644] Sat, 22 March 2014 08:50 Go to previous messageGo to next message
tisekofti
Messages: 21
Registered: February 2008
Junior Member
Sorry ,

Here is the code

--------------

file_handle utl_file.file_type;


BEGIN

file_handle := Utl_File.fopen( 'REPORTS', 'calc.xls', 'w');
Utl_File.fclose(file_handle);

file_handle := Utl_File.fopen( 'REPORTS', 'calc.xls', 'a');

for i in (select distinct T.details,T.ACC_NO
from temp t
)loop


Utl_File.put_line(file_handle,i.details||chr(9)||i.ACC_NO);

end loop;

Utl_File.fclose(file_handle);

------------
Re: generate xls file through pl/sql [message #610656 is a reply to message #610653] Sat, 22 March 2014 09:45 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
post results from SQL below so we can see datatype for every column


DESC TEST
Re: generate xls file through pl/sql [message #610658 is a reply to message #610653] Sat, 22 March 2014 10:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Note this is NOT an xls file it is an csv file that Excel can read.
Note that in a CSV file there is NO format just data for which you give in form in Excel.

See the below image, both cells contain the same data, the first one is with default format, the second one, enlarged, with number format with no decimals.

/forum/fa/11783/0/

  • Attachment: OraFAQ.jpg
    (Size: 15.47KB, Downloaded 1799 times)
Re: generate xls file through pl/sql [message #610744 is a reply to message #610658] Mon, 24 March 2014 01:11 Go to previous messageGo to next message
tisekofti
Messages: 21
Registered: February 2008
Junior Member
Is there any other way that i can resolve this issue?

If i use the following line in my code

file_handle := Utl_File.fopen( 'REPORTS', 'calc.csv', 'w');

Data is shown correctly but everything is listed in one column instead of two. Is there any way to present exported data in two columns?

thank you once more for all your help
Re: generate xls file through pl/sql [message #610754 is a reply to message #610744] Mon, 24 March 2014 02:31 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

This is an Excel issue NOT an Oracle one.
Select (in Excel) the column and depending on your Excel version you have to go to a Data menu and so on. Post your question in an Excel forum to have a more detailed answer.

Re: generate xls file through pl/sql [message #610803 is a reply to message #610754] Mon, 24 March 2014 08:27 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
csv stands for comma separated values. Maybe you should separate your values accordingly.
Previous Topic: computing statistics at the schema level
Next Topic: Insert statements
Goto Forum:
  


Current Time: Wed Apr 24 13:06:15 CDT 2024