Convert into Data Table issue from Excel Sheet Table

Hi 
i've excel file where 10-12 sheets are available in that excel file.one of the sheet is named as summary.there are 8-10 tables(named as Table1,Table2,Table3....) in that summary sheet as well. 
i've to actually get the Table1 from the summary sheet into the DataTable. 
So,i've written a following method to read "summary" sheet and then i checked if the Table1 exist then break the loop.My problem is i've found Table1 but i am not able to convert it into the DataTable.Can anyone tell me how to do it.
private void GetProjectTable(string ExcelFileUrl)
string sheetName = "Summary";
string value = null;
// Open the spreadsheet document for read-only access.
try
String siteURL = SPContext.Current.Site.Url;
SPSecurity.RunWithElevatedPrivileges(delegate()
Stream dataStream = null;
using (SPSite site = new SPSite(siteURL))
using (SPWeb web = site.OpenWeb())
SPFile file = web.GetFile(ExcelFileUrl);
dataStream = file.OpenBinaryStream();
using (SpreadsheetDocument document =
SpreadsheetDocument.Open(dataStream, false))
// Retrieve a reference to the workbook part.
WorkbookPart wbPart = document.WorkbookPart;
Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
Where(s => s.Name == sheetName).FirstOrDefault();
// Throw an exception if there is no sheet.
if (theSheet == null)
throw new ArgumentException("sheetName");
WorksheetPart wsPart =
(WorksheetPart)(wbPart.GetPartById(theSheet.Id));
DocumentFormat.OpenXml.Spreadsheet.Table table = null;
DataTable dt = null;
foreach (TableDefinitionPart tdp in wsPart.TableDefinitionParts)
if (tdp.Table.DisplayName == "Table1")
table = tdp.Table;
break;
catch (Exception ex)
Note: I am using this code in the Visual Web Part for SharePoint

Hi hellofragrance,
According to the description, you want to convert to the table in Excel to DataTable using Open XML SDK.
As far as I know, there is no such API we can achieve the goal directly. However, we can write custom code to complete the job. Here are some major steps for your reference:
1. Get the information of the table we wanted to convert. For example, column information and the range address for the table. And we can get the these information via the
Table object of
TableDefinitionPart Class
2. Then we can create a DataTable via the column information we get from step1 and initialize the data table via read the data from range of table.
In addition, here is helpful article about read the value of specific cell for your reference:
How to: Retrieve the values of cells in a spreadsheet document (Open XML SDK)
Regards & Fei
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.

Similar Messages

  • Pasting data from Excel sheet to Table in web dynpro View

    Hii All,
    Is it possible to copy data ( some rows) from Excel sheet and paste in table in a view?
    I tried doing this, but only first element is getting pasted..
    Does anybody know how to do this?
    Is there any way to perform similar thing?
    Pls help.
    regards,
    Amey

    Hi,
    Copy paste may work if you have that many rows in your table(not sure).
    One thing you can do is upload the excel and then populate the context of the node bound to the table by fetching data from the excel
    For this you can make use of JXL or APACHE POI.
    Regards
    Ayyapparaj

  • Upload data from excel sheet into md61

    Hi Gurus,
                    Can anybody please tell me the solution like how to upload the data from excel sheet into the MD61
    if u suggest me to write an ABAP code then its fine or any other way would be great
    and can u also send me the abap code i would be thankful to all

    Hi,
    I can be done in 2 ways.
    1. Using LSMW you can upload your MD61 demand thru Excel sheet.
    2. You can use BDC to upload the demand from Excel. For this you need to take help from the ABAP. You need to record the macro usinf SHDB and the table maintenance will be taken care by the developer.
    For LSMW you need not depend on your developer, as a functional consultant you can do it yourself.
    Regards,
    V. Suresh

  • Uploading data from excel sheets through BDC's into sap system

    hi guys,
    can you please help me with this. As we use gui_upload to upload data from flat file to sap system, which function module you use to upload data from Excel sheet to sap system through bdc's

    hello pavan,
    welcome to SDN
    check the below program
    REPORT ZEXCEL_TO_INTERNAL .
    data: begin of itab occurs 0,
          name(20) type c,
          addre(20) type c,
          end of itab.
    DATA : ITAB1 LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
    DATA : B1 TYPE I VALUE 1,
           C1 TYPE I VALUE 1,
           B2 TYPE I VALUE 100,
           C2 TYPE I VALUE 9999.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        FILENAME                   =
        'C:\Documents and Settings\administrator\Desktop\ppcon001bd_24.xls'
        I_BEGIN_COL                   = B1
        I_BEGIN_ROW                   = C1
        I_END_COL                     = B2
        I_END_ROW                     = C2
      TABLES
        INTERN                        = itab1
    EXCEPTIONS
       INCONSISTENT_PARAMETERS       = 1
       UPLOAD_OLE                    = 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.
    loop at itab1.
    write:/ itab1.
    Endlop.
    Regards,
    Naveen

  • Create a visual web part which get data from excel sheet and import it into sql server database in sharepoint 2010 (development)

    Hi,
    I want to create a visual webpart which will read data from excel sheet and import it in to sql server database.(using sharepoint development)
    I want to do it using visual webpart.
    Please help to solve the issue.
    Thanks in advance!
    Regards
    Rajni

    Hi  Rajni,
    Microsoft.Office.Interop.Excel assembly provides class to read excel file data, in your web part solution, reference the assembly, and following blog contains samples about how to read the excel file data,
    and import it to SQL  database.
    1.Create a Visual Web Part Project:Create
    Visual Web Parts in SharePoint 2010
    2.Read the excel workbook by using SPFile class:
    http://alancejacob.blogspot.in/2012/06/read-data-from-excel-file-and-insert-in.html
    http://stackoverflow.com/questions/14496608/read-excel-file-stored-in-sharepoint-document-library
    3.Export the excel workbook to SQL Server:
    http://www.c-sharpcorner.com/UploadFile/99bb20/import-excel-data-to-sql-server-in-Asp-Net/
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • How to transfer data more than 255 char from excel sheet to internal table.

    Hello Experts,
    I have a requirement where i have a text field in the excel sheet of more than 255 char and need to be updated in the text element. To do that i need to transfer the excel sheet data to an internal table where one of the field is more than 255 char.
    in the standard function module it works only upto 255 char. Can you help me if we have some other way to get more than 255 char in the internal table from excel sheet.
    Thanks in Advance.
    BR,
    RaJ.

    Using .xls, it is not possible transfer data more than 255 characters from excel sheet. However if the excel sheet is saved as Comma Delimited format or Tab Delimited format, then using GUI_DOWNLOAD function module data more than 255 characters can be transferred.
    File name should be : .csv (Comma Delimited format)  or .txt (Tab Delimited format)
    File Type would still remain 'ASC' while calling function module GUI_DOWNLOAD
    Also In the internal table declare the field type as String or LCHAR.
    Eg:
    TYPES: begin of ty_file,
            col_a TYPE string,
          end of ty_file.
    DATA: i_file type standard table
                   of ty_file
                 with header line
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      =  'C:\test.csv'
      TABLES
        DATA_TAB                      = i_file

  • Read data from excel sheet and then perform the required operations.

    Hi all
    I need to write a procedure which can read data from excel sheet.I have excel sheet in which i have to options one is modification and other is addition.so if it reads modification then i need to read the concerned table name then check its availability in pl-sql datbase.If table exists then reading the realated column in that row to fire the querry. The excel sheet is saved in local disk c.
    can anybody help me with this.How i need to start specialy to read the data from excel sheet saved in local disk c.
    Edited by: user13334062 on Jun 30, 2010 3:45 AM

    Hi
    If you can convert the excel to a csv format, then it can be simply query from DB Creating Oracle External Tables. Best part is that you may still change the CSV using EXCEL.
    Following action Points can be adopt;
    *1. Convert Excel File to a csv. File Save as CSV*
    *2. Create Oracle Directory* ( This has to be the location of your excel file )
    SQL> Create directory mydir as 'C:\testdb'; --- "testdb" is the location folder in win for your excel sheet.
    *3. Create the External Table*
    SQL> create table my_ext_tab (
    Field1 Datatype,
    Field2 Datatype,
    Field3 Datatype,
    Field4 Datatype,
    Field5 Datatype
    Organization external
    (type oracle_loader default directory mydir
    access parameters (records delimited by newline fields terminated by ',')
    location ('my_ext_tab.csv'))
    reject limit 100;
    *4. Now you can query the table "my_ext_tab"*
    Select * from "my_ext_tab";
    Please avoid the reformat the data column inside the spreadsheet (CSV).

  • Getting short dumps while reading bulky data from excel sheet

    Hi all,
    We have converted our non-unicode based sap system (R/3 4.7, Windows 2003,
    SQL 2000) into a unicode based system recently. We are facing two peculiar
    problems for last few days.
    *Problem 1 - *Whenever we want to upload the data from excel sheet, the
    system throws a dump after reading about 400 entries, while last week the
    same system used to read about 8000 entries in a single go.
    *Problem 2 - *Also, whenever we realease a transport requst from development
    containing a lot of changes, the request will reach the quality system but
    without the changes. but if i ll try to import the changes into quality
    system after generating more than one request containing small small
    changes, they get reflected in QAS immediately. Is there any size
    constraint in transporting a request fro DEV->QAS->PRD.
    Please suggest some ways.
    I am pasting the dump (that I am getting while data uploading from Excel).
    ~~~~~~~~~~~~~~~~~~
    Runtime errors
    MESSAGE_TYPE_X*
    Occurred on
    22.02.2008 at
    13:21:02*
    The current application triggered a termination with a short dump.
    What happened?
    The current application program detected a situation which really
    should not occur. Therefore, a termination with a short dump was
    triggered on purpose by the key word MESSAGE (type X).
    What can you do?
    Print out the error message (using the "Print" function)
    and make a note of the actions and input that caused the
    error.
    To resolve the problem, contact your SAP system administrator.
    You can use transaction ST22 (ABAP Dump Analysis) to view and administer
    termination messages, especially those beyond their normal deletion
    date.
    Error analysis
    Short text of error message:
    Control Framework : Error processing control
    Technical information about the message:
    Diagnosis
    An error occurred when the system tried to process the commands
    from the Automation Queue on the presentation server.
    There are several possible reasons for this:
    - The installation of the SAP GUI on the presentation server is
    faulty or obsolete.
    - There is an error in the application program
    - There is an error in the SAPGUI or an integrated control
    Procedure
    1. Make sure that you have imported the appropriate Support
    Package, the current kernel, and GUI patch for the release of your
    System
    2. Check whether the error occurs locally on one or a few PCs, or
    generally on all PCs. Note whether the error only occurs for some
    users, for example because of a specific Customizing setting.
    If it only occurs locally, this suggests an installation problem
    with the PC. Check the installation; if necessary, reinstall the
    software. In the dump, search for the SY-MSGLI field, since it may
    point to the cause of the error.
    3. Activate the Automation Trace (in accordance with SAP Note
    158985).
    4.Start the transaction and continue until the screen immediately
    before the dump.
    5. From the System -> Utilities menu, choose Autom. Queue,
    Synchronous Processing.
    The status bar of the GUI displays the text:
    "Automation synchron flush mode on"
    6. If you now proceed with the application, the short dump will
    display the ABAP call that caused the error; the Automation Trace
    will contain the error on the presentation server.
    7. If necessary, load the short dump and trace files on to
    sapservX, so that SAP can analyze them.
    Message classe...... "CNDP"
    Number.............. 006
    Variable 1.......... " "
    Variable 2.......... " "
    Variable 3.......... " "
    Variable 4.......... " "
    Variable 3.......... " "
    Variable 4.......... " "
    How to correct the error
    Probably the only way to eliminate the error is to correct the program.
    You may able to find an interim solution to the problem
    in the SAP note system. If you have access to the note system yourself,
    use the following search criteria:
    "MESSAGE_TYPE_X" C
    "SAPLOLEA" or "LOLEAU02"
    "AC_SYSTEM_FLUSH"
    If you cannot solve the problem yourself, please send the
    following documents to SAP:
    1. A hard copy print describing the problem.
    To obtain this, select the "Print" function on the current screen.
    2. A suitable hardcopy prinout of the system log.
    To obtain this, call the system log with Transaction SM21
    and select the "Print" function to print out the relevant
    part.
    3. If the programs are your own programs or modified SAP programs,
    supply the source code.
    To do this, you can either use the "PRINT" command in the editor or
    print the programs using the report RSINCL00.
    4. Details regarding the conditions under which the error occurred
    or which actions and input led to the error.
    System environment
    SAP Release.............. "620"
    Application server....... "nhbho930"
    Network address.......... "192.168.0.30"
    Operating system......... "Windows NT"
    Release.................. "5.2"
    Hardware type............ "4x Intel 801586"
    Character length......... 16 Bits
    Pointer length........... 32 Bits
    Work process number...... 0
    Short dump setting....... "full"
    Database server.......... "NHBHO930"
    Database type............ "MSSQL"
    Database name............ "DEV"
    Database owner........... "dev"
    Character set............ "C"
    SAP kernel............... "640"
    Created on............... "Aug 17 2007 00:18:58"
    Created in............... "NT 5.0 2195 Service Pack 4 x86 MS VC++ 13.10"
    Database version......... "SQL_Server_8.00 "
    Patch level.............. "196"
    Patch text............... " "
    Supported environment....
    Database................. "MSSQL 7.00.699 or higher, MSSQL 8.00.194"
    SAP database version..... "640"
    Operating system......... "Windows NT 5.0, Windows NT 5.1, Windows NT 5.2,
    Windows NT 6.0"
    User, transaction...
    Client.............. 300
    User................ "NHBABAP"
    Language key........ "E"
    Transaction......... "SE38 "
    Program............. "SAPLOLEA"
    Screen.............. "SAPMSDYP 0010"
    Screen line......... 0
    Information on where terminated
    The termination occurred in the ABAP program "SAPLOLEA" in
    "AC_SYSTEM_FLUSH".
    The main program was "ZBDC_CONTRACT ".
    The termination occurred in line 29 of the source code of the (Include)
    program "LOLEAU02"
    of the source code of program "LOLEAU02" (when calling the editor 290).
    ~~~~~~~~~~~~~~~~~~~~~
    Thank you all.
    Cheers.
    Mitra __.____._

    for the 50 millionth time: Excel spreadsheets are NOT databases, you should NOT try to use them as such and NEVER access them using JDBC.
    You should also under NO condition use the JDBC-ODBC bridge driver (that was actually the 78 millionth time that was told someone).

  • Urgent - Migrate data from Excel sheets

    Hello all..
    I want to move data from excel sheets into oracle9i Database
    I have a bout 50 table with average of 5000 row per table
    How could I do it
    I will be so obligated if you could detail it for me
    Thanks in advance

    I want to insert data using loader in the table Tablename
    Name Type
    CL_CL_CODE NUMBER(3)
    SUBCL_CODE VARCHAR2(50)
    SUBCL_NAME NUMBER(2)
    P_CODE_LENTH NUMBER(3)
    SCE_NAME VARCHAR2(50)
    I use this statement:
    load data
    infile 'D:\Sqlldr\load.dat'
    replace
    into table subclasses
    FIELDS TERMINATED BY ";" OPTIONALLY ENCLOSED BY '"'
    (CL_CL_CODE,SUBCL_CODE,SUBCL_NAME,P_CODE_LENTH SCE_NAME)
    I need to use default value for the column SCE_NAME,P_CODE_LENTH
    what is the formula for this
    Thanks

  • How to retrieve data from excel sheet

    Hi,
    How to retrieve data from excel sheet into a java file.

    janu05 wrote:
    If we append a $ in the end of the table name it is showing an error saying "invalid name,should not contain any invalid character or punctuation"Great, I'm very happy for you.
    Unless that was a question. In which case you might what to tell us a little more.
    Like which API you are using (assuming we are still on "reading an Excel sheet".

  • Uploading data from excel sheet

    HI,
         Can anyone provide me the details to upload vendor data from excel sheet to database through bdc?
    Thankyou.

    upload the excel file in your internal table and then use BDC to updated the database table.
    FM's to upload Excel:
    GUI_UPLOAD
    KCD_EXCEL_OLE_TO_INT_CONVERT
    ALSM_EXCEL_TO_INTERNALTABLE
    refer to the link:
    http://diocio.wordpress.com/2007/02/12/sap-upload-excel-document-into-internal-table-2/
    http://www.sap-img.com/abap/learning-bdc-programming.htm
    With luck,
    Pritam.

  • Dowloading data from excel sheet

    Hi all,
    Please tell me the function module to download the data from excel sheet in to the internal table created in program.
    And how to download the data from a particular line in the excel sheet into internal table.

    HI,
    TYPES:
      BEGIN OF ty_upload,
        field1 TYPE c length 12,
        field2 TYPE c length 12,
        field3 TYPE c length 12,
      END OF ty_upload.
      DATA it_upload TYPE STANDARD TABLE OF ty_upload WITH DEFAULT KEY.
      DATA wa_upload TYPE ty_upload.
      DATA itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.
      FIELD-SYMBOLS: <wa> type alsmex_tabline.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename    = filename
          i_begin_col = 1
          i_begin_row = 1
          i_end_col   = 3
          i_end_row   = 65535
        TABLES
          intern      = itab.
      LOOP AT itab ASSIGNING <wa>.
        CASE <wa>-col.
          WHEN '0001'.
            wa_upload-field1 = <wa>-value.
          WHEN '0002'.
            wa_upload-field2 = <wa>-value.
          WHEN '0003'.
            wa_upload-field3 = <wa>-value.
        ENDCASE.
        APPEND wa_upload TO it_upload.
        CLEAR wa_upload.
      ENDLOOP
    http://www.sap-img.com/abap/upload-direct-excel.htm
    <b>Another Program</b>
    *& Report  UPLOAD_EXCEL                                                *
    *& Upload and excel file into an internal table using the following    *
    *& function module: ALSM_EXCEL_TO_INTERNAL_TABLE                       *
    REPORT  UPLOAD_EXCEL no standard page heading.
    *Data Declaration
    data: itab like alsmex_tabline occurs 0 with header line.
    * Has the following format:
    *             Row number   | Colum Number   |   Value
    *      i.e.     1                 1             Name1
    *               2                 1             Joe
    TYPES: Begin of t_record,
        name1 like itab-value,
        name2 like itab-value,
        age   like itab-value,
        End of t_record.
    DATA: it_record type standard table of t_record initial size 0,
          wa_record type t_record.
    DATA: gd_currentrow type i.
    *Selection Screen Declaration
    PARAMETER p_infile like rlgrap-filename.
    *START OF SELECTION
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           exporting
                filename                = p_infile
                i_begin_col             = '1'
                i_begin_row             = '2'  "Do not require headings
                i_end_col               = '14'
                i_end_row               = '31'
           tables
                intern                  = itab
           exceptions
                inconsistent_parameters = 1
                upload_ole              = 2
                others                  = 3.
      if sy-subrc <> 0.
        message e010(zz) with text-001. "Problem uploading Excel Spreadsheet
      endif.
    * Sort table by rows and colums
      sort itab by row col.
    * Get first row retrieved
      read table itab index 1.
    * Set first row retrieved to current row
      gd_currentrow = itab-row.
      loop at itab.
    *   Reset values for next row
        if itab-row ne gd_currentrow.
          append wa_record to it_record.
          clear wa_record.
          gd_currentrow = itab-row.
        endif.
        case itab-col.
          when '0001'.                              "First name
            wa_record-name1 = itab-value.
          when '0002'.                              "Surname
            wa_record-name2 = itab-value.
          when '0003'.                              "Age
            wa_record-age   = itab-value.
        endcase.
      endloop.
      append wa_record to it_record.
    *!! Excel data is now contained within the internal table IT_RECORD
    * Display report data for illustration purposes
      loop at it_record into wa_record.
        write:/     sy-vline,
               (10) wa_record-name1, sy-vline,
               (10) wa_record-name2, sy-vline,
               (10) wa_record-age, sy-vline.
      endloop.
    Regards
    Sudheer

  • How to get data from excel sheet present in the client(local) system?

    hi,
    I have to upload the data from an excel sheet present in the local system(not on the server) to the table using webdynpro.
    i donot want to upload the excel file
    if it is necessary to upload the file then it should be on temporary basis and it should be deleted automatically.
    i can get the data from excel sheet which is present in the km using HSSF api but how to do the same if it is in local system?
    if anyone has the sample application of this type please give me the link.
    thanks

    You can use the FM ALSM_EXCEL_TO_INTERNAL_TABLE with Web Dynpro ABAP.

  • Problems in uploading from excel sheet to internal table

    hi experts,
    i got one problem regarding uploading data from excel sheet to int.table. I used FM ALSM_EXCEL_TO_INTERNAL_TABLE but in that the value is char of 50. but i need a case where i have to send value more than 50 characters. please suggest me any other FM to overcome this problem.
    advanced thanks
    vijay

    Hi,
    >
    Vijay Krishna Arvapalli wrote:
    > hi tarun,
    >
    > thank you for your reply
    >
    > but when i tried to use FM TEXT_CONVERT_XLS_TO_SAP it is giving error actually that 'Error generating the test frame'.
    >
    > so can you suggest me with some other option where i can upload the field with more than 50 character length.
    >
    > thank you
    > regards
    > vijay
    Yes, when you execute the FM from SE37, then it displays a message.
    Just copy the below code and paste it in a report (SE38) and execute.
    Create a file in C:/ with name test.xls and execute it will display the records even with more than 50 characters of length.
    I have tested and its working.
    I have taken three fields in the excel file empid, name and doj.
    TYPE-POOLS : truxs.
    PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.XLS'.
    DATA : BEGIN OF itab OCCURS 0,
             empid(150) TYPE c,
             name(150) TYPE c,
             doj(150) TYPE c,
           END OF itab.
    DATA: it_raw TYPE truxs_t_text_data.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      PERFORM f4_file_process USING p_file.
    AT SELECTION-SCREEN.
      PERFORM validate_file_path USING p_file.
    START-OF-SELECTION.
      PERFORM upload_data.
    END-OF-SELECTION.
      PERFORM display_data.
    *&      Form  F4_FILE_PROCESS
    *       text
    *      -->P_FILE_PATH  text
    FORM f4_file_process USING p_file.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
          field_name    = 'P_FILE'
        IMPORTING
          file_name     = p_file.
      IF sy-subrc NE 0.
        MESSAGE e000(zsd).
      ENDIF.
    ENDFORM.                    " F4_FILE_PROCESS
    *&      Form  VALIDATE_FILE_PATH
    *       text
    *      -->P_FILE  text
    FORM validate_file_path USING p_file.
      DATA : lv_dir TYPE string,
             lv_file TYPE string,
             lv_result(1) TYPE c.
      DATA : lv_filename TYPE string.
      lv_filename = p_file.
      CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
        EXPORTING
          full_name     = p_file
        IMPORTING
          stripped_name = lv_file
          file_path     = lv_dir
        EXCEPTIONS
          x_error       = 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.
      CALL METHOD cl_gui_frontend_services=>directory_exist
        EXPORTING
          directory            = lv_dir
        RECEIVING
          result               = lv_result
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          wrong_parameter      = 3
          not_supported_by_gui = 4
          OTHERS               = 5.
      IF lv_result IS INITIAL.
        MESSAGE 'Invalid Directory' TYPE 'E'.
      ENDIF.
      CLEAR lv_result.
      CALL METHOD cl_gui_frontend_services=>file_exist
        EXPORTING
          file                 = lv_filename
        RECEIVING
          result               = lv_result
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          wrong_parameter      = 3
          not_supported_by_gui = 4
          OTHERS               = 5.
      IF lv_result IS INITIAL.
        MESSAGE 'Invalid File' TYPE 'E'.
      ENDIF.
    ENDFORM.                    " VALIDATE_FILE_PATH
    *&      Form  UPLOAD_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM upload_data .
      CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
          i_field_seperator    = 'X'
          i_line_header        = 'X'
          i_tab_raw_data       = it_raw
          i_filename           = p_file
        TABLES
          i_tab_converted_data = itab[]
        EXCEPTIONS
          conversion_failed    = 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.                    " UPLOAD_DATA
    *&      Form  DISPLAY_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_data .
      LOOP AT itab.
        WRITE : / itab-empid, itab-name, itab-doj.
      ENDLOOP.
    ENDFORM.                    " DISPLAY_DATA
    Hope this helps you.
    Regards,
    Tarun

  • Cannot retrieve the data from excel sheet

    hi all ...
    i am trying to retrieve the data from excel sheet and at the same time i am inserting the data into mysql database.
    code is as follows
    try{             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");             conn1=DriverManager.getConnection("jdbc:odbc:"+estr,"","");             Class.forName("com.mysql.jdbc.Driver");             conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+ t_dsn ,"root","manager");             sql="select * from student_info";             srch2 = conn.prepareStatement(sql);             rs1 = srch2.executeQuery();             String query  = "select * from ["+einput+"$]";             String query1= "select  count(*) from ["+einput+"$]";             st  = conn1.createStatement();             rs  = st.executeQuery(query);             ResultSetMetaData rsmd = rs.getMetaData();             c = rsmd.getColumnCount();//gets the column count             rs1  = st.executeQuery(query1);             while (rs1.next())  //loop to get no. of rows             {                 r = rs1.getInt(1);             }             rs = st.executeQuery(query);             for(i=1;i<=r;i++){                 rs.next();                 for(j=1;j==c;j++) {                     a = rs.getString(j);                     b= rs.getString(j);                     d = rs.getString(j);                 }                 rs1.next();                 PreparedStatement ps2 = conn.prepareStatement("insert into materials_out values(?,?,?)");                 ps2.setString(1,a);                 ps2.setString(2,b);                 ps2.setString(3,d);                 ps2.executeUpdate();             }         }catch(Exception e){             e.printStackTrace();         }
    but it is showing error as :
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name too long
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at Outward_register.jButton2ActionPerformed(Outward_register.java:368)
    at Outward_register.access$400(Outward_register.java:23)
    at Outward_register$5.actionPerformed(Outward_register.java:312)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    please help me ...

    please help me ... The question has nothing to do with 'getting' data from excel and certainly not with putting it into MySQL.
    The stack trace specifically tells you that your connection string is wrong.
    It also tells you which connection string is wrong.
    Which you can use to determine specifically which one is wrong. And which you did not provide that info to us.

Maybe you are looking for