Sunteți pe pagina 1din 9

11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner

About
About

 
Ask a Question Write a Blog Post Login

Excel Files – How to handle them in SAP


XI/PI (The Alternatives)
April 5, 2009 | 3,075 Views |

Shabarish V Nair
more by this author

SAP Cloud Platform Integration for process services


excel | jexcel | sap netweaver pi | sap pi | sapmentor

share
0 share tweet share like
0 Follow

Life would have been easy if XI/PI provided us with the option of handling
data of MS Excel files in a standard way. Unfortunately it doesnt !

So how can Excel files be handled in XI/PI?

There are actually quite a few options available for us;

1. Use Conversion Agent – How to Handle Excel Documents with SAP PI

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 1/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

2. Use XSLT Mapping – The specified item was not found.

3. Use JAVA

Its the third option that we will be looking into in this blog.

There are free APIs available to help us read or create an excel file. One
such API is the JExcelAPI

I found it to be a very simple API to use and code. The jar files for building
any project using the JExcel API can be downloaded from here

The solution that I assume is the best would be to code a module. The
module can be coded in such a way so that you can make it generic across
scenarios as per your landscape and requirements.

Lets now look at the design of two scenarios.

a. Read an Excel File

You can use the package jxl to your advantage in this case. The method
getWorkbook(java.io.InputStream is) can be used in the module to read
the workbook. There are various interfaces like sheet and cell that provides
you various methods to access the data.

Once you access the data you can write out the source XML directly from
the module so that it can be used for transformation. If you are lazy, and
dont want to build the XML from your module itself, then make sure you
write out a flat file format from your module and leave the XML conversion
to the MessageTransformBean (Plain2XML), that will be next in chain after
your custom module.

b. Writing an Excel File

Comparing reading to writing excel files, reading is relatively an easy task


you can perform with the API. For writing out an excel file, the API provides
you numerous interfaces and methods that can help you also do the
following if required in a scenario;

1. Formating – Format cells in terms of font, font colour, number and date
formatting

2. You can also edit the cells in terms of assigning background colours,
borders etc.

3. Even formulas can be applied to the excel file

There are two ways you can code your module. The first would be to take
the target XML itself as the input, parse the XML and then convert it to the

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 2/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

required XML format. This would mean you implement a SAX or DOM
parser to help you read data from the XML. The other option is to use the
MessageTransformBean (XML2Plain) first in the chain to create a flat file
format. You can then using String functions in the module to play around
with the payload. I personally prefer this since its quite easy to manipulate
Strings

To create/write Excel files, the package jxl.write should be used. You can
use the method createWorkbook(java.io.OutputStream os) of the
Workbook class in the module. As mentioned earlier, it is also possible to
set font, font colour, background colour, borders etc for the cells.

I have written a sample class which tries to create an excel output that you
can base as a reference while building your custom module. The code also
documents the formatting of cells, just in case your client expects some
‘delicacies’ of that kind

Find the code here – LINK

Note:

There are also other APIs other than JExcel that can be used. Another
widely used API is POI-HSSF and POI-XSSF, part of the Apache POI
project. You can also explore that option, but on a personal note I found the
JExcel API much easier to use.

Alert Moderator

15 Comments
You must be Logged on to comment or reply to a post.

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 3/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

Chandra G

April 6, 2009 at 1:11 am

Read Excel instead of XML through FileAdapter

Shabarish Vijayakumar Post author

April 6, 2009 at 1:18 am

thanks Chandra …
it does seem i missed that one

Felix got to that earlier and i never knew …

Lets hope something new is absorbed from this blog of mine …

Thanks again !!!

Former Member

July 6, 2015 at 7:17 am

Hi Shabarish,

Please help me on below thread…

Excel(.xlsx) to .csv converison in SAP PI XI | SCN

Former Member

April 13, 2009 at 4:04 am

Nice blog buddy,Keep blogging

Regards
chandra dasari(x collegue T-Systems)

Former Member
https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 4/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

April 17, 2009 at 6:57 am

Nice Blog!

But I am begginer in SAP PI/XI and I would like to know how can I implements
modules !!

Thanks in advance
Regards
Diego

