Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Excel file on AS from Binary data

YouriC
Participant
0 Likes
4,719

Hi,

I need to create Excel file on Application Server.

I receive the Excel information from SProxy Attachment (SWA)


gs_document-att_type = ls_attach->get_content_type( ).

CALL METHOD ls_attach->get_binary_data

     RECEIVING

          p_data = gs_document-att_content.

The Excel content is stored in XString (att_content = XString).

I try to build the Excel file with Dataset in Binary Mode :


lv_xstring = gs_document-att_content.

OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.

TRANSFER lv_xstring TO lv_file.

CLOSE DATASET lv_file.

When i try to open the xls file :

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

Content :

PK     !Û1(òl Ä    [Content_Types].xml ¢  (  ¬”ËnÂ0 E÷•ú ‘·Ub袪* ‹>–-Ré ¸ñ„Xø%ð÷˜‡(¢

6±bûÞ{<òx0j&#141;Π P9[²~Ñc ØÊIe§%ûš¼å&#143;,Ã(¬ ÚY(Ù

&#144;&#141;†·7ƒÉÊ f¤¶X²&FÿÄ9V ...

I do the same method for PDF file and no problem.

I read a lot of information but nothing interesting in my case.

Thanks,

Youri

1 ACCEPTED SOLUTION
Read only

LukaszPegiel
SAP Champion
SAP Champion
0 Likes
3,556

I know it's trivial but are you saving your file under XLS or XLSX extension? As from you content passed for sure it is XLSX file, and this might be the reason.

11 REPLIES 11
Read only

LukaszPegiel
SAP Champion
SAP Champion
0 Likes
3,557

I know it's trivial but are you saving your file under XLS or XLSX extension? As from you content passed for sure it is XLSX file, and this might be the reason.

Read only

0 Likes
3,556

I saved my file with XLS extension.

I checked the MIME Type and in my case : application/vnd.ms-excel

Read only

0 Likes
3,556

Try with xlsx cause your file is 100% xlsx. And you must see if you have maybe somewhere original name & extension of the attached file.

Read only

0 Likes
3,556

With .xlsx i cannot open the file.

First message in Excel :


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

I click "Yes" and finally :


Excel cannot open ...xlsx because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

I try to consume the Web Service with SoapUI and no problem to open the Excel Attachment.

Read only

0 Likes
3,556

Youri,

have you tried to download it to pc via gui_download to see if xstring works correctly then? If yes that this means the problem lies in open dataset.

Cheers

Łukasz

Read only

0 Likes
3,556

Yes, i tried of course.

With XLSX extension when i try to open with Excel :

First message in Excel :

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

I click "Yes" and finally :

Excel cannot open ...xlsx because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

With XLS extension just one message :


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

But when i see the file content its always the same :

PK     !Û1(òl Ä    [Content_Types].xml ¢  (  ¬”ËnÂ0 E÷•ú ‘·Ub袪* ‹>–-Ré ¸ñ„Xø%ð÷˜‡(¢

6±bûÞ{<òx0jÎ  P9[²~Ñc ØÊIe§%ûš¼å,Ã(¬ ÚY(Ù

...

Thanks

Read only

0 Likes
3,556

And what about the size of the file when you download it by SAP and by SoapUI ? Are they the same?

Read only

0 Likes
3,555

They are the same.

SoapUI:

Name = BinaryFile

Content type = application/vnd.ms-excel

Type = MIME

Size = 14543

Part = BinaryFile

ContentID = BinaryFile

SAP AL11:

Length = 14543

If I open these 2 files (one from SoapUI and one from AL11) in Notepad++, I see the same.

But in Excel only the file from SoapUI is valid.

File from SAP looks like :

Regards,

Youri

Read only

0 Likes
3,555

Try some binary comparision tool like VBinDiff - Visual Binary Diff maybe it will give a hint.

Read only

0 Likes
3,555

The file are note the same, you're right.

I found a great difference with format.

File from SoapUI Format : Unix format

File downloaded from AL11 : Windows format

If I use CG3Y for downloading the file from AS I have no problem.

I can read the xls file without problem.

I think my problem is resolved.

Read only

former_member820263
Discoverer
0 Likes
3,555

How did you resolve this issue?