Export data to excel with EPPlus and Web Api - HELP!

I am trying to do a simple excel file export with EPPlus and Web Api. In the html client I have a button that calls the web api and opens a new window. No error is thrown, but the result is always "file could not be downloaded".  I get the
save file dialog but the file name is Order/ instead of the expected Orders.xls or Orders.xlsx.  Can anyone help? I'm surprised this is so difficult.
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using OfficeOpenXml;
using System.Collections.Generic;
using System.IO;
using System.Net.Http.Headers;
using System.Net;
using System.ComponentModel.DataAnnotations;
namespace LightSwitchApplication
public class OrdersController : ApiController
// GET: api/Orders
[HttpGet]
public HttpResponseMessage Get()
HttpResponseMessage response;
response = Request.CreateResponse(HttpStatusCode.OK);
MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/octet-stream");
response.Content = new StreamContent(GetExcelSheet());
response.Content.Headers.ContentType = mediaType;
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "Orders.xls";
return response;
public List<Order> GetOrders()
List<Order> colOrders = new List<Order>();
using (ServerApplicationContext ctx = ServerApplicationContext.Current ??
ServerApplicationContext.CreateContext())
colOrders = ctx.DataWorkspace.Data.Orders.GetQuery().Execute().ToList();
return colOrders;
public MemoryStream GetExcelSheet()
using (var package = new ExcelPackage())
var worksheet = package.Workbook.Worksheets.Add("Orders");
worksheet.Cells["A1"].LoadFromCollection(GetOrders(), false);
package.Save();
var stream = new MemoryStream(package.GetAsByteArray());
return stream;
This has been driving me crazy for two days!

Making some progress.  I got the spreadsheet into a byte[] and used code from Paul Van
Bladel's blog to make the HttpResponseMessage.  If I comment out the LightSwitch data access code, this works to export a spreadsheet from a static list to the browser from Web Api.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Details;
using OfficeOpenXml;
using System.ComponentModel.DataAnnotations;
namespace LightSwitchApplication
public class Order
[Key]
public int Id { get; set; }
public string OrderNumber { get; set; }
public class OrdersController : ApiController
// GET: api/Orders
[HttpGet]
public HttpResponseMessage Download()
MediaTypeHeaderValue mediaType =
MediaTypeHeaderValue.Parse("application/octet-stream");
byte[] excelFile = ExcelSheet();
string fileName = "Orders.xlsx";
MemoryStream memoryStream = new MemoryStream(excelFile);
HttpResponseMessage response =
response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StreamContent(memoryStream);
response.Content.Headers.ContentType = mediaType;
response.Content.Headers.ContentDisposition =
new ContentDispositionHeaderValue("fileName") { FileName = fileName };
return response;
public List<Order> Orders()
List<Order> orders = new List<Order>();
orders.Add(new Order { Id = 1, OrderNumber = "123456789" });
orders.Add(new Order { Id = 2, OrderNumber = "987654321" });
return orders;
// this doesn't work
//public List<Order> Orders()
// List<Order> colOrders = new List<Order>();
// using (ServerApplicationContext ctx = ServerApplicationContext.Current ??
// ServerApplicationContext.CreateContext())
// colOrders = ctx.DataWorkspace.Data.Orders.GetQuery().Execute().ToList();
// return colOrders;
public byte[] ExcelSheet()
using (var package = new ExcelPackage())
var worksheet = package.Workbook.Worksheets.Add("Orders");
worksheet.Cells["A1"].LoadFromCollection(Orders(), false);
byte[] bytes = package.GetAsByteArray();
return bytes;
The problem is that the LightSwitch query (commented out in the code above) is trying to load navigation properties for the orders.  Error: "It is not valid to access this object on the current thread."  How do I solve this? 

