Skip to Content
author's profile photo Former Member
Former Member

Export to Excel in XS Project


Hi,

I want to export data from a table to excel in xs project.

Please help me.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Feb 24, 2014 at 04:11 PM

    Embedded in a web page - via XSJS? If so there is a sample of this in the SHINE content. I will cut and paste a bit of it here for you to view; but I really recommend studying the complete sample in SHINE.

    function downloadExcel() {

    var
    body = '';

    try {

    var
    query = 'SELECT TOP 25000 "PurchaseOrderId", "PartnerId",
    "CompanyName", "CreatedByLoginName",
    "History.CREATEDAT", "GrossAmount" '

    +
    'FROM "sap.hana.democontent.epm.data::purchaseOrderHeaderExternal"
    order by "PurchaseOrderId"';

    $.trace.debug(query);

    var
    conn = $.db.getConnection();

    var
    pstmt = conn.prepareStatement(query);

    var
    rs = pstmt.executeQuery();

    body
    = MESSAGES.getMessage('SEPM_POWRK', '002') + "\t" + // Purchase

    // Order ID

    MESSAGES.getMessage('SEPM_POWRK',
    '003') + "\t" + // Partner ID

    MESSAGES.getMessage('SEPM_POWRK',
    '001') + "\t" + // Company Name

    MESSAGES.getMessage('SEPM_POWRK',
    '004') + "\t" + // Employee

    //
    Responsible

    MESSAGES.getMessage('SEPM_POWRK',
    '005') + "\t" + // Created At

    MESSAGES.getMessage('SEPM_POWRK',
    '006') + "\n"; // Gross Amount

    while
    (rs.next()) {

    body
    += rs.getNString(1) + "\t" + rs.getNString(2) + "\t"

    +
    rs.getNString(3) + "\t" + rs.getNString(4) + "\t"

    +
    rs.getDate(5) + "\t" + rs.getDecimal(6) + "\n";

    }

    } catch
    (e) {

    $.response.status
    = $.net.http.INTERNAL_SERVER_ERROR;

    $.response.setBody(e.message);

    return;

    }

    $.response.setBody(body);

    $.response.contentType
    = 'application/vnd.ms-excel; charset=utf-16le';

    $.response.headers.set('Content-Disposition',

    'attachment;
    filename=Excel.xls');

    $.response.status
    = $.net.http.OK;

    }



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 18, 2014 at 05:16 PM

    Hi Thomas -

    While doing this, can we also format the data before putting it in excel. For ex - Instead of using dot as decimal separator, can we change it to comma or vice-versa.

    regards

    Amit

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 13, 2016 at 12:57 PM

    Hi All,

    May I know where the sample code is available in SAP SHINE.

    Thanks,

    Supriya

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.