Shabarish Vijayakumar Post author

April 17, 2009 at 7:45 pm

diego,

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3bdc1
4e1-0901-0010-b5a9-a01e29d75a6a

that link should help you start !!!

Former Member

August 3, 2009 at 11:06 pm

Hi,

If I am not wrong there is a Blog for reading and writing Excel sheet using API’s (in
Adapter module) is already available on SDN:)

This blogs is very specific to reading/writing Excel sheet in Java.

Regards,
Farooq

Shabarish Vijayakumar Post author

August 3, 2009 at 11:29 pm

yes there is as it was rightly pointed out by Chandravadhana earlier

as i mentioned before … i hope this blog captures more details and will
give the reader a different perspective on the topic …

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 5/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

Former Member

March 6, 2011 at 8:41 pm

Hi Shabz,

Is it necessary for us to custom a new adapter module or is


there a standard Adapter Module for reading of Excel Files.

Former Member

January 22, 2010 at 10:46 am

Way Back I had the same requirement which was basically reading multiple Excel sheet
in the mail attachment and converting them into xml.

For this I had written a Adapter Module

https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=64389779

Thanks,
Sunil Singh

Former Member

September 3, 2012 at 2:40 pm

Hi Vijay ,

I follow your blogs quite often …Good sharings …Well i have come across the same
requirement of read a text file and write into an excel into an http://FTP... i have
created the data types , message types , inbound outbound interfaces .Followed the
same api and mapping class . and the test in the repository is showing java mapping
successful .

Start of test

Call method execute of the application Java mapping com.pi.xi.TextMapping


*** START APPLICATION TRACE ***
Processing message
Processing completed successfully
*** END APPLICATION TRACE ***

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 6/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

Java mapping com/pi/xi/TextMapping completed. (execute() of


com.pi.xi.TextMapping

Executed successfully

And the routing rules are also defined . However in the receiver channel is throwing
an error of illegal argument as below

Message processing failed. Cause:


com.sap.aii.af.ra.ms.api.RecoverableException: The parameter “argument” has
the value “remote:///test/*.xls”, so it contains the character
“remote:///test/*.xls” which is not allowed:
com.sap.exception.standard.SAPIllegalArgumentException: The parameter
“argument” has the value “remote:///test/*.xls”, so it contains the character
“remote:///test/*.xls” which is not allowed

Am i missing something

Thanks in advance

Shabarish Vijayakumar Post author

September 3, 2012 at 3:19 pm

is the excel file being created in the java mapping or a module? if it is in


the java mapping, then check you adapter CC settings. It might have
nothing to do with the java excel api.

Former Member

September 3, 2012 at 6:05 pm

Hi Vijay ,

Thanks for the quick reply …probably i didnt put my


description correctly. i have followed your blog exactly in
using the java excel api . And yes as you said i belive this
is sumting to be checked in adapter settings .should any
file content conversion be used in the sender cc or receiver
cc( file adapter ). Input file is *.txt and output file is *.xls

Thanks

Naresh

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 7/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

Former Member

July 15, 2015 at 10:29 pm

Hi Guys,

I am trying to read the xls and xlsx file to convert into Xml file using Apache POI jars.

I am facing error in OM like:

workbookjava.io.FileInputStream@36f4f861

*** END APPLICATION TRACE ***

LinkageError during appliction Java mapping com/incture/ExcelToXmlByPOI

java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at
com.incture.ExcelToXmlByPOI.transform(ExcelToXmlByPOI.java:80)

It clearly seems like xmlbeans jar is not reflecting in pi .

But Same code is running fine in NWDS without causing any error.

In ESR ,i imported all relevant jars.

Any Idea how to Solve this issue.Please help me…

Thanks

Gourav

Former Member

August 21, 2015 at 11:36 am

Nice Blog. As a beginner in SAP PI, your blogs are very informative and helpful to
me. Thanks. Keep Blogging!!

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 8/9
11/1/2018 Excel Files – How to handle them in SAP XI/PI (The Alternatives) | SAP Blogs

Share & Follow

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Cookie Preferences

Sitemap Newsletter

https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 9/9

S-ar putea să vă placă și