Similar Messages

  • Export Data to Excel with commands API

    Hello,With commands API, we want to add the possibility to Export Data to Excel to our users, but we don't want to give them the acess to the mouse right button, because they can change others things that we don't want.How can we do that ?Thanks.

    Hello,With commands API, we want to add the possibility to Export Data to Excel to our users, but we don't want to give them the acess to the mouse right button, because they can change others things that we don't want.How can we do that ?Thanks.

  • Export  data in Excel file - Debug and Break Point

    In the program RFUMSV00 the data  been displayed on the screen with the function REUSE_ALV_LIST_DISPLAY.
    With "Cntrl + Shift + F9" I exported the list of data in an Excel file.
    How can I see, with Debug, where the program RFUMSV00 passed the data to Excel File? I can indicate the point, In the program, where I need to set the break point?
    Thanks,
    Serena

    Hi,
    This download functionality has nothing to have with program RFUMSV00. It is actually processed by REUSE_ALV_LIST_DISPLAY fm, which calls fm LIST_COMMAND which finally calls fm LIST_DOWNLOAD, where you will actually find the downloading part (in fact in another fm, DOWNLOAD_LIST)...
    to resume: REUSE_ALV_LIST_DISPLAY->LIST_COMMAND->LIST_DOWNLOAD->DOWNLOAD_LIST
    so I would put the break-point in the last one..
    Kr,
    Manu.
    correction: I made a mistake, the break-point should be set in LIST_DOWNLOAD...where you will find the call to fm LIST_CONVERT_TO_DAT which is responsible of the download...
    Edited by: Manu D'Haeyer on Dec 9, 2011 1:46 PM

  • Exporting data to excel with time stamp

    We have written an express VI code recording voltage. The code works, and the data is recorded, but the data is transferred to an excel file without the time stamp. In the excel file we have the data down column A, but there is no time at which any of the data was recorded. Is there a way we can get the time recorded in excel also? Thanks for the help.

    I maybe wrong but I believe that the timestamp data associated with the data that is logged will be in the TDMS file as properties of those channels.  Are you sure the time data isn't logged as a property?
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • EXport Data to Excel with Columns format

    Dear All,
    This may  be a basic question, however, I just need a tip to conclude my issue. 
    I have a Report that displays Financial Budget data (AFE).  I am able to download to the Excel sheet.  However, I need to conclude it with the column formatted at code itself and not given to the user.
    That is I want to set couple of column to Numeric, and Set Colum width defined at Code level itself.
    I am already using the Function module : MS_EXCEL_OLE_STANDARD_DAT
    Regards,
    Venkat

    data: go_excel       type ole2_object,
              Go_CELL        TYPE OLE2_OBJECT,
              go_workbooks   TYPE OLE2_OBJECT,
              go_workbook    TYPE OLE2_OBJECT,
              go_sheet       type OLE2_OBJECT,
              go_application type OLE2_OBJECT,
              go_activesheet type OLE2_OBJECT,
              go_text        type OLE2_OBJECT.
        gv_EXTRD = sy-datum.
        gv_EXTRT = sy-uzeit.
        concatenate pfile gv_EXTRD gv_EXTRT  'check.xls' into gv_file.
        clear: gt_export, gs_export.
    ****INITIATE EXCEL
    Create object Excel
        create object go_excel 'EXCEL.APPLICATION'.
        set property of go_excel 'Visible' = 0.
    Create workbook object
        call method of go_excel 'WORKBOOKS' = go_workbook .
      Add workbook
        call method of go_workbook 'Add' = go_workbook.
        lv_line = 0.
        loop at gt_collect ASSIGNING <collect>.
          lv_line = lv_line + 1.
          move-corresponding <collect> to gs_export.
          clear: gs_export-ZALDT.
          concatenate <collect>-ZALDT4(2) '-' <collect>-ZALDT6(2) '-' <collect>-ZALDT+0(4)
               into gs_export-ZALDT.
    Populate cells
          call method of go_excel 'Cells' = Go_CELL
            EXPORTING
              #1 = lv_line
              #2 = 1.
    **************SET UP PROPERTY WIDTH ****************************
          SET PROPERTY OF GO_CELL 'ColumnWidth' = '11'.
          SET PROPERTY OF GO_CELL 'Value' = gs_export-BANKL.
    ***********SET PROPERTY CELL NUMBER**************************************
          call method of go_excel 'Cells' = Go_CELL
            EXPORTING
              #1 = lv_line
              #2 = 4.
          SET PROPERTY OF go_cell 'NumberFormat' = '@'.     "PROPERTY NUMBER
          SET PROPERTY OF GO_CELL 'ColumnWidth' = '10'.
          SET PROPERTY OF GO_CELL 'Value' = gs_export-ZALDT.
    endloop.
    **CLOSE EXCEL**********
        CALL METHOD OF go_workbook 'SaveAs'
          EXPORTING #1 = gv_file
          #2 = 1.
        "file format
        CALL METHOD OF go_workbook 'close'.                                    "file format
        call method of go_excel 'QUIT'.
    ****OPEN CREATED EXCEL FILE ****************************
        call method of go_excel 'Workbooks' = go_workbooks.
        call method of go_workbooks 'Open'
          EXPORTING
            #1 = gv_file.
        set property of go_excel 'Visible' = 1.

  • Export data to excel with multiple worksheet

    Hi all,
    Thanks to Roel, Andy, Scott, and Varad. I could go this far with my first project with APEX :)
    thank you guys !!
    I am left with one last bit (unless the client request more feature). I need to export the database to an excel spreadsheet.
    I have about 5 tables so I need to create 5 worksheet in the excel file.
    Now I have tried OWA_SYLK from Tom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:728625409049#PAGETOP)
    it works in my environment, but I just don't know how to create multiple worksheet in one excel file.
    I read on the internet that XML spreadsheet is the answer but how to do that, I don't know.
    Can anyone enlighten me?
    Thanks.
    Joel

    It's easy with free RXLS PL/SQL library :
    Procedure Test_002 is
    wbk RXLS.XLS_WorkBook; -- workBook data structure
    f1 integer; f2 integer; -– two workSheets
    Begin
    RXLS.NewWorkBook (wbk); -- new WorkBook init.
    -- two worksheets creation
    f1 := RXLS.NewSheet (Wbk,'Departments');
    f2 := RXLS.NewSheet (Wbk,'Employees');
    -- Writing into the first WorkSheet data from the first SQL request (DEPT)
    RXLS.SQLtoXLS (xSQL => 'select * from Dept', xSheet => f1, xWbk => wbk, xR => 3, xC=> 2,
    xMaxRows => 100, xMaxCols => 20);
    -- Writing into the second WorkSheet data from the second SQL request (EMP)
    RXLS.SQLtoXLS (xSQL => 'select * from Emp', xSheet => f2, xWbk => wbk, xR => 1, xC => 3,
    xMaxRows => 20, xMaxCols => 10);
    -- Excel Workbook or Open Office document , (MS XML 2003 format)
    RXLS.GenXLS (wbk);
    -- Dowload to IE or FF
    RXLS.Show (wbk);
    end; -- ex 2
    [www.rci-informatique.fr/rxls]

  • Export data to excel with powershell

    Code i'm using: 
    $Filter = @{Expression={$_.Name};Label="DiskName"}, `
    @{Expression={$_.Label};Label="Label"}, `
    @{Expression={$_.FileSystem};Label="FileSystem"}, `
    @{Expression={[int]$($_.BlockSize/1KB)};Label="BlockSizeKB"}, `
    @{Expression={[int]$($_.Size / 1gb)};Label="CapacityGB"}, `
    @{Expression={[int]$($_.Freespace/1GB)};Label="FreeSpaceGB"}
    Get-WmiObject –Class Win32_LogicalDisk –ComputerName 127.1.1.1 | Format-Table $Filter –AutoSize
    Result i get: 
    My question:
    What command(s) Can i use to put this infromation (Amount of Space free) in the right place at Excel? Lets say B5-B20 needs to be the amount of free space of Disk C:, and D5-D20 needs to be the mount of free space on disk D? etc?.. Is this Possible? 
    I want to use this on 5-10 servers. - This script will be done every week
    THanks all.
    Regards,
    Kece

    Hey thanks for your reaction i get this error I use your code- but it makes the CSV file. 
    Exception getting "Item": "Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))"
    At line:5 char:17
    + 1..2 | ForEach {$workbook.worksheets.item(2).Delete()}
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], GetValueInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertyGetValueTI
    Exception getting "Item": "Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))"
    At line:5 char:17
    + 1..2 | ForEach {$workbook.worksheets.item(2).Delete()}
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], GetValueInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertyGetValueTI
    Out-N : The term 'Out-N' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the sp
    elling of the name, or if a path was included, verify that the path is correct and try again.
    At line:29 char:90
    + ... ject]$excel) | Out-N
    + ~~~~~
    + CategoryInfo : ObjectNotFound: (Out-N:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    result of the code:
    Server A: FreeSpaceGB C: FreeSpaceGB E: FreeSpaceGB
    192.X.X.X 13,40331268 543,4093399 0
    192.X.X.X 0 16,05441666 66,05538177
    Is it possible to get - Diskcapacity + freescape? 
    btw im also exprimenting on this code
    Thanks!
    You are demanding others write a script for you and you are not making any effort to understand how to use a script.  The answer was given explicitly long ago.  You just don't understand.  Now you have a much more complicated and error prone
    script that does less that your original script.  Please try to think about what is happening and why.
    ¯\_(ツ)_/¯

  • Export data to excel in alv

    hi everybody ,
    could you give me an example about export data to excel with no ole objects?

    You can use FM - ALV_XXL_CALL , it exports the data with formatting and column heading.
    REPORT  ZSKC_ALV_XXL.
    TYPE-POOLS : KKBLO.
    DATA : ITAB LIKE T100 OCCURS 0,
           T_FCAT_LVC TYPE LVC_S_FCAT OCCURS 0 WITH HEADER LINE,
           T_FCAT_KKB TYPE KKBLO_T_FIELDCAT.
    START-OF-SELECTION.
    * Get data.
      SELECT * UP TO 20 ROWS
      FROM   T100
      INTO   TABLE ITAB
      WHERE  SPRSL = SY-LANGU.
      CHECK SY-SUBRC EQ 0.
    * Create the field catalog.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
          I_STRUCTURE_NAME             = 'T100'
        CHANGING
          CT_FIELDCAT                  = T_FCAT_LVC[]
        EXCEPTIONS
          INCONSISTENT_INTERFACE       = 1
          PROGRAM_ERROR                = 2
          OTHERS                       = 3.
      CHECK SY-SUBRC EQ 0.
    * make sure you pass the correct internal table name in the field catalog.
      t_fcat_lvC-tabname = 'ITAB'.
      MODIFY T_FCAT_LVC TRANSPORTING TABNAME WHERE TABNAME NE SPACE.
    * Transfer to KKBLO format.
      CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
        EXPORTING
          IT_FIELDCAT_LVC                 = T_FCAT_LVC[]
        IMPORTING
          ET_FIELDCAT_KKBLO               = T_FCAT_KKB
       EXCEPTIONS
         IT_DATA_MISSING                 = 1
         IT_FIELDCAT_LVC_MISSING         = 2
         OTHERS                          = 3.
      CHECK SY-SUBRC EQ 0.
    * Call XXL.
      CALL FUNCTION 'ALV_XXL_CALL'
        EXPORTING
          I_TABNAME                    = 'ITAB'
          IT_FIELDCAT                  = T_FCAT_KKB
        TABLES
          IT_OUTTAB                    = ITAB[]
        EXCEPTIONS
          FATAL_ERROR                  = 1
          NO_DISPLAY_POSSIBLE          = 2
          OTHERS                       = 3.
      IF SY-SUBRC <> 0.
      ENDIF.

  • Export data to excel and table column headers

    I noticed that with LV 2012 when I call the method "Export Data to Excel" for a table, the table headers (= column names) are not exported to excel.
    Am I right? I think that the column names should be exported too...
    As a matter of fact when you call the method "Export to simplified image" the column names are included
    How can I export the table column names to excel?
    Vix
    In claris non fit interpretatio
    Using LV 2013 SP1 on Win 7 64bit
    Using LV 8.2.1 on WinXP SP3
    Using CVI 2012 SP1 on Win 7 64bit, WinXP and WinXP Embedded
    Using CVI 6.0 on Win2k, WinXP and WinXP Embedded

    In this document there is a full description of how to export data from LabVIEW to Excel.
    Using a table, the method "Export data to excel" should export the "currently selected data", and data can be programmatically selected using ActiveCell property (as described here).
    With ActiveCell I can select the column headers too (using negative numbers for row and/or column), and I do this.
    And so I expect that when I select "Export data to Excel", the column headers should be exported too (because I selected them!).
    I think that the actual behavior is a bug, rather that an expected behavior.
    Don't you agree?
    Vix
    In claris non fit interpretatio
    Using LV 2013 SP1 on Win 7 64bit
    Using LV 8.2.1 on WinXP SP3
    Using CVI 2012 SP1 on Win 7 64bit, WinXP and WinXP Embedded
    Using CVI 6.0 on Win2k, WinXP and WinXP Embedded

  • Problem in exporting data to excel in nwds 7.3

    Hi All,
    I was using the following code for exporting data to excel in NWDS 7.3
    private IWDCachedWebResource getCachedWebResource(byte[] file, String name,
    WDWebResourceType type) {
    IWDCachedWebResource cachedWebResource = null;
    if (file != null) {
    cachedWebResource = WDWebResource.getWebResource(file, type);
    cachedWebResource.setResourceName(name);
    return cachedWebResource;
    I was getting the error in the following line cachedWebResource = WDWebResource.getWebResource(file, type); when I clicked the quick help it ststed the getWebResource method is depricated.  Kindly provide some assistance on what is the new method in its place.
    Thank you
    Regards,
    Preet Kaur

    Hi Ganesh,
    Thanks that worked fine, but when we go further we are facing problem ie
    byte[] excelXMLFile;
    IWDCachedWebResource cachedExcelResource = null;
    String fileName = dataNode.getNodeInfo().getName() + ".xls";
    try {
    // create Excel 2003 XML data as a byte array for the given context node,
    // attributes and headers
    excelXMLFile = toExcel(dataNode, columnInfos).getBytes("UTF-8");
    // create a cached Web Dynpro XLS resource for the given byte array
    // and filename
    cachedExcelResource = getCachedWebResource(
    excelXMLFile, fileName, WDWebResourceType.XLS);
    // Store URL and file name of cached Excel resource in context.
    if (cachedExcelResource != null) {
    wdContext.currentContextElement().setExcelFileURL(
    cachedExcelResource.getURL());
    wdContext.currentContextElement().setExcelFileName(
    cachedExcelResource.getResourceName());
    // Open popup window with a link to the cached Excel file Web resource.
    openExcelLinkPopup();
    } else {
    wdComponentAPI.getMessageManager().reportException(
    "Failed to create Excel file from table!", true);
    } catch (UnsupportedEncodingException e) {
    wdComponentAPI.getMessageManager().reportException(
    e.getLocalizedMessage(), true);
    } catch (WDURLException e) {
    wdComponentAPI.getMessageManager().reportException(
    e.getLocalizedMessage(), true);
    The above bold lines also would need to be converted to inputstream, but not sure how to correct that
    We are following the below pdf for the implementation.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/edc2f3c2-0401-0010-8898-acd5b6a94353?QuickLink=index&overridelayout=true
    Thank you
    Regards,
    Jaspreet Kaur

  • How to export Data to excel in wp8

    Hi,
    I have a requirement like export data to excel. I have googled and find OpenXML.Silverlight.Spreadsheet.WP8.dll . Its working good. I want to know is there any Other way to create an excel file and export data to Excel sheet in WP8..?
    I googled and find EPPlus.dll but it is throwing an exception. The exception is "A reference to a higher version or incompatible assembly cannot be added to a project."  
    Is there any another way to export data to excel sheet.? Please support me with answers.
    Thanks in Advance.

    Syncfusion controls for windows phone has a library for creating spreadsheets xlsio.  It i free if you qualify for community license
    https://www.syncfusion.com/products/communitylicense
    https://www.syncfusion.com/products/file-formats/xlsio

  • Upload data from excel with vba by calling a function module

    Hello all,
    i have a problem with the function module "ALSM_EXCEL_TO_INTERNAL_TABLE". I will call this function module with vba to load data from excel to sap with a Buttonclick. I have copied this function module and set it remotable. But i can´t call it from excel.
    Can you give me some tips how can i
    upload data from excel with vba by click a button.
    The problem seems the function: call method cl_gui_frontend_services=>clipboard_import in the function module, because when i comment this function call the vba-call is true but no results. 
    How can I call the function module correct with vba?
    Thanks a lot for your tips!!!!
    Chris
    Message was edited by:
            Christoph Kirschner

    HI
    Uploading data directly from Excel file format
    * Upload data direct from excel.xls file to SAP
    REPORT ZEXCELUPLOAD.
    PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
                begcol TYPE i DEFAULT 1 NO-DISPLAY,
                begrow TYPE i DEFAULT 1 NO-DISPLAY,
                endcol TYPE i DEFAULT 100 NO-DISPLAY,
                endrow TYPE i DEFAULT 32000 NO-DISPLAY.
    * Tick don't append header
    PARAMETERS: kzheader AS CHECKBOX.
    DATA: BEGIN OF intern OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern.
    DATA: BEGIN OF intern1 OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern1.
    DATA: BEGIN OF t_col OCCURS 0,
           col LIKE alsmex_tabline-col,
           size TYPE i.
    DATA: END OF t_col.
    DATA: zwlen TYPE i,
          zwlines TYPE i.
    DATA: BEGIN OF fieldnames OCCURS 3,
            title(60),
            table(6),
            field(10),
            kz(1),
          END OF fieldnames.
    * No of columns
    DATA: BEGIN OF data_tab OCCURS 0,
           value_0001(50),
           value_0002(50),
           value_0003(50),
           value_0004(50),
           value_0005(50),
           value_0006(50),
           value_0007(50),
           value_0008(50),
           value_0009(50),
           value_0010(50),
           value_0011(50),
           value_0012(50),
           value_0013(50),
           value_0014(50),
           value_0015(50),
           value_0016(50),
           value_0017(50),
           value_0018(50),
           value_0019(50),
           value_0020(50),
           value_0021(50),
           value_0022(50),
           value_0023(50),
           value_0024(50),
           value_0025(50),
           value_0026(50),
           value_0027(50),
           value_0028(50),
           value_0029(50),
           value_0030(50),
           value_0031(50),
           value_0032(50),
           value_0033(50),
           value_0034(50),
           value_0035(50),
           value_0036(50),
           value_0037(50),
           value_0038(50),
           value_0039(50),
           value_0040(50),
           value_0041(50),
           value_0042(50),
           value_0043(50),
           value_0044(50),
           value_0045(50),
           value_0046(50),
           value_0047(50),
           value_0048(50),
           value_0049(50),
           value_0050(50),
           value_0051(50),
           value_0052(50),
           value_0053(50),
           value_0054(50),
           value_0055(50),
           value_0056(50),
           value_0057(50),
           value_0058(50),
           value_0059(50),
           value_0060(50),
           value_0061(50),
           value_0062(50),
           value_0063(50),
           value_0064(50),
           value_0065(50),
           value_0066(50),
           value_0067(50),
           value_0068(50),
           value_0069(50),
           value_0070(50),
           value_0071(50),
           value_0072(50),
           value_0073(50),
           value_0074(50),
           value_0075(50),
           value_0076(50),
           value_0077(50),
           value_0078(50),
           value_0079(50),
           value_0080(50),
           value_0081(50),
           value_0082(50),
           value_0083(50),
           value_0084(50),
           value_0085(50),
           value_0086(50),
           value_0087(50),
           value_0088(50),
           value_0089(50),
           value_0090(50),
           value_0091(50),
           value_0092(50),
           value_0093(50),
           value_0094(50),
           value_0095(50),
           value_0096(50),
           value_0097(50),
           value_0098(50),
           value_0099(50),
           value_0100(50).
    DATA: END OF data_tab.
    DATA: tind(4) TYPE n.
    DATA: zwfeld(19).
    FIELD-SYMBOLS: <fs1>.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                mask      = '*.xls'
                static    = 'X'
           CHANGING
                file_name = filename.
    START-OF-SELECTION.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                filename                = filename
                i_begin_col             = begcol
                i_begin_row             = begrow
                i_end_col               = endcol
                i_end_row               = endrow
           TABLES
                intern                  = intern
           EXCEPTIONS
                inconsistent_parameters = 1
                upload_ole              = 2
                OTHERS                  = 3.
      IF sy-subrc <> 0.
        WRITE:/ 'Upload Error ', SY-SUBRC.
      ENDIF.
    END-OF-SELECTION.
      LOOP AT intern.
        intern1 = intern.
        CLEAR intern1-row.
        APPEND intern1.
      ENDLOOP.
      SORT intern1 BY col.
      LOOP AT intern1.
        AT NEW col.
          t_col-col = intern1-col.
          APPEND t_col.
        ENDAT.
        zwlen = strlen( intern1-value ).
        READ TABLE t_col WITH KEY col = intern1-col.
        IF sy-subrc EQ 0.
          IF zwlen > t_col-size.
            t_col-size = zwlen.
    *                          Internal Table, Current Row Index
            MODIFY t_col INDEX sy-tabix.
          ENDIF.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE t_col LINES zwlines.
      SORT intern BY row col.
      IF kzheader = 'X'.
        LOOP AT intern.
          fieldnames-title = intern-value.
          APPEND fieldnames.
          AT END OF row.
            EXIT.
          ENDAT.
        ENDLOOP.
      ELSE.
        DO zwlines TIMES.
          WRITE sy-index TO fieldnames-title.
          APPEND fieldnames.
        ENDDO.
      ENDIF.
      SORT intern BY row col.
      LOOP AT intern.
        IF kzheader = 'X'
        AND intern-row = 1.
          CONTINUE.
        ENDIF.
        tind = intern-col.
        CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
        ASSIGN (zwfeld) TO <fs1>.
        <fs1> = intern-value.
        AT END OF row.
          APPEND data_tab.
          CLEAR data_tab.
        ENDAT.
      ENDLOOP.
      CALL FUNCTION 'DISPLAY_BASIC_LIST'
           EXPORTING
                file_name     = filename
           TABLES
                data_tab      = data_tab
                fieldname_tab = fieldnames.
    *-- End of Program
    <b>Excel Upload Alternative - KCD_EXCEL_OLE_TO_INT_CONVERT</b>
    *Title : Excel Uploading
    TYPES:   BEGIN OF t_datatab,
             col1(25)  TYPE c,
             col2(30)  TYPE c,
             col3(30)  TYPE c,
             col4(30)  TYPE c,
             col5(30)  TYPE c,
             col6(30)  TYPE c,
             col7(30) TYPE c,
             col8(30)  TYPE c,
             col9(30)  TYPE c,
             col10(30)  TYPE c,
             col11(30)    TYPE c,
           END OF t_datatab.
    DATA: it_datatab TYPE STANDARD TABLE OF t_datatab INITIAL SIZE 0,
          wa_datatab TYPE t_datatab.
    Data : p_table type t_datatab occurs 0 with header line.
    DATA : gd_scol   TYPE i VALUE '1',
           gd_srow   TYPE i VALUE '1',
           gd_ecol   TYPE i VALUE '256',
           gd_erow   TYPE i VALUE '65536'.
    DATA: it_tab TYPE filetable,
          gd_subrc TYPE i.
    field-symbols : <fs>.
    *Selection screen definition
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS:  p_file LIKE rlgrap-filename
                   DEFAULT 'c:test.xls' OBLIGATORY.   " File Name
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      REFRESH: it_tab.
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title     = 'Select File'
          default_filename = '*.xls'
          multiselection   = ' '
        CHANGING
          file_table       = it_tab
          rc               = gd_subrc.
      LOOP AT it_tab INTO p_file.
    *    so_fpath-sign = 'I'.
    *    so_fpath-option = 'EQ'.
    *    append so_fpath.
      ENDLOOP.
    START-OF-SELECTION.
      PERFORM upload_excel_file TABLES   it_datatab
                                 USING   p_file
                                         gd_scol
                                         gd_srow
                                         gd_ecol
                                         gd_erow.
    * END-OF-SELECTION.
    END-OF-SELECTION.
      LOOP AT it_datatab INTO wa_datatab.
        WRITE:/ wa_datatab-col1,
                wa_datatab-col2,
                wa_datatab-col3,
                wa_datatab-col4,
                wa_datatab-col5,
                wa_datatab-col6,
                wa_datatab-col7,
                wa_datatab-col8,
                wa_datatab-col9,
                wa_datatab-col10,
                wa_datatab-col11.
      ENDLOOP.
    *&      Form  UPLOAD_EXCEL_FILE
    *       upload excel spreadsheet into internal table
    *      -->P_TABLE    Table to return excel data into
    *      -->P_FILE     file name and path
    *      -->P_SCOL     start column
    *      -->P_SROW     start row
    *      -->P_ECOL     end column
    *      -->P_EROW     end row
    FORM upload_excel_file TABLES   p_table
                           USING    p_file
                                    p_scol
                                    p_srow
                                    p_ecol
                                    p_erow.
      DATA : lt_intern TYPE  kcde_cells OCCURS 0 WITH HEADER LINE.
    * Has the following format:
    *             Row number   | Colum Number   |   Value
    *      i.e.     1                 1             Name1
    *               2                 1             Joe
      DATA : ld_index TYPE i.
    * Note: Alternative function module - 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
        EXPORTING
          filename                = p_file
          i_begin_col             = p_scol
          i_begin_row             = p_srow
          i_end_col               = p_ecol
          i_end_row               = p_erow
        TABLES
          intern                  = LT_INTERN
        EXCEPTIONS
          inconsistent_parameters = 1
          upload_ole              = 2
          OTHERS                  = 3.
      IF sy-subrc <> 0.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        WRITE:/ 'Error Uploading file'.
        EXIT.
      ENDIF.
      IF lt_intern[] IS INITIAL.
        FORMAT COLOR COL_BACKGROUND INTENSIFIED.
        WRITE:/ 'No Data Uploaded'.
        EXIT.
      ELSE.
        SORT lt_intern BY row col.
        LOOP AT lt_intern.
         MOVE lt_intern-col TO ld_index.
         assign component ld_index of structure
         p_table to <fs>.
    move : lt_intern-value to <fs>.
    *     MOVE lt_intern-value TO p_table.
          AT END OF row.
            APPEND p_table.
            CLEAR p_table.
          ENDAT.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    "UPLOAD_EXCEL_FILE
    Regards
    Pavan

  • How to upload data from excel to SAP and options to be used

    How to upload data from excel to SAP and options to be used
    thank you,
    Regards,
    Jagrut Bharatkumar shukla

    Hi Jagrut,
        You can use gui_upload.
    chk the sample program mentioned below.
    REPORT ZFTP .
    DATA: BEGIN OF I_FILE OCCURS 0,
    DATA(2000) TYPE C,
    END OF I_FILE.
    DATA: BEGIN OF I_FILE2 OCCURS 0,
    DATA(2000) TYPE C,
    END OF I_FILE2.
    DATA: W_COUNT TYPE I.
    PARAMETERS: P_FILEN TYPE STRING,
    P_FILE2 TYPE STRING,
    P_NUM(4) TYPE N..
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILEN.
    PERFORM F_FILE_GET USING P_FILEN TEXT-G01.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE2.
    PERFORM F_FILE_GET USING P_FILE2 TEXT-G01.
    START-OF-SELECTION.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = P_FILEN
    FILETYPE = 'ASC'
    HAS_FIELD_SEPARATOR = 'X'
    HEADER_LENGTH = 0
    READ_BY_LINE = 'X'
    DAT_MODE = ' '
    CODEPAGE = ' '
    IGNORE_CERR = ABAP_TRUE
    REPLACEMENT = '#'
    CHECK_BOM = ' '
    VIRUS_SCAN_PROFILE =
    NO_AUTH_CHECK = ' '
    IMPORTING
    FILELENGTH =
    HEADER =
    tables
    data_tab = I_FILE
    IF SY-SUBRC <> 0.
    MESSAGE E024(Z1).
    ENDIF.
    LOOP AT I_FILE.
    W_COUNT = W_COUNT + 1.
    IF NOT W_COUNT > P_NUM.
    MOVE I_FILE TO I_FILE2.
    APPEND I_FILE2.
    ENDIF.
    ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    BIN_FILESIZE =
    filename = P_FILE2
    FILETYPE = 'ASC'
    APPEND = ' '
    WRITE_FIELD_SEPARATOR = 'X'
    HEADER = '00'
    TRUNC_TRAILING_BLANKS = ' '
    WRITE_LF = 'X'
    COL_SELECT = ' '
    COL_SELECT_MASK = ' '
    DAT_MODE = ' '
    CONFIRM_OVERWRITE = ' '
    NO_AUTH_CHECK = ' '
    CODEPAGE = ' '
    IGNORE_CERR = ABAP_TRUE
    REPLACEMENT = '#'
    WRITE_BOM = ' '
    TRUNC_TRAILING_BLANKS_EOL = 'X'
    WK1_N_FORMAT = ' '
    WK1_N_SIZE = ' '
    WK1_T_FORMAT = ' '
    WK1_T_SIZE = ' '
    IMPORTING
    FILELENGTH =
    tables
    data_tab = I_FILE2
    FIELDNAMES =
    *& Form F_FILE_GET
    text
    -->P_P_FILEN text
    -->P_TEXT_G01 text
    FORM F_FILE_GET USING L_FILENA L_TEXT.
    CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
    DEF_FILENAME = ' '
    DEF_PATH = ' '
    MASK = ',.,*.TXT.'
    MODE = 'O'
    TITLE = L_TEXT
    IMPORTING
    FILENAME = L_FILENA
    rc =
    EXCEPTIONS
    INV_WINSYS = 1
    NO_BATCH = 2
    SELECTION_CANCEL = 3
    SELECTION_ERROR = 4
    OTHERS = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Reward if helpful.
    Regards,
    Harini.S

  • Import data from excel/csv file in web dynpro

    Hi All,
    I need to populate a WD table by first importing a excel/CSV file thru web dynpro screen and then reading thru the file.Am using FileUpload element from NW04s.
    How can I read/import data from excel / csv file in web dynpro table context?
    Any help is appreciated.
    Thanks a lot
    Aakash

    Hi,
    Here are the basic steps needed to read data from excel spreadsheet using the Java Excel API(jExcel API).
    jExcel API can read a spreadsheet from a file stored on the local file system or from some input stream, ideally the following should be the steps while reading:
    Create a workbook from a file on the local file system, as illustrated in the following code fragment:
              import java.io.File;
              import java.util.Date;
              import jxl.*;
             Workbook workbook = Workbook.getWorkbook(new File("test.xls"));
    On getting access to the worksheet, once can use the following code piece to access  individual sheets. These are zero indexed - the first sheet being 0, the  second sheet being 1, and so on. (You can also use the API to retrieve a sheet by name).
              Sheet sheet = workbook.getSheet(0);
    After getting the sheet, you can retrieve the cell's contents as a string by using the convenience method getContents(). In the example code below, A1 is a text cell, B2 is numerical value and C2 is a date. The contents of these cells may be accessed as follows
    Cell a1 = sheet.getCell(0,0);
    Cell b2 = sheet.getCell(1,1);
    Cell c2 = sheet.getCell(2,1);
    String a1 = a1.getContents();
    String b2 = b2.getContents();
    String c2 = c2.getContents();
    // perform operations on strings
    However in case we need to access the cell's contents as the exact data type ie. as a numerical value or as a date, then the retrieved Cell must be cast to the correct type and the appropriate methods called. The code piece given below illustrates how JExcelApi may be used to retrieve a genuine java double and java.util.Date object from an Excel spreadsheet. For completeness the label is also cast to it's correct type. The code snippet also illustrates how to verify that cell is of the expected type - this can be useful when performing validations on the spreadsheet for presence of correct datatypes in the spreadsheet.
      String a1 = null;
      Double b2 = 0;
      Date c2 = null;
                        Cell a1 = sheet.getCell(0,0);
                        Cell b2 = sheet.getCell(1,1);
                        Cell c2 = sheet.getCell(2,1);
                        if (a1.getType() == CellType.LABEL)
                           LabelCell lc = (LabelCell) a1;
                           stringa1 = lc.getString();
                         if (b2.getType() == CellType.NUMBER)
                           NumberCell nc = (NumberCell) b2;
                           numberb2 = nc.getValue();
                          if (c2.getType() == CellType.DATE)
                            DateCell dc = (DateCell) c2;
                            datec2 = dc.getDate();
                           // operate on dates and doubles
    It is recommended to, use the close()  method (as in the code piece below)   when you are done with processing all the cells.This frees up any allocated memory used when reading spreadsheets and is particularly important when reading large spreadsheets.              
              // Finished - close the workbook and free up memory
              workbook.close();
    The API class files are availble in the 'jxl.jar', which is available for download.
    Regards
    Raghu

  • Which version of the Forms Central subscription will allow me to export data to excel (CSV file)?

    Which version of the Forms Central subscription will allow me to export data to excel (CSV file)?

    Hi Heather 349
    I believe you can do it with both FormsCentral Basic and FormsCentral PLUS
    Also Refer : Tutorial: Exporting Responses to Excel, CSV or PDF

Maybe you are looking for

  • How do i copy playlists from one Mac computer to another?

    I have my iTunes on my iMac and I wish to copy the music AND the playlists to my new MacBook Air - what is hte most effective way to do this and keep them both updated and synchronized?

  • How to user HTMLDB_COLLECTIONS in a PL/SQL function?

    Hi! I am trying to validate/check that an item from an updateable report is not in a collection before I add the item. I wrote a PL/SQL function to do this. It appears that a "normal" PL/SQL function cannot correctly see the HTMLDB_COLLLECTIONS view.

  • Shopping Cart Approval Problem

    Hi. I have a shopping cart which is going through the loop to the approvers. As per the conditinos, it needs to go to only 2 approvers. after the 2nd approver approved it , it going back to the 1st approver again. now 2 approvers approved twice but a

  • Fifth Gen Driver issue

    Hello all, My fifth gen ipod was working fine up untill a couple of weeks ago when my pc started to display it as an unknown usb device. the only piece of info I get from the pc is to reconnect the device and if the problem persists replace the devic

  • Forecast Accuracy Report in BW

    Hi All, Our company is planning to implement Forecast Accuracy reporting within the BW space.  Can anyone please provide reference documents or links on how I can start building the solution for this report? Cheers, Patvin