Adapter Module (Reading Excel File)

Hi Guys,
I followed the Webblog : Read Excel instead of XML through FileAdapter
For File Adapter Module Development , for reading Excel Sheet.
Deployment all went fine and when i used in my configuration , file is getting picked up but the xml content is not getting displyed , it says not well formated.Below error is shown in the CC Monitor
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
XML document must have a top level element. Error processing resource 'http://pxxxxx:50xxx/mdt/messagecontentservlet?att...
My coding in nwds
          xmldata =   "<?xmlversion="1.0"encoding="UTF-8"?>
                         + "<ns:"+wb.getSheet(0).getCell(0, 0).getContents() +"xmlns:ns=""
                         + wb.getSheet(0).getCell(1, 0).getContents() + "">"
                         + "<Name>"+ wb.getSheet(0).getCell(1, 2).getContents()
                         + "</Name>" +"</ns:" wb.getSheet(0).getCell(0, 0).getContents()">";
Kindly suggest if any
srini
Edited by: Venkateswarlu Srinivas on Jul 4, 2008 2:47 PM

try removing the \n you have added in the string

Similar Messages

  • Problems with Adapter module converting Excel file to XML

    Hi All,
    I have created an adapter moduel to convert the input excel file to XML and have deployed it. While testing we found that there is an extra empty record with empty elements added additionally. Can anyone help on this?
    Below is the convert function used for it.
    public byte[] convert(byte src[],String msgType,String nameSpace) throws Exception
                        String xmldata = "";
                        try
                               ByteArrayInputStream byteArr= new ByteArrayInputStream(src);
                               Workbook wb = Workbook.getWorkbook(byteArr);
                               Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AO: Conversion Started.");
                               xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:"+msgType+" "+"xmlns:ns0=\""+nameSpace+"\">";
                               Cell[] cells ;
                               Cell[] cellNames ;
                               cellNames = wb.getSheet(0).getRow(4);
                               for(int j=5;j<wb.getSheet(0).getRows();j++)
                                       xmldata = xmldata+"<Record>";
                                       cells = wb.getSheet(0).getRow(j);
                                       for(int i=1;i<wb.getSheet(0).getColumns();i++)
                                            xmldata = xmldata+"<"+cellNames<i>.getContents().replaceAll(" ","")+">"+cells<i>.getContents()+"</"+cellNames<i>.getContents().replaceAll(" ","")+">";
                                       xmldata = xmldata+"</Record>";
                                xmldata = xmldata + "</ns0:"+msgType+">";     
                                                            wb.close();
                         catch (Exception e)
                             Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AO: Exception in Convert Method.");
                         return xmldata.getBytes();
    Regards,
    Malini
    Edited by: malini balasubramaniam on Mar 5, 2010 7:28 AM

    Hi,
    xmldata = xmldata+"<Record>";
    cells = wb.getSheet(0).getRow(j);
    for(int i=1;i<wb.getSheet(0).getColumns();i++)
    xmldata = xmldata"<"cellNames<i>.getContents().replaceAll(" ","")">"cells<i>.getContents()"</" ","")">";
    xmldata = xmldata+"</Record>";
    Can u please change this part of code as
    Hi,
    cells = wb.getSheet(0).getRow(j);
    if(cells.size()>0)  
    xmldata = xmldata+"<Record>";
    for(int i=1;i<wb.getSheet(0).getColumns();i++)
    xmldata = xmldata"<"cellNames<i>.getContents().replaceAll(" ","")">"cells<i>.getContents()"</" ","")">";
    xmldata = xmldata+"</Record>";
    Check first if the row is empty...
    im nt sure it is cells.size() or cells.length.. please try both
    Thanks & Regards
    Babu

  • Adapter module to read excel file -java code required for PI 7.1

    Hi PI experts,
    I am working on PI 7.1 SP 08.
    I am trying to develope an adapter module to read excel file
    http://wiki.sdn.sap.com/wiki/display/ABAP/AdapterModuleToReadExcelFilewithMultipleRowsandMultiple+Columns
    but here in this wiki , given java code is for pi 7.0 and it is using jar file from PI 7.0
    I tried with using corresponding PI 7.1 files
    com.sap.aii.af.lib.mod.jar:
    sap.comtcloggingjavaimpl.jar:
    com.sap.aii.af.svc_api.jar:
    com.sap.aii.af.cpa.svc_api.jar:
    com.sap.aii.af.ms.ifc_api.jar:
    jave program is not throwing any error in NWDS but After deploying file on server.
    i am getting this errot in communication channel
    2009-12-15 15:47:08 Information AO: Now calling the Convert Method to convert Excel to XML.
    2009-12-15 15:47:08 Error MP: exception caught with cause javax.ejb.TransactionRolledbackLocalException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file; nested exception is: javax.ejb.EJBException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file; nested exception is: javax.ejb.EJBTransactionRolledbackException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file; nested exception is: javax.ejb.EJBException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file
    since i am not a JAVA expert so i am unable to resolve this error
    if some one has already deployed this module for PI 7.1, then please provide me java code for PI 7.1
    Thanks
    sandeep sharma

    hi,
    please try this:
    obj = inputModuleData.getPrincipalData();
    msg = (Message) obj;
    amk = new MessageKey(msg.getMessageId(),msg.getMessageDirection());
    XMLPayload xpld = msg.getDocument();
    Workbook wb = Workbook.getWorkbook((InputStream) xpld.getInputStream());
    xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:"msgType" ""xmlns:ns0=\""nameSpace+"\">";
    Cell[] cells ;
    Cell[] cellNames ;
    cellNames = wb.getSheet(0).getRow(0);
    for(int j=1;j<wb.getSheet(0).getRows();j++)
    xmldata = xmldata+"<Record>";
    cells = wb.getSheet(0).getRow(j);
    for(int i=0;i<wb.getSheet(0).getColumns();i++)
    xmldata = xmldata"<"cellNames<i>.getContents()">"cells<i>.getContents()"</"cellNames<i>.getContents()+">";
    xmldata = xmldata+"</Record>";
    xmldata = xmldata"</ns0:"msgType+">"; 
    wb.close();
    byte byt[] = xmldata.getBytes();
    xpld.setContent(byt);
    inputModuleData.setPrincipalData(msg);
    Thanks,
    Mayank

  • Customised module for reading Excel files.

    Hi Gurus,
    I have to develop a customsed java module for reading Excel files from PI. I downloaded NWDS 7.31 from following location NWDS Download links - Java Development - SCN Wiki. I have installed it on my local laptop. For developing the module I need following Jar files.
    com.sap.aii.af.ms.svc_api
    com.sap.aii.proxy.svc_api.jar
    com.sap.aii.sec.svc_api.jar
    com.sap.aii.utilxi.server.jar
    com.sap.aii.utilxi.core.jar
    com.sap.xi.mapping.tool.lib_api.jar
    sap.com~tc~bl~txmanagerimpl~plb~impl.jar
    sap.com~tc~je~appcontect_api~API.jar
    com.sap.aii.af.cpa.svc.api
    com.sap.aii.af.lib.mod
    com.sap.aii.af.ms.ifc_api
    com.sap.aii.af.svc_api
    com.sap.xpi.ib.mapping.lib
    1. Where can i get these jar files. I checked these files in my downloaded NWDS 7.31  package, but cold not find them.
    Thanks in advance

    Hi.
    Check this thread.
    Where to get the libraries for XI development - Process Integration - SCN Wiki
    Regards
    Lucho

  • Jar files required to read excel file in SAP PI 7.3.1 sp09 dualstack

    Hi experts,
    I need to read excel file (.xls) using SAP PI and process it to target system. I have read blogs
    and found that there are 2 ways to read an excel file in PI using file adapter.
    1) Developing a custom adapter module
    2) Using XSLT code.
    So in order to develop a custom adapter module, i have followed the following blogs
    **************** - XI - Step-by-step guide to develop Adapter Module to read Excel file
    and
    Excel Files - How to handle them in SAP XI/PI (The Alternatives)
    and
    http://wiki.scn.sap.com/wiki/display/ABAP/Adapter+Module+To+Read+Excel+File+with+Multiple+Rows+and+Multiple+Columns
    I am unable to find the jar files in SAP PI at OS level as per the first blog(think they were obsolete).
    Please let me know
    1) What are the required jar files needed to read excel file and their location
    2) Even if i use the old jar files as mentioned in the first blog can i achieve my requirement
    3) Following this blog Convert incoming XML to Excel or Excel XML – Part 1 - XSLT Way if i apply the same logic at sender side, will it work? Because through case studies i came to know that we cannot read a .xls file using XSLT code. Correct me if i am wrong.
    Looking for your valuable suggestions.
    Regards
    Shilpa

    Hi Shilpa
    Welcome to SCN!
    The blog you refered to might be for previous versions of PI. You can refer to the following two wikis to find out what are the relevant JAR files for PI 7.3 and also how to get them.
    XI libraries for development - Process Integration - SCN Wiki
    Where to get the libraries for XI development - Process Integration - SCN Wiki
    It also looks like for newer versions, you might not need to manually get and add those JAR files into your NWDS project - please refer to the first comment on the blog below. I have not tried it personally as I'm not using the latest NWDS, but you can try that first, and if it does not work, then go get them manually.
    PI 7.4 - Adapter Module Creation using EJB 3.0
    Do note that you should be using the JAR files that is corresponding to your PI server version.
    As for your third question, that does not apply to you. XLS is the older non-XML format, and therefore cannot be read by XLST since it is in binary format.
    Rgds
    Eng Swee

  • Adapter Module for Sender File Adapter to access a Flat file

    Hi,
    We have a scenario where the source is a flat file.I want to develop an Adapter Module to make a small change to every line in the Flat file.
    Now how do we read a flat file in the Adapter Module?Coz the flat file will be converted to XML file by the Standard Adapter Module of the File adapter.
    Please help me out with this.
    Thank you,
    Anu.

    Hi Anu,
    If you are not using Content Conversion option Standard Adapter Module does not convert the Flat file to XML .
    You can directly access the payload as it is in flat file in the Adapter Module and make changes.
    Use the Standard classes ModuleData & moduleContext to fetch the Payload.
    chk this :
    Customized Sender Adapter Module
    XI: Read data from PDF file in Sender Adapter
    regards
    Ganga

  • Error reading excel file using POI.

    Hi ,
    I am having some problem when reading the excel file.
    While reading excel file I am getting error-java.io.IOException: Unable to read entire block; 4 bytes read; expected 512 bytes.
    part of my code:-
    InputStream stream = objFormFile.getInputStream();
    POIFSFileSystem fs = new POIFSFileSystem(stream);//getting above error here.
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    Case 1:
    I download the file on the system ,save it ,and then directly upload it to the system ,I get the above error .
    Case 2:
    It works fine if I download the excel and manually open and save it and then upload it .
    I am using JDK1.4.1 and poi-2.5.1-final-20040804.jar.
    Can any one please help me out for the above problem?
    Edited by: hruday on Jul 31, 2008 3:20 AM

    Instead of using POIFSFileSystem, try to directly create the HSSFWorkbook
    InputStream stream = objFormFile.getInputStream();
    //POIFSFileSystem fs = new POIFSFileSystem( stream );//getting above error here.
    HSSFWorkbook wb = new HSSFWorkbook( stream );

  • How to read Excel file in java

    Respected sir/madam
    I want to read the values from Excel file in Java program. How can I do that. When I searched over the net I came to know that you can treat Excel file as a Database and write the code as u write for making DB connections .
    I did that but i am getting the following error ..can anybody please help..
    This is the code what i have written
    import java.io.*;
    import java.sql.*;
    public class ReadExcelFile {
    Connection c;
    Statement stmnt;
    public void checkABA_Number()
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    c = DriverManager.getConnection("jdbc:odbc:ExcelTest","",""); // ExcelTest is the DSN name
    stmnt = c.createStatement();
    ResultSet rs = stmnt.executeQuery("select * from abadata"); // abadata is my Excel file name
    while(rs.next())
    System.out.println(rs.getString(1)+" "+rs.getString(2));
    }catch(Exception e)
    System.out.println(""+e.toString());
    finally
    try
    stmnt.close();
    c.close();
    catch( Exception e )
    System.err.println( e );
    public static void main(String[] args)
    new ReadExcelFile().checkABA_Number();
    My Excel file starts from the first row and first column and also the first row contains the names of the column.
    It give me the following error..
    java.sql.SQLException: [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'abadata'. Make sure the object exists and that you spell its name and the path name correctly.
    How can I deal with this.?I have properly selected the worksheet while giving the DSN . Is there any versionig problem with Excel or some drivers are in appropriate..and yes i chose Microsoft Excel Driver (.xsl) from ODBC .
    I created System DSN.
    Can anybody please help me with this ? I will be very gratefull for replies
    Thanks in advance

    here is the code to read excel file
    public void readexel(String filename)
    Connection c = null;
    Statement stmnt = null;
    try
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
    c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + filename);
    stmnt = c.createStatement();
    String query = "Select * from [Sheet1$]" ;
    ResultSet rs = stmnt.executeQuery( query );
    while( rs.next() )
    System.out.println( rs.getString(1) );
    catch( Exception e )
    System.err.println( e );
    }

  • Open data set for reading excel file on application server in back ground

    open data set for reading excel file on application server in back ground

    hi Vijay,
    I am afraid you won't be able to read from Excel file on Appl. Server.
    ec

  • Error while reading excel file from application server into internal table.

    Hi experts,
    My requirement is to read an excel file from application server into internal table.
    Hence I have created an excel file fm_test_excel.xls in desktop and uploaded to app server using CG3Z tcode (as BIN file type).
    Now in my program I have used :
    OPEN DATASET v_filename FOR INPUT IN text mode encoding default.
    DO.
    READ DATASET v_filename INTO wa_tab.
    The statement OPEN DATASET works fine but I get a dump (conversion code page error) at READ DATASET statement.
    Error details:
    A character set conversion is not possible.
    At the conversion of a text from codepage '4110' to codepage '4103':
    - a character was found that cannot be displayed in one of the two
    codepages;
    - or it was detected that this conversion is not supported
    The running ABAP program 'Y_READ_FILE' had to be terminated as the conversion
    would have produced incorrect data.
    The number of characters that could not be displayed (and therefore not
    be converted), is 445. If this number is 0, the second error case, as
    mentioned above, has occurred.
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_SY_CONVERSION_CODEPAGE', was not
    caught and
    therefore caused a runtime error.
    The reason for the exception is:
    Characters are always displayed in only a certain codepage. Many
    codepages only define a limited set of characters. If a text from a
    codepage should be converted into another codepage, and if this text
    contains characters that are not defined in one of the two codepages, a
    conversion error occurs.
    Moreover, a conversion error can occur if one of the needed codepages
    '4110' or '4103' is not known to the system.
    If the conversion error occurred at read or write of  screen, the file
    name was '/usr/sap/read_files/fm_test_excel.xls'. (further information about
    the file: "X 549 16896rw-rw----201105170908082011051707480320110517074803")
    Also let me know whether this is the proper way of reading excel file from app server, if not please suggest an alternative .
    Regards,
    Karthik

    Hi,
    Try to use OPEN DATASET v_filename FOR INPUT IN BINARY mode encoding default. instead of OPEN DATASET v_filename FOR INPUT IN text mode encoding default.
    As I think you are uploading the file in BIN format to Application server and trying to open text file.
    Regards,
    Umang Mehta

  • Java API for reading Excel Files.

    Hi,
    Can you please suggest me any api for reading excel files.
    Right now i am using jxl.jar for this purpose but i am searching for an open source java api better than this.
    Whether POI gives better than this ?
    Thanks,
    Amit Shah.

    Can you please suggest me any api for reading excel
    files.
    Right now i am using jxl.jar for this purpose
    but i am searching for an open source java api better
    than this.
    Whether POI gives better than this ?i don't know about jxl but poi has several features which an excel can contain and it has been vastly improved in the past few versions.

  • Read Excel file path in WD

    Hi,
    We want to read a excel file. For that we are using file upload UI element and HSSF POI to read excel file. The code to read the excel file is working fine in standalone. In standalone we are hardcoding the file path. But in WD application, we are not hard coding it.
    We are using following code to supply the file name to HSSF code through  file upload UI:
    try
             InputStream in = new FileInputStream(wdContext.currentContextElement  
                                               ().getFileResource());
             wdComponentAPI.getMessageManager().reportSuccess("IN "+in);
             HSSFWorkbook wb  = new HSSFWorkbook(in);
    catch (Exception e)
         wdComponentAPI.getMessageManager().reportSuccess("ERROR in HSSF");
    Where FileResource is a context variable binded with property "data" of FileUpload UI element.
    Now, the problem is that the excel file is not getting read. We are getting ERROR in HSSF message.
    Please help in reading the file path.
    Regards,
    Vaibhav

    Hi,
       Try this:
    InputStream in = wdContext.currentContextElement().getFileResource().read(false);
    Regards,
    Satyajit.

  • Adapter Module Filename in File Receiver Channel

    Hi All,
    is it possible to set the Filename in File Receiver Adapter from Adapter Module?
    I know that it is possible to read the data      
    Channel ch = new Channel(moduleContext.getChannelID());
    path = ch.getValueAsString("file.targetDir");
    I Need to set the filename in Adapter Module, using of Payload is not possible because Payload is not xml.
    Dynamic Parameters in Message Header is not possible because it is an multi mapping process an i need dynamic Filename for each Part
    payload after mapping is like
    MainDocument
    SubMainDocument
    MainDocument
    SubMainDocument
    i need special Name for each SubMainDocument in FileReceiverAdapter
    regards
    ralf

    Hello Stefan,
    interface mapping is an mapping  like this:
    outbound_interface => Inbound_Interface1
                                 => Inbound_Interface2
                                => Inbound_Interface3
    in sxmb_moni this looks like this
    Soap_Header
    Soap_Body
    Payloads
         =>MainDocument ( application/xml )
        => SubMainDocument ( text/xml )
         =>MainDocument ( application/xml )
        => SubMainDocument ( text/xml )
    First SubMainElement is routing to FileReceiverAdapeter A   where Filename has to be like "NameA%nr%"
    second SubMainElement is routing to FileReceiverAdapeter B   where Filename has to be like "NameB%nr%" 
    %nr% is som value from the Payload.
    Payload is not xml  because using of Conversion Argent!!
    I Think there is only one Dynamic in Header for all subelements, i have test it!
    ralf

  • Adapter module to enhance File adapter

    Hey guys
    i need a small clarification regarding adapter modules.
    is it possible via adapter modules to enhance the File adapter to such an extent that it can deliver files to two separate systems in separate landscapes.
    i know i can design one more receiver determination and can also use Run OS command options,but modules in general give better performance compared to others so just wan't to explore a little bit more about them.
    Thanx
    Aamir

    Hey Aamir,
    yeah, they do take a lot of resources, but that's how XI was built to work.
    What you're trying to do is a workaround and may not get support from SAP.
    If I have understood right, you still wanna maintain the endpoint connection data in the communication channels but want to acces them directly without going through the technical routing pipeline, is that so?
    If that's it, I'm sorry but I cannot help you any further.
    The only way I know of accessing adapters without going throught technical routing is by using lookup API (RFC, JDBC, Soap) but it is not intended for endpoint scenarios (insert, update etc), mainly for simple read (lookups).
    If maintaining the connection data outside adapters is not a concern, you could try to create the connections directly in Java code, inside java proxies.
    Regards,
    Henrique.

  • Adapter module that dumps file to XI file directory

    I am given a task to find a way of backing up files the simpliest way. Currently, our config is in a scenario where there are 2 receiver, the receiving system (SAP) and the file backup (File adapter). I would want to reduce the config requirements by eliminating the file backup objects. And I am thinking of doing this by creating an adapter module to be included in the sender adapter.
    Another idea I could think of is the adapter module calls upon the file comm channel to do the file backup.
    The purpose of this research is to reduce object transport time and the mistakes the transport guys are doing on the file comm ch reconfiguration.
    To those who have experiences with adapter module development, is this idea feasible?

    Hi Jai,
    Thanks for your reply. That is the 2nd option I have in case the 1st one isnt possible.
    To further elaborate,
    Current config:
    we have two AS2 comm channels (sender and receiver) managing the connection with our external partners.
    File comm channels to backup the files we send and receive.
    The problem:
    We are having problems with the transport guys as they often make mistake on reconfiguring the file comm channel during transport.
    Requirements:
    Reduce object creation and tranport time.
    Solution proposal 1:
    The idea is to remove all existing objects related to file back up and have all the file back ups done by the adapter module. And this adapter module would become part of the as2 comm channels module processes.
    Hope this clarifies things more.

Maybe you are looking for

  • Data Validation - a feature that Numbers really needs.

    Right now, the newly purchased Numbers app for iPad/iPhone is little more than a crippled document viewer for me because numbers doesn't support 'data validation' (as implemented in excel). Its not a hard concept and likely utilized in a LOT of sprea

  • Purchase Orders Per Project Report

    Is a report in 4.6 that will list all purchase orders assigned to a project and give the total order value, rather than a quantity and item price. I currently use ME2J - the report prints the PO, vendor and each line item with qty @ each price but do

  • Time Frame for Costing

    Hi Can any one tell me "What is the time frame for configuring the complete product costing" and majority of the events and its time consumption. thanks in advance. regards Adi

  • ANNOYING ERROR MESSAGE IN SYSTEM PREFERENCES!!! PLEASE HELP...

    When I open System Preferences and click on the Network Settings icon, I get an error message that says "Your network settings have been changed by another application." It just gives the option to click "OK," but after I click "OK" it just keeps pop

  • Generic DataReader FetchSize property

    Hi, Does DataReader FetchSize property, available with ODP.NET provider, exist for other provider ? If I want to make a generic class to access datas, how can I implement specifics properties of each provider like FetchSize in Oracle ? (excuse me for