Read a excel file and split its sheets to seperate file ?

Dear all :
How to split a excel file into several file, each have one sheet.my code is as below,thanks:
import org.apache.poi.hssf.usermodel.*;
import java.io.*;
import java.util.*;
import org.apache.poi.poifs.filesystem.*;
public class Extractxls {
public static void main(String[] args) throws Exception
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));
HSSFWorkbook wb = new HSSFWorkbook(fs);
int sheetCount = wb.getNumberOfSheets();
System.out.println(sheetCount);
try {
     while(sheetCount > 0) {
     sheetCount--;
     HSSFWorkbook wb1 = new HSSFWorkbook();
     HSSFSheet s = wb1.createSheet();
     String sheetName = wb.getSheetName(sheetCount);
     HSSFSheet sheet = wb.getSheet(sheetName);
//     HSSFSheet sheet = wb.getSheetAt(sheetCount);
     System.out.println(sheet.toString());
     s = sheet;
FileOutputStream fileOut = new FileOutputStream("atest" + sheetCount + ".xls");
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
     System.err.println("Error: " + e.getMessage());
} catch (Exception e) { e.toString();}

The HSSFWorkbook class is part of the POI project:
http://jakarta.apache.org/poi/
Regards,
Dave Gilbert
JFreeChart Project Leader
I understand poi porject, my problem is that POI can not read a excel file and split its sheets into seperate file (each have one sheet) ?Does any one know how to do it.

Similar Messages

  • How to  read from excel file and write it using implicit jsp out object

    our code is as below:Please give us proper solution.
    we are reading from Excel file and writing in dynamicaly generated Excel file.it is writing but not as original excel sheet.we are using response.setContentType and response.setHeader for generating pop up for saveing the original file in to dynamically generated Excel file.
    <%@ page contentType="application/vnd.ms-excel" %>
    <%     
         //String dLoadFile = (String)request.getParameter("jspname1");
         String dLoadFile = "c:/purge_trns_nav.xls" ;
         File f = new File(dLoadFile);
         //set the content type(can be excel/word/powerpoint etc..)
         response.setContentType ("application/msexcel");
         //get the file name
         String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
         //set the header and also the Name by which user will be prompted to save
         response.setHeader ("Content-Disposition", "attachment;     filename="+name);
         //OPen an input stream to the file and post the file contents thru the
         //servlet output stream to the client m/c
              FileInputStream in = new FileInputStream(f);
              //ServletOutputStream outs = response.getOutputStream();
              int bit = 10;
              int i = 0;
              try {
                        while (bit >= 0) {
                        bit = in.read();
                        out.write(bit) ;
    } catch (IOException ioe) { ioe.printStackTrace(System.out); }
              out.flush();
    out.close();
    in.close();     
    %>

    If you want to copy files as fast as possible, without processing them (as the DOS "copy" or the Unix "cp" command), you can try the java.nio.channels package.
    import java.nio.*;
    import java.nio.channels.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    class Kopy {
         * @param args [0] = source filename
         *        args [1] = destination filename
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                System.err.println ("Syntax: java -cp . Kopy source destination");
                System.exit(1);
            File in = new File(args[0]);
            long fileLength = in.length();
            long t = System.currentTimeMillis();
            FileInputStream fis = new FileInputStream (in);
            FileOutputStream fos = new FileOutputStream (args[1]);
            FileChannel fci = fis.getChannel();
            FileChannel fco = fos.getChannel();
            fco.transferFrom(fci, 0, fileLength);
            fis.close();
            fos.close();
            t = System.currentTimeMillis() - t;
            NumberFormat nf = new DecimalFormat("#,##0.00");
            System.out.print (nf.format(fileLength/1024.0) + "kB copied");
            if (t > 0) {
                System.out.println (" in " + t + "ms: " + nf.format(fileLength / 1.024 / t) + " kB/s");
    }

  • How can one  read a Excel File and Upload into Table using Pl/SQL Code.

    How can one read a Excel File and Upload into Table using Pl/SQL Code.
    1. Excel File is on My PC.
    2. And I want to write a Stored Procedure or Package to do that.
    3. DataBase is on Other Server. Client-Server Environment.
    4. I am Using Toad or PlSql developer tool.

    If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
    1. Get your DBA to create directory object in oracle using the following command:
    create directory TEST_DIR as ‘directory_path’;
    Note: This directory is on the server.
    2. Grant read,write on directory directory_object_name to username;
    You can find out the directory_object_name value from dba_directories view if you are using the system user account.
    3. Logon as the user as mentioned above.
    Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
    function getData(p_filename in varchar2,
    p_filepath in varchar2
    ) RETURN VARCHAR2 is
    input_file utl_file.file_type;
    --declare a buffer to read text data
    input_buffer varchar2(4000);
    begin
    --using the UTL_FILE in built package
    input_file := utl_file.fopen(p_filepath, p_filename, 'R');
    utl_file.get_line(input_file, input_buffer);
    --debug
    --dbms_output.put_line(input_buffer);
    utl_file.fclose(input_file);
    --return data
    return input_buffer;
    end;
    Hope this helps.

  • Read an excel file and convert to a 1-D array of long, 32-bit integer?

    My vi right now reads an column of numbers as a 1-D array, but I need to input the numbers manually, and for what I'm trying to do, there could be anywhere between 100 to 500 numbers to input. I want the vi to be able to read the excel file and use that column of numbers for the rest, which the data type is long (32-bit integer).
    I have an example vi that is able to get excel values, but the output data type is double (64-bit real).
    I need to either be able to convert double(64-bit real) data to long (32-bit integer), or find another way to get the values from the excel file.

    Just to expand on what GerdW is saying.  There are many programs that hold exclusive access to a file.  So if a file is opened in Excel, the LabVIEW cannot access the file.
    What is the exact error code?  Different error codes will point to different issues.
    Make sure the csv file is exactly where you think it is and LabVIEW is pointing to the right place.  (I'm just going through stupid things I have done)
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Use labview to read an Excel file to some control and add a checkbox for each row

      As the subject say,I need to use labview to read an excel file,and show it in some control,such as mclb;then ,I should add an checkbox for each row,enable me to choose the row i want.What should I do ? Many Thanks.
    Solved!
    Go to Solution.

    Hi,
    to answer your question:
    - read an excel file
    - show it in some control, such as a MCLB
    - add an checkbox for each row
    - choose the row you want
    Hint to make it easier: I wouldn't use checkboxes, as the MCLB already allows to select rows by mouseclick…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Read an EXCEL file from application server

    Hi all
    I have to read an excel file from applicatin sever and update my custom tablels.
    The problem is when the file is uploaded into the application server .
    the fields it has are
    name age gender
    xyz    67  m.
    when seeing the file using al11 tcode :
    its showing the following:
    ###&#2161;##################>#######################################################################################################################
    #################################################################O#b#j#I#n#f#o################################################################
    How do i read this and put in my internal table
    Pleaes help.
    Thanks and Regards,

    Hi,
    I am using ECC6.0.
    I think the EXCEL file is stored in compressed format to save space.
    Please let me know how to decompress etc.
    I tried using the function moduel
    text_convert_xls_to_sap.
    How do I pass the parameter to I_filename.
    Regards,

  • Read an excel file using JSP in MII 12.1

    Hi,
    I want to read an excel file using jsp page. I dont want to use the UDS or ODBC for connecting to excel.
    I am trying to use org.apache.poi to read the excel file in jsp page.
    While running, its showing a compilation error "package org.apache.poi.hssf.usermodel does not exist"
    I have the jar files for it, where do we need to upload it so that jsp page works.
    Thanks a lot
    Regards,
    Neha Maheshwari

    The user doesn't want to save the excel file in server.
    I want to upload file and save its contents in database.
    I have the code to read and save excel data in database but not able to get the location to deploy the jar file.
    In general, if we are creating a jsp page in MII workbench which is using some jar file.
    Whats the location to upload this jar file so that the jsp page works correctly?

  • Getting an Error after reading a excel file

    hi
    I am reading a excel file using POI
    my code is
    package businessLogic;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
    import org.apache.poi.hssf.eventusermodel.HSSFListener;
    import org.apache.poi.hssf.eventusermodel.HSSFRequest;
    import org.apache.poi.hssf.record.BOFRecord;
    import org.apache.poi.hssf.record.BoundSheetRecord;
    import org.apache.poi.hssf.record.LabelSSTRecord;
    import org.apache.poi.hssf.record.NumberRecord;
    import org.apache.poi.hssf.record.Record;
    import org.apache.poi.hssf.record.RowRecord;
    import org.apache.poi.hssf.record.SSTRecord;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    * This example shows how to use the event API for reading a file.
    public class EventExample implements HSSFListener
    private SSTRecord sstrec;
    * This method listens for incoming records and handles them as required.
    * @param record The record that was found while reading.
    public void processRecord(Record record)
         try
    switch (record.getSid())
    // the BOFRecord can represent either the beginning of a sheet or the workbook
    case BOFRecord.sid:
    BOFRecord bof = (BOFRecord) record;
    if (bof.getType() == bof.TYPE_WORKBOOK)
    System.out.println("Encountered workbook");
    // assigned to the class level member
    } else if (bof.getType() == bof.TYPE_WORKSHEET)
    System.out.println("Encountered sheet reference");
    break;
    case BoundSheetRecord.sid:
    BoundSheetRecord bsr = (BoundSheetRecord) record;
    System.out.println("New sheet named: " + bsr.getSheetname());
    break;
    case RowRecord.sid:
    RowRecord rowrec = (RowRecord) record;
    System.out.println("Row found, first column at " + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol());
    break;
    case NumberRecord.sid:
    NumberRecord numrec = (NumberRecord) record;
    System.out.println("Cell found with value " + numrec.getValue()+ " at row " + numrec.getRow() + " and column " + numrec.getColumn());
    break;
    // SSTRecords store a array of unique strings used in Excel.
    case SSTRecord.sid:
    sstrec = (SSTRecord) record;
    for (int k = 0; k < sstrec.getNumUniqueStrings(); k++)
    System.out.println("String table value " + k + " = " + sstrec.getString(k));
    break;
    case LabelSSTRecord.sid:
    LabelSSTRecord lrec = (LabelSSTRecord) record;
    System.out.println("String cell found with value " + sstrec.getString(lrec.getSSTIndex()));
    break;
         catch(Exception ex)
    * Read an excel file and spit out what we find.
    * @param args Expect one argument that is the file to read.
    * @throws IOException When there is an error processing the file.
    public static void main(String[] args) throws IOException
    // create a new file input stream with the input file specified
    // at the command line
         try
              FileInputStream fin = new FileInputStream("C:/FTERPending/FTER format.xls");
              // create a new org.apache.poi.poifs.filesystem.Filesystem
              POIFSFileSystem poifs = new POIFSFileSystem(fin);
              //      get the Workbook (excel part) stream in a InputStream
              InputStream din = poifs.createDocumentInputStream("Workbook");
              // construct out HSSFRequest object
              HSSFRequest req = new HSSFRequest();
              // lazy listen for ALL records with the listener shown above
              req.addListenerForAllRecords(new EventExample());
              // create our event factory
              HSSFEventFactory factory = new HSSFEventFactory();
              //      process our events based on the document input stream
              factory.processEvents(req, din);
              // once all the events are processed close our file input stream
              fin.close();
              // and our document input stream (don't want to leak these!)
              din.close();
              System.out.println("done.");
         catch(Exception ex)
    It prints correctly the output at the console and after that it throws an exception as
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
         at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.genericProcessEvents(HSSFEventFactory.java:183)
         at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processEvents(HSSFEventFactory.java:101)
         at businessLogic.EventExample.main(EventExample.java:103)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
         at java.lang.System.arraycopy(Native Method)
         at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
         at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
         at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
         at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
         at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
         at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
         ... 8 more
    I am not getting why this exception is cming
    can anyone help me pls reply

    Does your Excel file has the "AutoFilter" activated?
    If that is the problem, you have here a solution for reading a file with AutoFilter : http://article.gmane.org/gmane.comp.jakarta.poi.user/4690

  • Problem in reading the excel file path in WINDOWs machine from UNIX environ

    Hello friends,
    My requirement is to read each row of the excel sheet and sent that row to the database. I have implemented it by using jxl and apache poi framework. locally in my WINDOWS machine it is working fine..
    But when i deploy the code in UNIX machine. My application runs on a Unix server , trying to read the excel file in WINDOWS environment. I am not able to retrieve the file path. for ex : C:\Documents and Settings\sabbanik\My Documents\KARUNAKAR\excel.xls
    I am getting error in this line
    workbook = Workbook.getWorkbook(filepath)
    Error message : input file not found.
    Thanks in advance..

    You said: I am getting error in this line workbook = Workbook.getWorkbook(filepath) >
    Based on this, I will assume you are trying to use OLE to access information about the Excel file. As mentioned by Andreas, your code will be executing on the server (Unix) and since Excel isn't on the server (and cannot be) an error will result. OLE can only be used in Windows environments (client or server). To access client side OLE calls and content, you need a java bean and Excel installed on the client machine. Oracle provides WebUtil as an option to writing your own Java Bean. To use this, you will need to be running Forms 10.1.2 or newer. Details can be found here along with a demo:
    http://www.oracle.com/technetwork/developer-tools/forms/webutil-090641.htm

  • Store data in mysql after reading from excel files

    i am trying to make o program where i will read the data from excel files and i will store them in a database. I am using eclipse as editor and mySQL. I am using APACHE POI to read the excel files and JDBC for the connection. The excel files have the structure as shown below:
    ID NAME SALARY STREET
    321 TIM 1254 14 avenue
    121 PAUL 1265 28h oktovriou
    432 NICK 4521 papaflessa
    I have of course plenty of such files which contains many more rows and columns. The purpose of my program is to read the data, create table named as the name of the excel file and the fields of each table to be the first rows of the excel file. Afterwards the values will be the rest data of the excel file. In the code below i have managed to read them, show the data in the console. Afterwrds i am trying to call a database with JDBC but there i have problem when i create the table.
    try
    String[] allFields;
    String createTableStr = "CREATE TABLE" + createTableStr
    + "(" + org.apache.commons.lang3.StringUtils.join(allFields,
    ",") + ")";
    Could anyone help me?
    Thank you in advance!:)
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.commons.lang3.StringUtils;
    import org.apache.poi.ss.usermodel.Cell;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class exam1 {
    @SuppressWarnings({ "unchecked", "unchecked" })
    static void main (String[] args) throws Exception {
    String filename = "C:\\Users\\Efi\\Documents\\test5.xls";
    List sheetData = new ArrayList();
    FileInputStream fis = null;
    try {
    fis = new FileInputStream(filename);
    HSSFWorkbook workbook = new HSSFWorkbook(fis);
    HSSFSheet sheet = workbook.getSheetAt(0);
    Iterator rows = sheet.rowIterator();
    while (rows.hasNext()) {
    HSSFRow row = (HSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    List data = new ArrayList();
    while (cells.hasNext()) {
    HSSFCell cell = (HSSFCell) cells.next();
    data.add(cell);
    sheetData.add(data);
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (fis != null) {
    fis.close();
    showExcelData(sheetData);
    @SuppressWarnings("unused")
    HashMap<String, String> tableFields = new HashMap();
    for (int i=0; i<sheetData.size();i++){
    List list = (List) sheetData.get(i);
    for (int j=0; j<list.size(); j++){
    Cell cell = (Cell) list.get(j);
    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
    System.out.print(cell.getNumericCellValue());
    }else if(cell.getCellType()==Cell.CELL_TYPE_STRING) {
    System.out.print(cell.getRichStringCellValue());
    } else if(cell.getCellType()==Cell.CELL_TYPE_BOOLEAN) {
    System.out.print(cell.getBooleanCellValue());
    if (j < list.size() - 1) {
    System.out.print(", ");
    private static void showExcelData(List sheetData) {
    @SuppressWarnings("unchecked")
    private HashMap parseExcelData (List sheetData){
    HashMap<String,Integer> tableFields = new HashMap();
    List list = (List) sheetData.get(0);
    for (int j=0; j<list.size(); j++){
    Cell cell=(Cell) list.get(j);
    tableFields.put(cell.getStringCellValue(),cell.getCellType());
    return tableFields;
    @SuppressWarnings({ "unchecked", "unchecked", "unchecked", "unchecked", "unused" })
    private String getCreateTable(String tablename, HashMap<String, Integer> tableFields){
    Iterator iter = tableFields.keySet().iterator();
    String str="";
    String[] allFields = new String[tableFields.size()];
    int i = 0;
    while (iter.hasNext()){
    String fieldName = (String) iter.next();
    Integer fieldType=(Integer)tableFields.get(fieldName);
    switch (fieldType){
    case Cell.CELL_TYPE_NUMERIC:
    str=fieldName + "INTEGER";
    break;
    case Cell.CELL_TYPE_STRING:
    str= fieldName + "VARCHAR(255)";
    break;
    case Cell.CELL_TYPE_BOOLEAN:
    str=fieldName + "INTEGER";
    break;
    allFields[i++]= str;
    return str;
    public Connection getConnection() throws SQLException {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/kainourgia","root", "root");
    Statement stmt = con.createStatement();
    try
    System.out.println( "Use the database..." );
    stmt.executeUpdate( "USE kainourgia;" );
    catch( SQLException e )
    System.out.println( "SQLException: " + e.getMessage() );
    System.out.println( "SQLState: " + e.getSQLState() );
    System.out.println( "VendorError: " + e.getErrorCode() );
    try
    String[] allFields;
    String createTableStr = "CREATE TABLE" + createTableStr
    + "(" + org.apache.commons.lang3.StringUtils.join(allFields,
    *",") + ")";*
    System.out.println( "Create a new table in the database" );
    stmt.executeUpdate( createTableStr );
    catch( SQLException e )
    System.out.println( "SQLException: " + e.getMessage() );
    System.out.println( "SQLState: " + e.getSQLState() );
    System.out.println( "VendorError: " + e.getErrorCode() );
    catch( Exception e )
    System.out.println( ((SQLException) e).getSQLState() );
    System.out.println( e.getMessage() );
    e.printStackTrace();
    return null;
    }

    Please don't multipost! Also crossposted: http://www.java-forums.org/jdbc/71612-store-data-mysql-after-reading-excel-files.html
    Mod: I'm locking this thread.

  • How to read an excel file in webdynpro application

    Hello Experts,
    Can someone please tell me how to read an excel file in a webdynpro application?
    There is a tutorial for how to write contect into an excel, but i want to read the excel.
    Can someone help please !!
    Thanks and Kind regards,
    G.Singh.

    Hello Experts,
    I have done all the given above.
    I want to read a excel file from KM. My code is as below
    ResourceContext resourceContext = buildResourceContext();
    IResourceFactory resourceFactory = ResourceFactory.getInstance();
    RID pathRID = RID.getRID("/documents/ExcelReport.xls");     
    IResource resource =     resourceFactory.getResource(pathRID, resourceContext);
    Workbook wb = Workbook.getWorkbook(resource.getURI().getPath());
    Sheet sh = wb.getSheet(0);
    int columns = sh.getColumns();
    int rows = sh.getRows();
    wdComponentAPI.getMessageManager().reportSuccess(" Rows: " + rows);
    wdComponentAPI.getMessageManager().reportSuccess(" Columns: " + columns);
    This does not give me the excel file form the KM
    Can you please just what i can do at this point?
    Kind Regards,
    G Singh.

  • Reading heavy excel files page wise using OpenXML

    Hi, 
    I am using OpenXML to read heavy excel files, but I am using paging to read files because I have to process data and show in Grid on frontend. 
    Problem here is for reading every page of 10000 records its time is increasing. 
    First Page = 38397 Milliseconds
    Second Page = 81910 MS
    Third page =117923 MS
    Fourth page =150142 MS
    Any body has any clue...

    Hi,
    >> I am using paging to read files <<
    Are you sure the extra time is used to read the data from Excel files or
    show the data in Grid? If not, I suggest you checking that.
    If the issue is related to reading data from Excel files by Open XML SDK, would you mind sharing some sample code for us to know how you read the files and troubleshoot?
    If the extra time is used for showing data, I suggest you posting in the proper forum based on your developing language for more effective responses.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • .exe reading from Excel files

    Hi everybody,
    I know similar questions have been asked lots of times but while searching the forum didn't find an anwer to my problem.
    I created an exe file (using exe4j) of a java application which reads form Excel files. Although it works when I run it from my editor, when running the exe file it cant find the Excel file. More specifically I have this error:
    "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
    In order to read from excel files I use POI. I used it so as not to use ODBC driver and make it possible to run in every computer. When adding the driver, the exe works.Do you know a way to make it work without having to install the Driver?
    Thanks in Advance

    You need database drivers to read excel spread sheets?
    Also, why did you make it an exe? just jar it and be done with it.

  • Download read only excel file

    Hi Experts,
    How to download a READ ONLY excel file to workstation (local Machine).

    Hi kaleemullah,
    Steps to create a BDC program.
    1. Create an internal table with fields same as Excel sheet fields.
    2. Declare an internal table with BDCDATA table to store the BDC recording.
    3. Declare an internal table with BDCMSGCOL to store the error messages after
    the execution of the BDC.
    4. Write the code using the fun. module ALSM_EXCEL_TO_INTERNAL_TABLE
    to upload the data from the excel sheet.
    5. loop that internal table and write the Subroutines to fill the internal table
    BDCDATA with the recording of a specified Transaction Code.
    6. Using Call Transaction execute the BDC recording.
    7. Check Sy-subrc = 0 and store the error messages in the internal table.
    8. If you want you can pass those error records to a session using the SESSION method.
    Here is an example of a BDC program, but this program is from a text file. Change the function module WS_UPLOAD with ALSM_EXCEL_TO_INTERNAL_TABLE
    to upload an excel and write the program with your BDC recording. You can do recording using t-code SHDB.
    Sample Program:
    REPORT ZRAJ_DATASET_XD01 NO STANDARD PAGE HEADING LINE-SIZE 132
    LINE-COUNT 60
    MESSAGE-ID Z00.
    Table/Structure declarations. *
    TABLES : KNA1. "Customer master
    Constants declarations. *
    CONSTANTS : C_MODE VALUE 'N',
    C_UPDATE VALUE 'S',
    C_X VALUE 'X',
    C_SESS TYPE APQI-GROUPID VALUE 'ZCUSTOMER', "Session Name
    C_XD01 LIKE TSTC-TCODE VALUE 'XD01'.
    Variable declarations. *
    DATA : V_FNAME(15) VALUE SPACE, " Name of file to be created
    V_FAILREC TYPE I, " No of failed records
    V_MSG(255), " Message Text
    V_ERRREC TYPE I, " No of failed records
    V_LINES TYPE I. " No of records
    *-- FLAG DECLARATIONS
    DATA : FG_DATA_EXIST VALUE 'X', " Check for data
    FG_SESSION_OPEN VALUE ' '. " Check for Session Open
    Structures / Internal table declarations *
    *-- Structure to hold BDC data
    TYPES : BEGIN OF T_BDCTABLE.
    INCLUDE STRUCTURE BDCDATA.
    TYPES END OF T_BDCTABLE.
    *-- Structure to trap BDC messages
    TYPES : BEGIN OF T_MSG.
    INCLUDE STRUCTURE BDCMSGCOLL.
    TYPES : END OF T_MSG.
    *-- Structure to trap ERROR messages
    TYPES : BEGIN OF T_ERR_MSG,
    MESSAGE(255),
    END OF T_ERR_MSG.
    *--Internal table to store flat file data
    DATA:BEGIN OF IT_KNA1 OCCURS 0,
    KUNNR LIKE KNA1-KUNNR,
    KTOKD LIKE T077D-KTOKD,
    NAME1 LIKE KNA1-NAME1,
    SORTL LIKE KNA1-SORTL,
    ORT01 LIKE KNA1-ORT01,
    PSTLZ LIKE KNA1-PSTLZ,
    LAND1 LIKE KNA1-LAND1,
    SPRAS LIKE KNA1-SPRAS,
    LZONE LIKE KNA1-LZONE,
    END OF IT_KNA1.
    *-- Internal table to hold BDC data
    DATA: IT_BDCDATA TYPE STANDARD TABLE OF T_BDCTABLE WITH HEADER LINE,
    *-- Internal Table to store ALL messages
    IT_MSG TYPE STANDARD TABLE OF T_MSG WITH HEADER LINE,
    *-- Internal Table to store error messages
    IT_ERR_MSG TYPE STANDARD TABLE OF T_ERR_MSG WITH HEADER LINE.
    Selection Screen. *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    PARAMETERS : P_FLNAME(15) OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS : R_LIST RADIOBUTTON GROUP GRP1.
    SELECTION-SCREEN COMMENT 5(20) TEXT-003.
    PARAMETERS : R_SESS RADIOBUTTON GROUP GRP1.
    SELECTION-SCREEN COMMENT 30(20) TEXT-004.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2.
    Event:Initialization *
    INITIALIZATION.
    AT Selection Screen. *
    AT SELECTION-SCREEN.
    Event: Start-of-Selection *
    START-OF-SELECTION.
    V_FNAME = P_FLNAME.
    PERFORM GET_DATA.
    PERFORM GENERATE_DATASET.
    Event: End-of-Selection *
    END-OF-SELECTION.
    IF FG_DATA_EXIST = ' '.
    MESSAGE I010 WITH TEXT-009.
    EXIT.
    ENDIF.
    PERFORM GENERATE_BDCDATA.
    PERFORM DISPLAY_ERR_RECS.
    Event: top-of-page
    TOP-OF-PAGE.
    FORM DEFINITIONS *
    *& Form get_data
    Subroutine to get the data from mard
    --> p1 text
    <-- p2 text
    FORM GET_DATA.
    CALL FUNCTION 'UPLOAD'
    EXPORTING
    CODEPAGE = ' '
    FILENAME = 'C:\XD01.TXT'
    FILETYPE = 'DAT'
    ITEM = ' '
    FILEMASK_MASK = ' '
    FILEMASK_TEXT = ' '
    FILETYPE_NO_CHANGE = ' '
    FILEMASK_ALL = ' '
    FILETYPE_NO_SHOW = ' '
    LINE_EXIT = ' '
    USER_FORM = ' '
    USER_PROG = ' '
    SILENT = 'S'
    IMPORTING
    FILESIZE =
    CANCEL =
    ACT_FILENAME =
    ACT_FILETYPE =
    TABLES
    DATA_TAB = IT_KNA1
    EXCEPTIONS
    CONVERSION_ERROR = 1
    INVALID_TABLE_WIDTH = 2
    INVALID_TYPE = 3
    NO_BATCH = 4
    UNKNOWN_ERROR = 5
    GUI_REFUSE_FILETRANSFER = 6
    OTHERS = 7
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF IT_KNA1[] IS INITIAL.
    FG_DATA_EXIST = ' '.
    ENDIF.
    ENDFORM. " get_data
    *& Form GENERATE_DATASET
    text
    --> p1 text
    <-- p2 text
    FORM GENERATE_DATASET.
    MESSAGE I010 WITH 'OPENING FILE IN APPLICATION SERVER'.
    **--Creating a data set in application server
    OPEN DATASET V_FNAME FOR OUTPUT IN TEXT MODE.
    **---Transfering data from internal table to dataset
    MESSAGE I010 WITH 'TRANSFERING DATA FROM INETERAL TABLE TO THE FILE'.
    LOOP AT IT_KNA1.
    TRANSFER IT_KNA1 TO V_FNAME.
    ENDLOOP.
    **--Closing the dataset
    MESSAGE I010 WITH 'CLOSING THE FILE'.
    CLOSE DATASET V_FNAME.
    ENDFORM. " GENERATE_DATASET
    *& Form BDC_DYNPRO
    text
    -->P_0467 text
    -->P_0468 text
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
    CLEAR IT_BDCDATA.
    IT_BDCDATA-PROGRAM = PROGRAM.
    IT_BDCDATA-DYNPRO = DYNPRO.
    IT_BDCDATA-DYNBEGIN = 'X'.
    APPEND IT_BDCDATA.
    ENDFORM.
    *& Form BDC_FIELD
    text
    -->P_0472 text
    -->P_0473 text
    FORM BDC_FIELD USING FNAM FVAL.
    IF NOT FVAL IS INITIAL.
    CLEAR IT_BDCDATA.
    IT_BDCDATA-FNAM = FNAM.
    IT_BDCDATA-FVAL = FVAL.
    APPEND IT_BDCDATA.
    ENDIF.
    ENDFORM.
    *& Form GENERATE_BDCDATA
    text
    --> p1 text
    <-- p2 text
    FORM GENERATE_BDCDATA.
    REFRESH IT_KNA1.
    Opening dataset for reading
    OPEN DATASET V_FNAME FOR INPUT IN TEXT MODE.
    Reading the file from application server
    DO.
    CLEAR: IT_KNA1,IT_BDCDATA.
    REFRESH IT_BDCDATA.
    READ DATASET V_FNAME INTO IT_KNA1.
    IF SY-SUBRC <> 0.
    EXIT.
    ELSE.
    Populate BDC Data for Initial Screen
    PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0100',
    BDC_FIELD USING 'BDC_CURSOR' 'RF02D-KUNNR',
    BDC_FIELD USING 'BDC_OKCODE' '/00',
    BDC_FIELD USING 'RF02D-KUNNR' IT_KNA1-KUNNR,
    BDC_FIELD USING 'RF02D-KTOKD' IT_KNA1-KTOKD.
    Populate BDC Data for Second Screen
    PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0110',
    BDC_FIELD USING 'BDC_CURSOR' 'KNA1-NAME1',
    BDC_FIELD USING 'BDC_OKCODE' '/00',
    BDC_FIELD USING 'KNA1-NAME1' IT_KNA1-NAME1,
    BDC_FIELD USING 'KNA1-SORTL' IT_KNA1-SORTL,
    BDC_FIELD USING 'KNA1-ORT01' IT_KNA1-ORT01,
    BDC_FIELD USING 'KNA1-PSTLZ' IT_KNA1-PSTLZ,
    BDC_FIELD USING 'KNA1-LAND1' IT_KNA1-LAND1,
    BDC_FIELD USING 'KNA1-SPRAS' IT_KNA1-SPRAS.
    Populate BDC Data for Third Screen
    PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0120',
    BDC_FIELD USING 'BDC_CURSOR' 'KNA1-LZONE',
    BDC_FIELD USING 'BDC_OKCODE' '=UPDA',
    BDC_FIELD USING 'KNA1-LZONE' IT_KNA1-LZONE.
    CALL TRANSACTION C_XD01 USING IT_BDCDATA
    MODE C_MODE
    UPDATE C_UPDATE
    MESSAGES INTO IT_MSG.
    IF SY-SUBRC <> 0.
    *--In case of error list display
    IF R_LIST = C_X.
    V_ERRREC = V_ERRREC + 1.
    PERFORM FORMAT_MESSAGE.
    IT_ERR_MSG-MESSAGE = V_MSG.
    APPEND IT_ERR_MSG.
    CLEAR : V_MSG,IT_ERR_MSG.
    ENDIF.
    *--In case of session log
    IF R_SESS = C_X.
    *-- In case of transaction fails.
    IF FG_SESSION_OPEN = ' '.
    FG_SESSION_OPEN = C_X.
    PERFORM BDC_OPEN_GROUP.
    ENDIF. " IF FG_SESSION_OPEN = ' '.
    *-- Insert BDC Data..
    PERFORM BDC_INSERT_DATA.
    ENDIF. " IF R_SESS = C_X.
    ENDIF. " IF SY-SUBRC <> 0.
    ENDIF. " IF SY-SUBRC <> 0.
    ENDDO.
    Closing the dataset
    CLOSE DATASET V_FNAME.
    *-- Close the session if opened
    IF FG_SESSION_OPEN = C_X.
    PERFORM BDC_CLOSE_GROUP.
    CALL TRANSACTION 'SM35'.
    ENDIF.
    ENDFORM. " GENERATE_BDCDATA
    *& Form BDC_OPEN_GROUP
    text
    --> p1 text
    <-- p2 text
    FORM BDC_OPEN_GROUP.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    CLIENT = SY-MANDT
    DEST = FILLER8
    GROUP = C_SESS
    HOLDDATE = FILLER8
    KEEP = C_X
    USER = SY-UNAME
    RECORD = FILLER1
    IMPORTING
    QID =
    EXCEPTIONS
    CLIENT_INVALID = 1
    DESTINATION_INVALID = 2
    GROUP_INVALID = 3
    GROUP_IS_LOCKED = 4
    HOLDDATE_INVALID = 5
    INTERNAL_ERROR = 6
    QUEUE_ERROR = 7
    RUNNING = 8
    SYSTEM_LOCK_ERROR = 9
    USER_INVALID = 10
    OTHERS = 11
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " BDC_OPEN_GROUP
    *& Form BDC_INSERT_DATA
    text
    --> p1 text
    <-- p2 text
    FORM BDC_INSERT_DATA.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    TCODE = C_XD01
    POST_LOCAL = NOVBLOCAL
    PRINTING = NOPRINT
    TABLES
    DYNPROTAB = IT_BDCDATA
    EXCEPTIONS
    INTERNAL_ERROR = 1
    NOT_OPEN = 2
    QUEUE_ERROR = 3
    TCODE_INVALID = 4
    PRINTING_INVALID = 5
    POSTING_INVALID = 6
    OTHERS = 7
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " BDC_INSERT_DATA
    *& Form BDC_CLOSE_GROUP
    text
    --> p1 text
    <-- p2 text
    FORM BDC_CLOSE_GROUP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
    NOT_OPEN = 1
    QUEUE_ERROR = 2
    OTHERS = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " BDC_CLOSE_GROUP
    *& Form FORMAT_MESSAGE
    text
    --> p1 text
    <-- p2 text
    FORM FORMAT_MESSAGE.
    CLEAR V_LINES.
    DESCRIBE TABLE IT_MSG LINES V_LINES.
    READ TABLE IT_MSG INDEX V_LINES.
    CLEAR V_MSG.
    CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
    ID = IT_MSG-MSGID
    LANG = IT_MSG-MSGSPRA
    NO = IT_MSG-MSGNR
    V1 = IT_MSG-MSGV1
    V2 = IT_MSG-MSGV2
    V3 = IT_MSG-MSGV3
    V4 = IT_MSG-MSGV4
    IMPORTING
    MSG = V_MSG
    EXCEPTIONS
    NOT_FOUND = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " FORMAT_MESSAGE
    *& Form DISPLAY_ERR_RECS
    text
    --> p1 text
    <-- p2 text
    FORM DISPLAY_ERR_RECS.
    LOOP AT IT_ERR_MSG.
    WRITE: / IT_ERR_MSG-MESSAGE.
    ENDLOOP.
    ENDFORM. " DISPLAY_ERR_RECS
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • Problem:  this mac is not reading an excell file after upgrading to yosemite.   My Mac is from 2009, it use to work perfectly but it wasn´t able to open some apps, thats why i upgrade it.   Now it once i donwload the zip it appears with an ".ods" ext

    Problem:  this mac is not reading an excell file after upgrading to yosemite.   My Mac is from 2009, it use to work perfectly but it wasn´t able to open some apps, thats why i upgrade it.   Now it once i donwload the zip it appears with an ".ods" extension
    i even already download a link
    http://www.microsoft.com/en-us/download/confirmation.aspx?id=44026
    which i read on another support page... but it doesnt allowed me to install it cause it says that i already have the disk of this program....
    Im afraid to erase it and not being able to get it back...
    What can i do!??
    Thanks in advance for this kind answer!!!

    fsolution wrote:
    Problem:  this mac is not reading an excell file after upgrading to yosemite...   Now it once i donwload the zip it appears with an ".ods" extension...
    If the "it" refers to a compressed (zipped) spreadsheet that you downloaded, the ".ods" extension is used by LibreOffice and probably OpenOffice (which are free versions of MS Office) for spreadsheets, which would suggest that wherever you're getting that "Excel" file from has switched to one of those programs. I've tried opening an .ods file from LibreOffice using MS Office 2013 for Windows and it does open though with a warning that some things have been changed. I don't know if Office for Mac can normally open .ods files. But if your need is to just open .ods files, take a look at LibreOffice.

Maybe you are looking for

  • Member are not seen in Metaoutline dimensions

    Hi All, We are using SQLServer 2005 as a backend, trying to build the cube using EIS 9.3.1. My question is in Metaoutline, i am unable to see sample outline of a dimension, this you will get it right click dimension and view sample then supposed to s

  • Error ERR-1016 Application "107" Page "0" not found (requested language="en

    I tried to clear cache to solve a "Not Data Found: error and now I am getting this error. I am going from bad to worst. I press a submit button to insert rows into a table which worked fine until I did the following: (1) used the "Return Key Into Ite

  • Image to show when drop down menu is visible

    Hi all, Just a CSS problem I can't work out. The horz menu has drop down sub menu and I'm trying to get a arrow image to show when you hover over the main mene items, please see image. Thanks for any advise.

  • AS3 to PHP to XML

    Does anyone know of an example that will show me how to have a php file save to an xml file? I want to send a php file xml data and have that xml data saved to a xml doc on my server. Thanks!

  • Adding a sales order with DI Server 8.8 results in document with no rows

    Hello, I am facing a weird problem situation running DI Server in a 8.8 (pl8) environment. When adding a new sales order document, the add operation results in a "success", but when I go to B1 client and see the document, there are no rows at all. Pl