`

DOI create excel

    博客分类:
  • ABAP
阅读更多
REPORT  ztest_create_excel NO STANDARD PAGE HEADING.
 
DATA:
oref_container   TYPE REF TO cl_gui_custom_container,
iref_control     TYPE REF TO i_oi_container_control,
iref_document    TYPE REF TO i_oi_document_proxy,
iref_spreadsheet TYPE REF TO i_oi_spreadsheet,
iref_error       TYPE REF TO i_oi_error.
 
DATA: BEGIN OF it_spfli OCCURS 0.
       INCLUDE STRUCTURE spfli.
DATA: END OF it_spfli.
 
DATA:
v_document_url TYPE c LENGTH 256,
i_sheets TYPE soi_sheets_table,
wa_sheets TYPE soi_sheets,
i_data        TYPE soi_generic_table,
wa_data       TYPE soi_generic_item,
i_ranges      TYPE soi_range_list.
 
*PARAMETERS:
*p_file  TYPE  localfile OBLIGATORY,
*p_rows TYPE i DEFAULT 100 OBLIGATORY,   "Rows (Maximum 65536)
*p_cols TYPE i DEFAULT 10 OBLIGATORY.    "Columns (Maximum 256)
 
INITIALIZATION.
 
 CALL METHOD c_oi_container_control_creator=>get_container_control
   IMPORTING
     control = iref_control
     error   = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'E'.
 ENDIF.
 
 
 CREATE OBJECT oref_container
   EXPORTING
     container_name              = 'CONT'
   EXCEPTIONS
     cntl_error                  = 1
     cntl_system_error           = 2
     create_error                = 3
     lifetime_error              = 4
     lifetime_dynpro_dynpro_link = 5
     OTHERS                      = 6.
 IF sy-subrc <> 0.
   MESSAGE e001(00) WITH 'Error while creating container'.
 ENDIF.
 
 CALL METHOD iref_control->init_control
   EXPORTING
     inplace_enabled      = 'X'
     r3_application_name  = 'EXCEL CONTAINER'
     parent               = oref_container
   IMPORTING
     error                = iref_error
   EXCEPTIONS
*      javabeannotsupported = 1
     OTHERS               = 2.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'E'.
 ENDIF.
 
 CALL METHOD iref_control->get_document_proxy
   EXPORTING
     document_type  = soi_doctype_excel_sheet
   IMPORTING
     document_proxy = iref_document
     error          = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'E'.
 ENDIF.
 
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*
** To provide F4 help for the file
*  PERFORM sub_file_f4.
 
START-OF-SELECTION.
 
 SELECT * FROM spfli INTO TABLE it_spfli.
*  CONCATENATE 'FILE://' p_file INTO v_document_url.
 
*  CALL METHOD iref_document->open_document
*    EXPORTING
*      document_title = 'Excel'
*      document_url   = v_document_url
*      open_inplace   = 'X'
*    IMPORTING
*      error          = iref_error.
*  IF iref_error->has_failed = 'X'.
*    CALL METHOD iref_error->raise_message
*      EXPORTING
*        type = 'I'.
*    LEAVE LIST-PROCESSING.
*  ENDIF.
 
 CALL METHOD iref_document->create_document
   EXPORTING
     document_title = 'Excel'
     open_inplace   = 'X'
   IMPORTING
     error          = iref_error.
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 
 CALL METHOD iref_document->get_spreadsheet_interface
   EXPORTING
     no_flush        = ' '
   IMPORTING
     error           = iref_error
     sheet_interface = iref_spreadsheet.
 
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
   LEAVE LIST-PROCESSING.
 ENDIF.
 
 CALL METHOD iref_spreadsheet->insert_range
   EXPORTING
     name    = 'TEST'
     rows    = 20
     columns = 16
   IMPORTING
     error   = iref_error.
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 
 CALL METHOD iref_spreadsheet->insert_one_table
   EXPORTING
     ddic_name  = 'SPFLI'
     data_table = it_spfli[]
     rangename  = 'TEST'
     wholetable = 'X'
   IMPORTING
     error      = iref_error.
 
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 
 
 CALL METHOD iref_document->save_as
   EXPORTING
     file_name = 'C:\TEXT.XLS'
   IMPORTING
     error     = iref_error.
 
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 

 CALL METHOD iref_document->close_document
   IMPORTING
     error = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
   LEAVE LIST-PROCESSING.
 ENDIF.
 
 CALL METHOD iref_document->release_document
   IMPORTING
     error = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
   LEAVE LIST-PROCESSING.
 ENDIF.
 
分享到:
评论

相关推荐

    Abap中使用DOI与OLE工具

    在SAP ABAP环境中,DOI(Data Output Interface)和OLE(Object Linking and Embedding)是两种常用的工具,用于与外部系统交互,特别是在处理数据导出到如Microsoft Excel这样的应用程序时。下面将详细介绍这两个...

    ABAP-操作Excel导出数据

    在ABAP中,我们可以利用DO (Document Object) Interface(DOI),这是一个与OLE相关的接口,来实现对Office应用程序(如Excel)的控制。 首先,我们需要创建一个ABAP报告或函数模块,用于执行数据导出。在这个过程...

    ABAP DOI详解

    通过DOI,开发者能够更方便地创建、编辑和管理Excel或Word文档,而无需直接使用VBA。 在DOI开发中,涉及的关键对象包括: 1. **Container**:这是一个用来存放Excel电子表格的容器,通常在对话屏幕中定义。在ABAP...

    delphi7如何读取excel文件

    // 获取 Excel 的数据第 i 行,第 j 列单元格内的数据 Strs.Add(Sheet.Cells[i, j].Value); end; List.Add(Strs.CommaText); end; finally // 关闭工作区 ExcelApp.WorkBooks.Close; List.EndUpdate; end;...

    Delphi操作Excel2

    function CreateExcel: Variant; var v: Variant; sheet: Variant; begin v := CreateOleObject('Excel.Application'); // 创建 Excel 对象 v.Visible := True; // 显示 Excel 窗口 v.Workbooks.Add(-4167); //...

    Delphi控制Excel自动生成报表

    function createExcel: variant; var v: variant; sheet: variant; begin v := CreateOleObject('Excel.Application'); // 创建 Excel 对象 v.Visible := True; // 显示 Excel 窗口 v.Workbooks.Add(-4167); //...

    ci框架利用phpexcel导入excel表格并将其插入数据库

    在本文中,我们将深入探讨如何在CodeIgniter(CI)框架中使用PHPExcel库来导入Excel表格数据,并将其存储到数据库中。这是一个常见的任务,特别是在处理大量用户输入数据或者需要从Excel文件同步数据到Web应用时。让...

    Excel 2003 Programming with VBA

    I was talking to an Excel guru the other day. We were reflecting on what we have enjoyed most about our consulting careers. We both agreed that the most satisfying aspect of our career is the ...

    cxGrid向Excel导出单元颜色

    for i := 0 to cxGrid1.MainView.DataController.RecordCount - 1 do for j := 0 to cxGrid1.MainView.DataController.Fields.Count - 1 do begin CellColor := cxGrid1.MainView.GetCellStyle(i, j).BackColor;...

    ABAP与EXCEL接口操作

    FOR i FROM 1 TO 3 DO. lo_excel_writer-&gt;set_cell_value( iv_column = 'A' iv_row = i + 4 iv_text = some_data[i] ). ENDFOR. ``` 3. 在原来的模板上删除若干行: 删除行的需求可以通过`DELETE_ROWS`...

    Programming Excel With Vba And .net.chm

    Part I: Learning VBA Chapter 1. Becoming an Excel Programmer Section 1.1. Why Program? Section 1.2. Record and Read Code Section 1.3. Change Recorded Code Section 1.4. Fix Misteakes ...

    DELPHI_EXCEL导入导出.txt

    for i := 1 to 10000 do begin if Trim(ExcelWorksheet1.Cells.Item[i + 1, 1]) &lt;&gt; '' then begin s0 := ExcelWorksheet1.Cells.Item[i + 1, 1]; // 读取第一列数据 end; end; ``` - **连接到打开的工作簿和...

    Delphi控制Excel

    function createExcel: Variant; var v: Variant; sheet: Variant; begin v := CreateOleObject('Excel.Application'); // 创建 Excel 对象实例 v.Visible := True; // 设置 Excel 应用程序为可见 v.Workbooks....

    Delphi DBGrid导出Excel文件最快速的代码

    在Delphi编程环境中,开发人员经常需要将...在处理大量数据时,优化内存管理和减少磁盘I/O操作是非常重要的,这也是本方案强调“最快”的原因。通过理解并应用上述技术,你可以在Delphi项目中实现高效的数据导出功能。

    利用存储过程将Excel中数据导入到数据库表中

    WHILE i (dataText) DO INSERT INTO your_table (column1, column2) VALUES (SUBSTRING_INDEX(dataText, ',', 1), SUBSTRING_INDEX(dataText, ',', -1)); SET dataText = SUBSTRING(dataText, LENGTH(SUBSTRING_...

    Marketing Analytics: Data-Driven Techniques with Microsoft® Excel®

    I could not fi nd an Excel-based book that provided a how-to-do-it approach suitable for an MBA elective or an advanced undergraduate course. With no suitable book in hand, I wrote up course notes ...

    支持多个DBGridEH导出Excel

    for i := 0 to 9 do //初始化数组 begin DbOut.DBGridEhRecAry[i].TempDBGridEh := nil; DbOut.DBGridEhRecAry[i].TitleName := ''; DbOut.DBGridEhRecAry[i].SheetTabName := ''; end; //有多少个DBGridEh...

    delphi 写信息到excel里

    for j := 0 to DataList[i].Count - 1 do begin Worksheet.Cells[i + 1, j + 1] := DataList[i][j]; end; end; ``` 这段代码会逐行逐列地将`DataList`中的数据写入Excel工作表。 6. 保存并关闭工作簿: ```...

    delphi从Access输出到Excel

    for I := 0 to Recordset.RecordCount - 1 do begin Worksheet.Cells[I + 1, 1].Value := Recordset.Fields[0].Value; // 以此类推,写入其他字段 Recordset.MoveNext; end; ``` 这将数据从记录集的每一行...

Global site tag (gtag.js) - Google Analytics