Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Correct formatting of decimals whne donloading data to Excel from BSP

Hi everybody,

I've got a problem with the correct formatting of prices when downloading data from BSP to an Excel file: E.g. '14,67' is displayed properly as '14,67' in Excel, but e.g. '12,50' is displayed as '12,5' or '13,00' as '13'.

The way that was chosen to create this Excel file is (not my decision, I've inherited this topic from my predecessor - as it works 'almost' to the customers expectations I don't want to change the whole work):

After pressing the corresponding link in a BSP page ('View.htm') the same page is processed again. In 'onInitialization' there is the command

navigation->goto_page( 'Export.xls' ).

This opens a new browser window and the user is asked to confirm the download.

The BSP page 'Export.xls' contains in layout basically this:

<html>

<body>

<table>

<tr><td>Preis</td></tr>

<tr><td><%=x_value1%></td></tr>

<tr><td><%=x_value2%></td></tr>

...

</table>

</body>

</html>

x_value1 is defined as string and is filled with e.g. '12.50'.

onManipulation ('Excel.xls'):

call method response->set_header_field

exporting name = 'Content-Disposition'

value = 'attachment; filename=Testprogramm.xls'.

  • Tells the browser to open excel

call method response->set_header_field

exporting name = 'Content-Type'

value = 'application/vnd.ms-excel'.

Is there an easy way to force Excel to display the prices properly?

Thanks for Your help in advance,

Markus

replied

Not with the way that your are creating the Excel File. You would have to use one of two other methods that allow you more interaction with Excel.

First you could use ActiveX (or Office Web Controls) to instantiate Excel and pass the data directly to the cells. This is considerably more difficult to code and requires the use of ActiveX - which many people like to avoid for security reasons.

The other approach is to use the Excel XML format to pass the data to the client. The XML format allows for setting formatting parameters in addition to passing the data. This is what is used internally in Web Dynpro ABAP for exporting ALV tables to Excel. The XML format is documented by Microsoft on their Website. However it is a rather complex XML schema. You can create a sample XML file by opening Excel and formatting it a sample spreadsheet the way you want it. Then do a save as and choose XML. This will give you an idea of the format you would have to create.

However either of these approaches requires a complete redesign of how you creating your Excel file.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question