Exporting data from table to Excel in a particular format using BSP.

Hello all,
      I am creating a application in BSP  wherein i have to export data to excel sheet.
  I am able to do that but the output in excel sheet is not formatted. it is displaying the data in a single 
column. For example, the internal table which i am exporting to excel contains fields "product
name", "area name", country name", "values". all these should be displayed in different columns.How 
can i achieve this functionality.A sample code will be of great help..
Below is the code i hav written for exporting to excel :
     data: l_len type i,
           l_string type string,
           app_type type string,
           file_content type xstring,
           file_mime_type type string.
     create OBJECT cached_response TYPE cl_http_response EXPORTING add_c_msg = 1.
     cached_response->set_data( file_content ).
     cached_response->set_header_field(
                      name = if_http_header_fields=>content_type
                      value = file_mime_type ).
LOOP AT itab_xls INTO wa_xls.
   CONCATENATE L_STRING wa_xls-product_name
   wa_xls-area_name
   wa_xls-landx
   CL_ABAP_CHAR_UTILITIES=>CR_LF INTO L_STRING SEPARATED BY SPACE.
ENDLOOP.
  APP_TYPE = 'APPLICATION/MSEXCEL; charset=utf-16le'.
  data: l_xstring type xstring.
call function 'SCMS_STRING_TO_XSTRING'
    exporting
      text = l_string
      MIMETYPE = 'APPLICATION/MSEXCEL; charset=utf-16le'
    IMPORTING
      BUFFER = l_xstring.
Add the Byte Order Mark - UTF-16 Little Endian
  concatenate  cl_abap_char_utilities=>byte_order_mark_little
               l_xstring
               into l_xstring in byte mode.
   cached_response->set_data( l_xstring ).
   cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                     value = 'APPLICATION/MSEXCEL; charset=utf-16le' ).
*Set the filename into the response header
   cached_response->set_header_field( name  = 'Content-Disposition'
                              value = 'attachment; filename=gkb_excel.xls' ).
*Set the Response Status
   cached_response->set_status( code = 200 reason = 'OK' ).
*Set the Cache Timeout - 60 seconds - we only need this in the cache
*long enough to build the page and allow the IFrame on the Client to request it.
   cached_response->server_cache_expire_rel( expires_rel = 60 ).
    CALL FUNCTION 'GUID_CREATE'
    IMPORTING
      ev_guid_32 = guid.
    CONCATENATE runtime->application_url '/' guid '.xls' INTO url.
    cl_http_server=>server_cache_upload( url      = url
                                       response = cached_response ).
Can anyone help me with some solution.
Thanks in advance.
Gurmahima.

the issue is here
LOOP AT itab_xls INTO wa_xls.
CONCATENATE L_STRING wa_xls-product_name
wa_xls-area_name
wa_xls-landx
CL_ABAP_CHAR_UTILITIES=>CR_LF INTO L_STRING SEPARATED BY SPACE.
ENDLOOP.
instead do the following
LOOP AT itab_xls INTO wa_xls.
CONCATENATE L_STRING wa_xls-product_name ','
wa_xls-area_name  ','
wa_xls-landx  ','
CL_ABAP_CHAR_UTILITIES=>CR_LF INTO L_STRING .
ENDLOOP.
and then change the file name extension from xls to csv. it should open properly in excel.
Note that this is only excel csv file. if you want a proper excel excel file, then
option one: build a html table with your data into a string and pass it to excel
option 2: build excel xml using your data into a string and pass it to excel.
Regards
Raja

