2016 Feb 09 3:17 PM
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Î P9[²~Ñc ØÊIe§%ûš¼å,Ã(¬ ÚY(Ù
†·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
2016 Feb 09 3:31 PM
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.
2016 Feb 09 3:31 PM
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.
2016 Feb 09 4:25 PM
I saved my file with XLS extension.
I checked the MIME Type and in my case : application/vnd.ms-excel
2016 Feb 09 4:29 PM
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.
2016 Feb 09 5:50 PM
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.
2016 Feb 10 4:41 PM
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
2016 Feb 10 5:00 PM
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
2016 Feb 10 5:09 PM
And what about the size of the file when you download it by SAP and by SoapUI ? Are they the same?
2016 Feb 10 9:09 PM
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
2016 Feb 10 9:25 PM
Try some binary comparision tool like VBinDiff - Visual Binary Diff maybe it will give a hint.
2016 Feb 11 8:55 AM
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.
2022 Oct 19 11:03 AM