Documente Academic
Documente Profesional
Documente Cultură
Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner
About
About
Ask a Question Write a Blog Post Login
Shabarish V Nair
more by this author
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 !
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
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.
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.
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.
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
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
thanks Chandra …
it does seem i missed that one
Former Member
Hi Shabarish,
Former Member
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
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
diego,
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3bdc1
4e1-0901-0010-b5a9-a01e29d75a6a
Former Member
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:)
Regards,
Farooq
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
Hi Shabz,
Former Member
Way Back I had the same requirement which was basically reading multiple Excel sheet
in the mail attachment and converting them into xml.
https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=64389779
Thanks,
Sunil Singh
Former Member
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
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
Executed successfully
And the routing rules are also defined . However in the receiver channel is throwing
an error of illegal argument as below
Am i missing something
Thanks in advance
Former Member
Hi Vijay ,
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
Hi Guys,
I am trying to read the xls and xlsx file to convert into Xml file using Apache POI jars.
workbookjava.io.FileInputStream@36f4f861
java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at
com.incture.ExcelToXmlByPOI.transform(ExcelToXmlByPOI.java:80)
But Same code is running fine in NWDS without causing any error.
Thanks
Gourav
Former Member
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
Sitemap Newsletter
https://blogs.sap.com/2009/04/05/excel-files-how-to-handle-them-in-sap-xipi-the-alternatives/ 9/9