Similar Messages

  • Exporting Data from Essbase to Excel

    Hi All,
    We are using classic planning application developed in Hyperion 11.1.2.2.
    Is there any way that we can export data from Essbase to Excel (Please note that i don't want to do it on server machine where essbase is installed, instead i want it on any client PC which is accessing Essbase)

    there are many ways you can do that, Through Excel Add-in,SmartView functions etc different.
    It depends on the requirement , if you mean to say who Essbase Data then someone else should be able to answer this.
    Thanks
    Amith

  • Export data from forms to excel

    HI
    In my application im trying to export data from forms to excel.Everything works fine.First of all im using get_file_name for selecttion of file and passing it to ole2 package as follows
    FILENAME := GET_FILE_NAME(File_Filter=> 'XLS Files (*.xls)|*.xls|',dialog_type=>SAVE_FILE);
         ARGS:=OLE2.CREATE_ARGLIST;
         oLE2.ADD_ARG(ARGS,Filename);
         OLE2.INVOKE(WORKSHEET,'SAVEAS',ARGS);
    The problem is if i select an existing file the get_file_name itself raises one message ".....file already exists Replace an existing file?"
    Similarly the excel also also raises the same message "".....file already exists Replace an existing file?".I want to suppress atleast one of them? Could anyone help for this problem?
    appreciate ur help
    THANKS

    Looks like...
    ole2.set_property( ex_app, 'DisplayAlerts', false );
    where "ex_app" variable Excel Application -
         ex_app:=     ole2.create_obj('Excel.Application');
    and more Question:
    When i close excel app - in process viewer i see "excel.exe"
    ole2.release_obj don't work :(

  • How to export the data from table to excel sheet

    hi experts i have some problem am trying to export the data fro table to Excel sheet  in the view controller i have created one button wit public void onActionCLEAR(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionCLEAR(ServerEvent)
       //wdContext.nodeBapi_Salesorder_Getlist_Input().
       //wdContext.nodeBapi_Salesorder_Getlist_Input().invalidate();
        //@@end
      //@@begin javadoc:onActionExporToExcel(ServerEvent)
      /** Declared validating event handler. */
      //@@end
      public void onActionExporToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionExporToExcel(ServerEvent)
         try{
         FileOutputStream fos=new FileOutputStream("Test.xls");
          PrintStream ps=new PrintStream(fos);
          ps.println("<html><body><table border=1>");
          int size=wdContext.nodeBapi_Salesorder_Getlist_Input().size();
           Iterator attributes=wdContext.getNodeInfo().iterateAttributes();
           ps.println("<tr>");
           while(attributes.hasNext()){
            ps.println("<th>");
            DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();
            ps.println(attrName.getName());
            ps.println("</th>");
           ps.println("</tr>");
          for(int i=0; i<wdContext.nodeBapi_Salesorder_Getlist_Input().size();i++)
            attributes=wdContext.getNodeInfo().iterateAttributes();
            ps.println("<tr>");
            IWDNodeElement ele=wdContext.getElementAt(i);
            while(attributes.hasNext()){
              ps.println("<td>");
              DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();
              ps.println(""+ele.getAttributeAsText(attrName.getName()));
              ps.println("</td>");
            ps.println("</tr>");
           ps.println("</table></body></html>");
           ps.flush();
           ps.close();
           fos.close();
          catch(Exception e){
           wdComponentAPI.getMessageManager().reportException(e.getMessage(), false);
          finally{
         //return("Test.xls")  ;
        //@@end
      }h action and i have return the code
    its running sucessfully but am not able to perform the action plz help me

    Hi,
    You shouldn't use DataAttributeInfo as it is an internal object, if I'm correct.
    Use IWDAttributeInfo instead of DataAttributeInfo and it should work
    (See also API doc of IWDNodeInfo.iterateAttributes() at http://help.sap.com/javadocs/nwce/ce711sp02/wdr/com.sap.wdr/com/sap/tc/webdynpro/progmodel/api/IWDNodeInfo.html#iterateAttributes())
    Cheers,
    Robin

  • Issue to export data from sql to excel

    I have MS SQL 2008 Developer version and visual studio 2008. I'm using SSIS Import and Export Wizard on the VS2008 to create a simple package to export data from a table using a sql query to excel file (.xlsx), but I got the following
    error messages:
    [Destination - Query [37]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E21.
    [Destination - Query [37]] Error: Cannot create an OLE DB accessor. Verify that the column metadata is valid.
    [SSIS.Pipeline] Error: component "Destination - Query" (37) failed the pre-execute phase and returned error code 0xC0202025.
    The SQL query is
    SELECT [BusinessEntityID]
          ,[PersonType]
          ,[NameStyle]
          ,[Title]
          ,[FirstName]
          ,[MiddleName]
          ,[LastName]
      FROM [AdventureWorks2008].[Person].[Person]
    Any help will be appreciated. Thanks.
    A Fan of SSIS, SSRS and SSAS

    Or another way is to save the package created by Export Import wizard, open it in BIDS and add a Derived column task before the Excel destination to do explicit casting of the columns to your required unicode datatypes.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Export data from block to excel.

    Hi
    Does anybody know how I can export data from oracle forms to an excel worksheet. I need to provide a direct interface for a user where he fetches the data into the block and by just click a button the data from the block should go to an excel sheet.
    Thanks in advance
    -Samsam

    Something along the following lines should help you in you are Client/Server. If you're on the Web then make sure you have WebUtil set up and add "CLIENT_" to all the OLE2 calls.
    PROCEDURE P_EXCEL IS
         application ole2.Obj_Type;
         workbooks ole2.Obj_Type;
         workbook ole2.Obj_Type;
         worksheets ole2.Obj_Type;
         worksheet ole2.Obj_Type;
         args ole2.List_Type;
         cell ole2.Obj_Type;
         j INTEGER;
         k INTEGER;
         file_name_cl VARCHAR2(32767);
         item_prompt VARCHAR2(32767);
    user_cancel EXCEPTION;
    BEGIN
    -- open the java save file dialogue box
    file_name_cl := GET_FILE_NAME('H:\', 'file_name.xls', 'XLS Files (*.xls)|*.xls|', NULL, SAVE_FILE, TRUE);
    file_name_cl := SUBSTR(file_name_cl,1,LENGTH(file_name_cl));
    IF file_name_cl IS NULL THEN
    RAISE user_cancel;
    END IF;
    application := ole2.create_obj('Excel.Application');
    workbooks := ole2.Get_Obj_Property(application, 'Workbooks');
    workbook := ole2.Invoke_Obj(workbooks, 'Add');
    worksheets := ole2.Get_Obj_Property(workbook, 'Worksheets');
    worksheet := ole2.Invoke_Obj(worksheets, 'Add');
    go_block('EXPORT_BLOCK');
    first_record;
    j:=1; /* Represents row number */
    k:=1; /* Represemts column number */
    /* Add the column headings using item prompts */
         FOR k IN 1..10 /* Block has 10 visible columns */
    LOOP
    item_prompt := get_item_property(:SYSTEM.CURRENT_BLOCK||'.'||:SYSTEM.CURRENT_ITEM, prompt_text);
    args:=ole2.create_arglist;
    ole2.add_arg(args, j);
    ole2.add_arg(args, k);
    cell:=ole2.get_obj_property(worksheet, 'Cells', args);
    ole2.destroy_arglist(args);
    ole2.set_property(cell, 'Value', item_prompt);
    ole2.release_obj(cell);
    next_item;
    END LOOP;
    j:=j+1; /* Add to rowcount so that data won't overwrite column headings! */
    LOOP
    /* Add in all the data */
    FOR k IN 1..10 /* Block has 10 visible columns */
    LOOP
    IF NOT name_in(:system.cursor_item) IS NULL THEN
    args:=ole2.create_arglist;
    ole2.add_arg(args, j);
    ole2.add_arg(args, k);
    cell:=ole2.get_obj_property(worksheet, 'Cells', args);
    ole2.destroy_arglist(args);
    ole2.set_property(cell, 'Value', name_in(:system.cursor_item));
    ole2.release_obj(cell);
    END IF;
    next_item;
    END LOOP;
    j:=j+1;
    IF :system.last_record = 'TRUE' THEN
         exit;
    ELSE
         next_record;
    END IF;
    END LOOP;
         ole2.Release_Obj(worksheet);
         ole2.Release_Obj(worksheets);
         /* Save the Excel file created */
         args := ole2.Create_Arglist;
         ole2.Add_Arg(args, file_name_cl);
         ole2.Invoke(workbook, 'SaveAs', args);
         ole2.Destroy_Arglist(args);
         /* release workbook */
         ole2.Release_Obj(workbook);
         ole2.Release_Obj(workbooks);
         /* Release application */
         ole2.Invoke(application, 'Quit');
         ole2.Release_Obj(application);
    EXCEPTION
    WHEN user_cancel THEN
         RAISE;
    END;

  • Export data from MSA to Excel?

    Can we export daat from MSA to Excel? When we search for the business partners, is there a way to download the results to excel?
    Thanks!

    Hi,
    Yes you can bring the data to Excel. One you a Business Partner Search,the results flow down to the list tile.
    1)Select one of the grid rows and Right Click on where the Arrow points.
    2) A small drop down comes up.choose the option "Generate Report".
    3) This opens up the"InstantReport" screen. Choose "MicrosoftExcel" in the Instant Report To Combo.
    4)Select the grid columns that you want and add them using the buttons present there.
    5)Then click on the button "Generate".
    6)The data flows down to an Excel sheet.
    Regards,
    Abishek

  • Exporting Data from Forms to Excel

    Hi,
    How can I export the data from Forms to Excel like which Export function in the Oracle Applications.
    Thank you,
    Voon

    Hello,
    By using dde package you can export the data from Form to Excel. Here is the sample code which i have used. you can write this code in the when_button_pressed trigger.
    declare
    appl_name varchar2(255);
    channel_id pls_integer;
    application_id pls_integer;
    x number;
    y number;
    V_TIME VARCHAR2(30);
    begin
    if :global.application_id is not null then
    message('Application already open');
    else
    appl_name := 'c:\program files\microsoft office\office\excel.exe';
    :global.application_id := dde.app_begin(appl_name,dde.app_mode_normal);
    end if;
    if :global.channel_id is not null then
    message('Communication channel already established.');
    elsif :global.application_id is null then
    message('Application must be launched first.');
    else
    :global.channel_id := dde.initiate('excel','book1');
    end if;
    DDE.POKE(:global.channel_id,'R1C1','Col1 Heading',DDE.CF_TEXT,1000);
    DDE.POKE(:global.channel_id,'R1C2','Col2 Heading',DDE.CF_TEXT,1000);
    DDE.POKE(:global.channel_id,'R1C3','Col3 Heading',DDE.CF_TEXT,1000);
    FIRST_RECORD;
    X := No of Records;
    for y in 2..x
    loop
    launch_excel is a program unit--
    launch_excel(y,:global.channel_id,:block.item1,:block.item2,::block.item3);
    next_record;
    end loop;
    FIRST_RECORD;
    EXCEPTION
    WHEN DDE.DDE_APP_FAILURE THEN
    MESSAGE('Could not launch application for DDE operations.');
    RAISE FORM_TRIGGER_FAILURE;
    WHEN DDE.DDE_INIT_FAILED THEN
    MESSAGE('Could not initialize DDE communication channel.');
    RAISE FORM_TRIGGER_FAILURE;
    WHEN DDE.DMLERR_NO_CONV_ESTABLISHED THEN
    MESSAGE('Could not establish DDE communication channel.');
    RAISE FORM_TRIGGER_FAILURE;
    WHEN OTHERS THEN
    MESSAGE('Error: '&#0124; &#0124;TO_CHAR(SQLCODE)&#0124; &#0124;' '&#0124; &#0124;SQLERRM);
    RAISE FORM_TRIGGER_FAILURE;
    END;
    LAUNCH_EXCEL
    PROCEDURE LAUNCH_EXCEL(
    y in number,
    channel_id pls_integer,
    param1 varchar2,
    param2 VARCHAR2,
    param3 varchar2) IS
    v_rowno varchar2(20) := 'R'&#0124; &#0124;y;
    BEGIN
    dde.poke(channel_id,v_rowno&#0124; &#0124;'C1',col1,dde.cf_text,2000);
    dde.poke(channel_id,v_rowno&#0124; &#0124;'C2',col2,dde.cf_text,2000);
    dde.poke(channel_id,v_rowno&#0124; &#0124;'C3',col3,dde.cf_text,2000);
    EXCEPTION
    when others then
    message('Error --'&#0124; &#0124;sqlcode&#0124; &#0124;sqlerrm);
    message('Error --'&#0124; &#0124;sqlcode&#0124; &#0124;sqlerrm);
    raise form_trigger_failure;
    END;
    null

  • BI 4.0 sp 6 service name to export data from webi to excel

    Hi there,
    I'm using BI 4.0 SP6 and I was just curious to find out which servers/services are invoked while exporting data from WebI report to Excel?
    Thanks in advance.
    Regards,
    samique

    Check below section in the Admin guide for this information.
    Architecture\Process Workflows

  • How to export data from report to excel using report 10g

    Hi,
    usnig report 10g, can we export the data from report to excel.
    Regards
    Randhir

    Hi,
    have a look at metalink note 209770.1: Getting Reports Ouput to MS Excel - Techniques and References
    Regards
    Rainer

  • How to export message body and data from Table to Excel from outlook 2010

    I usually get Employee announcement in emails and I need to compile excel sheet from all these emails to know change in status of employee from previous line to current line .
    Dear Concerned,
    The change in status of the following employee has been carried out as per following details:
    New Status
    Change in Job
    Effective Date
    01-Feb-2015
    Employee Name
    Ricky ponting
    Employee Code
    4982
    Designation
    Sourcing Executive (Secondment)
    Job Group
    1A
    Department
    Sourcing & Supply Chain
    Unit
    Technology Sourcing
    Division
    Finance
    Location
    sydney
    Reporting Line
    Mr Micheal king
    Note: Ricky Ponting  was previously working as
    Tariff Implementation Support Officer XYZ organization was reporting to
    Mr Robin Sing
    I need working code that export about HTML table data as well last Note : full line so that I can have an excel file of 2000 Employees whoes status have been changed and I can easily sort out from which previous line they were reporting to new line and I
    can get in touch with the new line for any Access rights re-authorization exercise on later stage .
    Currently i am using following code thats working fine with the table extraction but NOTE: line is not being fetched with the following code based on following URL
    https://techniclee.wordpress.com/2011/10/29/exporting-outlook-messages-to-excel/
    Const MACRO_NAME = "Export Messages to Excel (Rev Sajjad)"
    Private Sub ExportMessagesToExcel()
        Dim olkFld As Outlook.MAPIFolder, _
            olkMsg As Outlook.MailItem, _
            excApp As Object, _
            excWkb As Object, _
            excWks As Object, _
            arrCel As Variant, _
            varCel As Variant, _
            lngRow As Long, _
            intPtr As Integer, _
            intVer As Integer
        Set olkFld = Session.PickFolder
        If TypeName(olkFld) = "Nothing" Then
            MsgBox "You did not select a folder.  Operation cancelled.", vbCritical + vbOKOnly, MACRO_NAME
        Else
            intVer = GetOutlookVersion()
            Set excApp = CreateObject("Excel.Application")
            Set excWkb = excApp.Workbooks.Add
            Set excWks = excWkb.Worksheets(1)
            excApp.Visible = True
            With excWks
                .Cells(1, 1) = "Subject"
                .Cells(1, 2) = "Received"
                .Cells(1, 3) = "Sender"
                .Cells(1, 4) = "New Status"
                .Cells(1, 5) = "Effective Date"
                .Cells(1, 6) = "Employee Name"
                .Cells(1, 7) = "Employee Code"
                .Cells(1, 8) = "Designation"
                .Cells(1, 9) = "Job Group"
                .Cells(1, 10) = "Department"
                .Cells(1, 11) = "Unit"
                .Cells(1, 12) = "Division"
                .Cells(1, 13) = "Location"
                .Cells(1, 14) = "Reporting Line"
                .Cells(1, 15) = "Note:"
            End With
            lngRow = 2
            For Each olkMsg In olkFld.Items
                excWks.Cells(lngRow, 1) = olkMsg.Subject
                excWks.Cells(lngRow, 2) = olkMsg.ReceivedTime
                excWks.Cells(lngRow, 3) = GetSMTPAddress(olkMsg, intVer)
               For intPtr = LBound(arrCel) To UBound(arrCel)
                    Select Case Trim(arrCel(intPtr))
                        Case "New Status"
                            excWks.Cells(lngRow, 4) = arrCel(intPtr + 1)
                        Case "Effective Date"
                            excWks.Cells(lngRow, 5) = arrCel(intPtr + 1)
                        Case "Employee Name"
                            excWks.Cells(lngRow, 6) = arrCel(intPtr + 1)
                        Case "Employee Code"
                            excWks.Cells(lngRow, 7) = arrCel(intPtr + 1)
                        Case "Designation"
                            excWks.Cells(lngRow, 8) = arrCel(intPtr + 1)
                        Case "Job Group"
                            excWks.Cells(lngRow, 9) = arrCel(intPtr + 1)
                        Case "Department"
                            excWks.Cells(lngRow, 10) = arrCel(intPtr + 1)
                        Case "Unit"
                            excWks.Cells(lngRow, 11) = arrCel(intPtr + 1)
                        Case "Division"
                            excWks.Cells(lngRow, 12) = arrCel(intPtr + 1)
                        Case "Location"
                            excWks.Cells(lngRow, 13) = arrCel(intPtr + 1)
                        Case "Reporting Line"
                            excWks.Cells(lngRow, 14) = arrCel(intPtr + 1)
                        Case "Note:"
                            excWks.Cells(lngRow, 14) = arrCel(intPtr + 1)
                        End Select
                Next
                lngRow = lngRow + 1
            Next
            excWks.Columns("A:W").AutoFit
            excApp.Visible = True
            Set excWks = Nothing
            Set excWkb = Nothing
            Set excApp = Nothing
        End If
        Set olkFld = Nothing
    End Sub
    Private Function GetSMTPAddress(Item As Outlook.MailItem, intOutlookVersion As Integer) As String
        Dim olkSnd As Outlook.AddressEntry, olkEnt As Object
        On Error Resume Next
        Select Case intOutlookVersion
            Case Is < 14
                If Item.SenderEmailType = "EX" Then
                    GetSMTPAddress = SMTP2007(Item)
                Else
                    GetSMTPAddress = Item.SenderEmailAddress
                End If
            Case Else
                Set olkSnd = Item.Sender
                If olkSnd.AddressEntryUserType = olExchangeUserAddressEntry Then
                    Set olkEnt = olkSnd.GetExchangeUser
                    GetSMTPAddress = olkEnt.PrimarySmtpAddress
                Else
                    GetSMTPAddress = Item.SenderEmailAddress
                End If
        End Select
        On Error GoTo 0
        Set olkPrp = Nothing
        Set olkSnd = Nothing
        Set olkEnt = Nothing
    End Function
    Function GetOutlookVersion() As Integer
        Dim arrVer As Variant
        arrVer = Split(Outlook.Version, ".")
        GetOutlookVersion = arrVer(0)
    End Function
    Function SMTP2007(olkMsg As Outlook.MailItem) As String
        Dim olkPA As Outlook.PropertyAccessor
        On Error Resume Next
        Set olkPA = olkMsg.PropertyAccessor
        SMTP2007 = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001E")
        On Error GoTo 0
        Set olkPA = Nothing
    End Function
    Sub DebugLabels()
        Dim olkMsg As Outlook.MailItem, objFSO As Object, objFil As Object, strBuf As String, strPth As String, arrCel As Variant, intPtr As Integer
        strPth = Environ("USERPROFILE") & "\Documents\Debugging.txt"
        Set olkMsg = Application.ActiveExplorer.Selection(1)
        arrCel = Split(GetCells(olkMsg.HTMLBody), Chr(255))
        For intPtr = LBound(arrCel) To UBound(arrCel)
            strBuf = strBuf & StrZero(intPtr, 2) & vbTab & "*" & arrCel(intPtr) & "*" & vbCrLf
        Next
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFil = objFSO.CreateTextFile(strPth)
        objFil.Write strBuf
        objFil.Close
        Set olkMsg = Application.CreateItem(olMailItem)
        With olkMsg
            .Recipients.Add "[email protected]"
            .Subject = "Debugging Info"
            .BodyFormat = olFormatPlain
            .Body = "The debugging info for the selected message is attached.  Please click Send to send this message to David."
            .Attachments.Add strPth
            .Display
        End With
        Set olkMsg = Nothing
        Set objFSO = Nothing
        Set objFil = Nothing
    End Sub
    Function StrZero(varNumber, intLength)
        Dim intItemLength
        If IsNumeric(varNumber) Then
            intItemLength = Len(CStr(Int(varNumber)))
            If intItemLength < intLength Then
                StrZero = String(intLength - intItemLength, "0") & varNumber
            Else
                StrZero = varNumber
            End If
        Else
            StrZero = varNumber
        End If
    End Function

    Dear Graham
    I am already big fan of yours and using mail to many Addin from years from word 2007 to Word 2010 :) and still loving it and I use it for access re-authorization from Lines for application accesses . I tried and finally got understanding of the Extract to
    mail Addin and after tweaking excel - Text To columns and other few things finally i was able to get the required data - from morning to now :) I am happy to see your provided guidance
    Thanks alot - by the way why your Mail to many add-in is so slow now these days :) previous versions usually help me send 1000 emails in 10 minutes now it takes long time :)

  • How to export data from webdynpro to Excel and start a Excel macro

    Hello All
    I want to export data displayed in the Web dynpro ALV into Excel. I have tried the ALV export function but my problem with it is when it does export to excel the data loses formatting and I have long text in columns which display with wrapping in ALV but when exported to excel it loses formatting.
    So I want to define a custom button and when user presses on this button the excel export is called with a macro. Can you kindly share ideas how I can do this from a webdynpro.
    Thanks
    Karen

    Hi friends!
    I have followed the following:
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417300)ID1487994050DB10407586481486749551End?blog=/pub/wlg/5522
    ...in order to create standard ALV with Export to Excel.
    However what is exported into excel is awful. It does not contain my data in nice columns... Instead it shows a lot of meta-data.
    Please let me know what to do to kick the standard Export button in the correct direction.. that is...to have my nice table in same way in Excel, because that is my intention with "Export to excel"
    Best reg
    Henrik

  • Error while exporting data from ABAP to Excel

    Hello All,
    iam trying to download data from ABAP scrn to Excel using I_OI_SPREADSHEET METHODS. I get an error in method 'SET_RANGES_DATA' - 'Memory protection fault occurred in document interface'.
    I have pasted my code below. Kindly help me to solve this issue.
    Create container ??
      CALL METHOD c_oi_container_control_creator=>get_container_control
        IMPORTING
          control = g_control
          error   = g_error.
    Initialize
      CALL METHOD g_control->init_control
        EXPORTING
          r3_application_name      = 'Basis'
          parent                   = g_container
         register_on_close_event  = c_reg_on_close_event
         register_on_custom_event = c_reg_on_custom_event
         no_flush                 = c_no_flush
        IMPORTING
          error                    = g_error.
    Set Doc type
      g_document_type = 'Excel.Sheet'.
    Create Proxy
      CALL METHOD g_control->get_document_proxy
        EXPORTING
          document_type  = g_document_type
        IMPORTING
          document_proxy = g_document
          error          = g_error.
      CALL METHOD g_document->create_document
        EXPORTING
          document_title = 'Excel'.                             "#EC NOTEXT
      CALL METHOD g_document->get_spreadsheet_interface
        IMPORTING
          sheet_interface = g_handle.
      CHECK g_document IS NOT INITIAL.
    read selected line data from gtab
      READ TABLE g_tab_data INDEX 1  INTO l_wa_pos_trans.
    Get Field Descriptions
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          tabname        = 'TRIGS_EXPORT_EXCEL'
          langu          = sy-langu
        TABLES
          dfies_tab      = lt_dfies
        EXCEPTIONS
          not_found      = 1
          internal_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.
    Header for User Data
      l_h_cnt  = 1.
      LOOP AT lt_dfies INTO lwa_dfies.
        IF lwa_dfies-fieldname EQ 'USER_ID'          OR
           lwa_dfies-fieldname EQ 'EXCEL_DATE'       OR
           lwa_dfies-fieldname EQ 'EXCEL_TIME'       OR
           lwa_dfies-fieldname EQ 'SECURITY_ACCOUNT' OR
           lwa_dfies-fieldname EQ 'SECURITY_ID'      OR
           lwa_dfies-fieldname EQ 'COMPANY_CODE'.
          PERFORM fill_cell USING l_h_cnt 1 1 lwa_dfies-scrtext_m.
          l_h_cnt  =  l_h_cnt  + 1.
        ENDIF.
      ENDLOOP.
    Fill Header Values
      PERFORM fill_cell USING 1 2 1 sy-uname.
      PERFORM fill_cell USING 2 2 1 sy-datum.
      PERFORM fill_cell USING 3 2 1 sy-uzeit.
      PERFORM fill_cell USING 4 2 1 l_wa_pos_trans-company_code .
      PERFORM fill_cell USING 5 2 1 l_wa_pos_trans-security_account.
      PERFORM fill_cell USING 6 2 1 l_wa_pos_trans-security_id.
    Texts
    l_h_cnt = l_h_cnt + 1.
      PERFORM fill_cell USING l_h_cnt 1 1 text-011.
      PERFORM fill_cell USING l_h_cnt 3 1 text-012.
    Range for header
      range_item-name = 'RANGE1'.
      range_item-rows = '7'.
      range_item-columns = '3'.
      range_item-code = g_handle->spreadsheet_insertall.
      APPEND range_item TO range_list.
      CALL METHOD g_handle->set_selection
        EXPORTING
          left    = 1
          top     = 1
          rows    = 7
          columns = 3
        IMPORTING
          retcode = retcode.
      CALL METHOD g_handle->insert_range
        EXPORTING
          columns = 3
          rows    = 7
          name    = 'RANGE1'
        IMPORTING
          retcode = retcode.
      CALL METHOD g_handle->set_ranges_data
        EXPORTING
          ranges   = range_list
          contents = gt_cell_data
        IMPORTING
          retcode  = retcode.
    Columns for PC
      CLEAR: gt_cell_data[].
      l_pc_cnt  = l_h_cnt + 1.
      LOOP AT lt_dfies INTO lwa_dfies.
        IF lwa_dfies-fieldname EQ 'SBWHR' OR
           lwa_dfies-fieldname CP '_PC'.
          PERFORM fill_cell USING l_pc_cnt 1 0 lwa_dfies-scrtext_m.
          l_pc_cnt =  l_pc_cnt + 1.
        ENDIF.
      ENDLOOP.
    Pos Curr - Values
      PERFORM fill_cell USING 9 2 0  trls_position_value-sbwhr.
      PERFORM fill_cell USING 10 2 0 trls_position_value-purch_pc.
      PERFORM fill_cell USING 11 2 0 trls_position_value-charge_pc.
      PERFORM fill_cell USING 12 2 0 trls_position_value-impmnt_pc.
      PERFORM fill_cell USING 13 2 0 trls_position_value-amort_pc.
      PERFORM fill_cell USING 14 2 0 trls_position_value-val_ti_pc.
      PERFORM fill_cell USING 15 2 0 trls_position_value-val_idx_pc.
      PERFORM fill_cell USING 16 2 0 trls_position_value-val_ch_ti_pc.
      PERFORM fill_cell USING 17 2 0 trls_position_value-val_ti_npl_pc.
      PERFORM fill_cell USING 18 2 0 trls_position_value-val_idx_npl_pc.
      PERFORM fill_cell USING 19 2 0 trls_position_value-val_ch_ti_npl_pc.
      PERFORM fill_cell USING 20 2 0 trls_position_value-book_val_pc.
    Columns for VC
      l_vc_cnt = l_h_cnt + 1.
      LOOP AT lt_dfies INTO lwa_dfies.
        IF lwa_dfies-fieldname EQ 'SBWHR' OR
             lwa_dfies-fieldname CP '_VC'.
          PERFORM fill_cell USING l_vc_cnt 3 0 lwa_dfies-scrtext_m.
          l_vc_cnt =  l_vc_cnt + 1.
        ENDIF.
      ENDLOOP.
    Val Curr
      PERFORM fill_cell USING 9 4 0  trls_position_value-svwhr.
      PERFORM fill_cell USING 10 4 0 trls_position_value-purch_vc.
      PERFORM fill_cell USING 11 4 0 trls_position_value-charge_vc.
      PERFORM fill_cell USING 12 4 0 trls_position_value-impmnt_vc.
      PERFORM fill_cell USING 13 4 0 trls_position_value-amort_vc.
      PERFORM fill_cell USING 14 4 0 trls_position_value-val_ti_vc.
      PERFORM fill_cell USING 15 4 0 trls_position_value-val_fx_vc.
      PERFORM fill_cell USING 16 4 0 trls_position_value-val_idx_vc.
      PERFORM fill_cell USING 17 4 0 trls_position_value-val_ch_ti_vc.
      PERFORM fill_cell USING 18 4 0 trls_position_value-val_ch_fx_vc.
      PERFORM fill_cell USING 19 4 0 trls_position_value-val_fx_npl_vc.
      PERFORM fill_cell USING 20 4 0 trls_position_value-val_ti_npl_vc.
      PERFORM fill_cell USING 21 4 0 trls_position_value-val_idx_npl_vc.
      PERFORM fill_cell USING 22 4 0 trls_position_value-val_ch_ti_npl_vc.
      PERFORM fill_cell USING 23 4 0 trls_position_value-val_ch_fx_npl_vc.
      PERFORM fill_cell USING 24 4 0 trls_position_value-book_val_vc.
    Range for PC and VC
      CLEAR: range_list[].
      range_item-name = 'RANGE2'.
      range_item-rows = '17'.
      range_item-columns = '4'.
      range_item-code = g_handle->spreadsheet_insertall.
      APPEND range_item TO range_list.
      CALL METHOD g_handle->set_selection
        EXPORTING
          left    = 1
          top     = 9
          rows    = 17
          columns = 4
        IMPORTING
          retcode = retcode.
      CALL METHOD g_handle->insert_range
        EXPORTING
          columns = 4
          rows    = 17
          name    = 'RANGE2'
        IMPORTING
          retcode = retcode.
      CALL METHOD g_handle->set_ranges_data
        EXPORTING
          ranges   = range_list
          contents = gt_cell_data
        IMPORTING
          retcode  = retcode.
    ***********************************Form routine****************
    FORM fill_cell USING i j bold val.
      DATA:
       wa_cell_data TYPE soi_generic_item.
      wa_cell_data-row = i.
      wa_cell_data-column = j.
      wa_cell_data-value = val.
      APPEND wa_cell_data TO gt_cell_data.
    ENDFORM.                    "FILL_CELL

    Solved

  • Procedure/batch file to export data from sql to excel(predefined path)

    Hi,
    I have countries, sites, states tables (total 3) in database (i have user id and password to connect to this database).
    every week i need to extract data from these tables into excel files and i need to save those in shared drive for team use.
    Currently i am connecting to database every time running sql query and manually exporting that latest data to excel and saving that as excel files in (G:\team\common\) folder with specific name.
    output format should be : excel (.xls)
    file names should - countries.xls,sites.xls,states.xls
    server name : ap21
    output location : G:\team\common\ ( G is shared drive).
    i heard that we could create batch file to do this task and also we could use oracle procedure to do this task. but not sure which one is the best option.
    could you please guide me what is the option and also help me with technical stuff to do this task.

    Hello,
    output format should be : excel (.xls)Do you really want to create .xls files? This is not easy to do because it is a proprietary (MS) binary format. You should consider other formats like .csv or .xlsx. Follow the link in the previous answer how to generate them.
    file names should ...The name of the files does not matter, you are free to name them as you like.
    server name : ap21
    output location : G:\team\common\ ( G is shared drive).You can write the file generated in the database only to directories that are accessible from the db as Oracle Directories. You could mount the shared drive to the db server, but it might be better to write the output to a server directory and then transfer them to the shared drive with OS-copy command or FTP.
    i heard that we could create batch file to do this task and also we could use oracle procedure to do this task. but not sure which one is the best option.I would use Oracle Scheduler to execute a PL/SQL procedure to generate the files and then a OS-batch file to transfer them. You can use the Scheduler to execute the batch file too, see {message:id=3895983}.
    Regards
    Marcus

  • Exporting data from arraylist to excel

    I'm working on a program, in which data is uploaded from an excel spreadsheet, modified through an arraylist and the UI, then dumped back to the excel spreadsheet...
    Currently, I can save the data to an xls spreadsheet, but it is actually saved as a tab-delimited text file...
    This causes a problem when I use the jdbc-odbc bridge to upload the data back to my arraylist, as it does not recognize this tab delimited file as a proper excel spreadsheet. So, what I need is to be able to save the data into a true excel spreadsheet. How do I go about doing this (preferably using the jdbc-odbc, NOT poi)?
    Here is what I currently use to save the data:
    try
    out = new FileOutputStream("myfile.xls");
    p = new PrintStream( out );
    p.println("Asset Tag\tPO Number\tOrder Date\tReceive Date\tName\tDescription");
    for (int i = inventory.size();i>0;i--)
    String inventoryout = (String)inventory.get(0);
    p.println (inventoryout);
    p.close();
    catch (Exception e)
    System.err.println ("Error writing to file");
    And here is what I use to read the data:
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection( "jdbc:odbc:exceltest" );
    Statement st1 = con.createStatement();
    ResultSet rs = st1.executeQuery( "Select * from [myfile$]" );
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();
    while (rs.next())
    for (int i = 1; i <= numberOfColumns; i++)
    if (i > 1)
    String columnValue = rs.getString(i);
    inventory.add(columnValue);
    System.out.println("");
    st1.close();
    con.close();
    catch(Exception ex)
    System.err.print("Exception: ");
    System.err.println(ex.getMessage());
    PS
    Sorry about the indentation, the text doesn't copy over correctly from my source...

    from http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=3&t=000964:
    "If you're using Microsoft's ODBC driver for Excel, I've got some bad news for you... no DELETE or UPDATE queries, and INSERT can only append to table. Read this from MS ... Excel ODBC Driver and Text ODBC Driver Notes. There might be 3rd party drivers out there that's more flexible... good luck though"
    Do also read:
    http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q178/7/17.ASP&NoWebContent=1
    So you can only append. Switch to POI.
    /Kaj

Maybe you are looking for

  • I am running itunes 10.5.0.142 but I can't update to 10.5.2

    I am running itunes 10.5.0.142 but I can't update to 10.5.2.  My laptop is running Windows 7.  It asks me if I want to update to 10.5.2 and I say yes, but then nothing else happens.

  • [solved] After sytem update ALSA only plays sound for root

    Hello. Yesterday I performed a system update as usual, and after rebooting I found that my user account does not have any sound anymore. Root has sound just fine. I checked and my user is still in the audio group. I even removed him from the group, a

  • How to know whether a particular query is using the aggregates

    hi all.... im very new to this group so plz help me out.....anyway hi to all .... There are many aggreegates are there but how to know which query is using perticular a?gregates

  • Api to interact with a Thumbprint Reader

    Hi, I have become interested in developing an application that uses a thumbprint reader and I was wondering if there is an Api or set of java classes that I can use to develop this application in java. Any directions would help.

  • Oracle startup

    What are the tasks that a dba can perform when. Database is in shutdown mode, NOMOUNT stage,Mount stage.