GUI_DOWNLOAD相关

来源:互联网 发布:惊天动地影评知乎 编辑:程序博客网 时间:2024/06/03 16:49

问题一:导出的EXCEL如何带表头?

解决:

  DATA:BEGIN OF T_FIELDNAMES  OCCURS 0,
        NAME TYPE CHAR20,
       END OF T_FIELDNAMES.

 

      T_FIELDNAMES-NAME = '公司代码'.
      APPEND T_FIELDNAMES.
      T_FIELDNAMES-NAME = '功能范围'.
      APPEND T_FIELDNAMES.

 

      CALL FUNCTION 'GUI_DOWNLOAD'   的时候在TABLE里面加上 FIELDNAMES    = T_FIELDNAMES.

 

问题二:导出的EXCLE里面,如果把文本型的前导零显示出来?

解决:

     参数FILETYPE的类型定义成DBF,同时CODEPAGE = ‘8400’,问题解决。

     但是带来了新的问题:每列的长度不能大于内表字段定义的最大长度,否则会自动换到下一列,我目前解决办法是把内表文本列定义长度大一些,没发现更好的办法。还有一个问题是:抬头最大长度只能是10char,目前我没解决,只能缩小我抬头的长度。

 

存放codepage的表是TCP00


1. FILETYPE: GUI_DOWNLOAD FILETYPE

'ASC' :

ASCII format. The table is transferred as text. Conversion exits are performed. The output format additionally depends on the parameters CODEPAGE, TRUNC_TRAILING_BLANKS, and TRUNC_TRAILING_BLANKS_EOL.

 

'IBM' :

ASCII format with IBM codepage conversion (DOS). This format corresponds to the 'ASC' format when using target codepage 1103. This codepage is frequently used for data exchange via floppy disk.

 

'DAT' :

Column-by-column transfer. With this format, the data is transferred as text as with ASC. However, no conversion exits are performed and the columns are separated by tab characters. This format generates files than can be uploaded again using gui_upload or ws_upload.

 

'DBF' :

Data is downloaded in dBase format. Since in this format the data types of the individual columns are stored as well, you can often avoid import problems, for example, into Microsoft Excel, especially when interpreting numeric values.

 

'WK1' :

Data is downloaded in Lotus 1-2-3 format.

 

'BIN' :

Binary format. Data is transferred binarily. There is no formatting and no codepage conversion. The data is interpreted row by row; it is not formatted by columns. Specify the data length in parameter BIN_FILESIZE. The table should consist of a column of type X, because especially in Unicode systems, the conversion of structured into binary data causes errors.

 

Default

'ASC'


2. APPEND
GUI_DOWNLOAD APPEND

By default, existing local files are overwritten by new versions. By setting APPEND to 'X', the downloaded data is appended to an existing file. If the file does not yet exist, it is created.

Value range

'X'   = Data is appended.

SPACE = Data is overwritten if the file already exists.

Default

SPACE


3. WRITE_FIELD_SEPARATOR
GUI_DOWNLOAD WRITE_FIELD_SEPARATOR

In the downloaded file, the columns are separated by tab characters (cl_abap_char_utilities=>horizontal_tab). You should use this setting if you want to upload the data from the file at a later time, because this is the only way of identifying individual columns.

The parameter makes sense only for the FILETYPE values ASC, DAT and IBM; for DAT it is set implicitly.

Value range

'X'   : Write separator.

SPACE : Do not write separator.

Default

SPACE


4. WRITE_LF
GUI_DOWNLOAD WRITE_LF

If this parameter is set, at the end of each row a row separator is inserted by CL_ABAP_CHAR_UTILITIES=>CR_LF. This parameter makes sense only for FILETYPE 'ASC', 'DAT' and 'IBM'. If this parameter is not set, blanks at the end of a row are not removed.

Value range

'X': Row separator is inserted.

SPACE: Row separator is not inserted.

Default

'X'


5. DAT_MODE
GUI_DOWNLOAD DAT_MODE

If parameter DAT_MODE is set, the file is stored in 'DAT' format. No conversion exits are performed. Number and date fields are stored in a standard format which makes it possible, to later import the file using gui_upload.

Value range

'X': DAT_MODE is switched on.

SPACE: DAT_MODE is not switched on.

Default

SPACE


6. CODEPAGE
GUI_DOWNLOAD CODEPAGE

Use parameter CODEPAGE to specify the desired target codepage. If this parameter is not set, the codepage of the SAP GUI is used as the target codepage.

Value range

4-digit number of the SAP codepage. The function module SCP_CODEPAGE_BY_EXTERNAL_NAME returns the SAP codepage number for an external character set name, for example, "iso-8859-1". The function module NLS_GET_FRONTEND_CP returns the appropriate non-Unicode frontend codepage for a language.

You can determine the desired codepage interactively, if the parameter with_encoding of method file_save_dialog is set by cl_gui_frontend_services.

SPACE: Codepage of the SAP GUI

Default

SPACE


7. REPLACEMENT
GUI_DOWNLOAD REPLACEMENT

Specifies the replacement character to be used when during a character set conversion a character cannot be converted.

Value range

An individual character.

Default

'#'


8. WRITE_BOM
GUI_DOWNLOAD WRITE_BOM

If the data is written in a Unicode codepage, at the beginning of the file the respective byte order mark (BOM) is inserted.

Unicode - Little Endian Codepage 4103, binary values 'FFFE'

Unicode - Big Endian Codepage 4102, binary values 'FEFF'

UTF-8 Codepage 4110, binary values 'EFBBBF'

Note: Microsoft Excel only supports Unicode data if they have been written in the format Unicode - Little Endian.

Value range

'X': Write BOM.

SPACE: Do not write BOM.

Default

SPACE


如何控制输出文件单元格格式?

Download a report to excel with format (border, color cell, etc) 

Try this program...it may help you to change the font ..etc. Code: REPORT ZSIRI NO STANDARD PAGE HEADING. * this report demonstrates how to send some ABAP data to an * EXCEL sheet using OLE automation. INCLUDE OLE2INCL. * handles for OLE objects DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object       H_MAPL TYPE OLE2_OBJECT,         " list of workbooks       H_MAP TYPE OLE2_OBJECT,          " workbook       H_ZL TYPE OLE2_OBJECT,           " cell       H_F TYPE OLE2_OBJECT.            " font TABLES: SPFLI. DATA  H TYPE I. * table of flights DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE. *&---------------------------------------------------------------------* *&   Event START-OF-SELECTION *&---------------------------------------------------------------------* START-OF-SELECTION. * read flights   SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS. * display header   ULINE (61).   WRITE: /     SY-VLINE NO-GAP,           (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,           (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,           (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,           (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,           (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.   ULINE /(61). * display flights   LOOP AT IT_SPFLI.   WRITE: / SY-VLINE NO-GAP,            IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,            IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,            IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,            IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,            IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.   ENDLOOP.   ULINE /(61). * tell user what is going on   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'      EXPORTING *           PERCENTAGE = 0            TEXT       = TEXT-007        EXCEPTIONS             OTHERS     = 1. * start Excel   CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'. *  PERFORM ERR_HDL.   SET PROPERTY OF H_EXCEL  'Visible' = 1. *  CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls' . *  PERFORM ERR_HDL. * tell user what is going on   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'      EXPORTING *           PERCENTAGE = 0            TEXT       = TEXT-008        EXCEPTIONS             OTHERS     = 1. * get list of workbooks, initially empty   CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.   PERFORM ERR_HDL. * add a new workbook   CALL METHOD OF H_MAPL 'Add' = H_MAP.   PERFORM ERR_HDL. * tell user what is going on   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'      EXPORTING *           PERCENTAGE = 0            TEXT       = TEXT-009        EXCEPTIONS             OTHERS     = 1. * output column headings to active Excel sheet   PERFORM FILL_CELL USING 1 1 1 'Flug'(001).   PERFORM FILL_CELL USING 1 2 0 'Nr'(002).   PERFORM FILL_CELL USING 1 3 1 'Von'(003).   PERFORM FILL_CELL USING 1 4 1 'Nach'(004).   PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).   LOOP AT IT_SPFLI. * copy flights to active EXCEL sheet     H = SY-TABIX + 1.     PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.     PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.     PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.     PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.     PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.   ENDLOOP. * changes by Kishore  - start *  CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.   CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.   PERFORM ERR_HDL. * add a new workbook   CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.   PERFORM ERR_HDL. * tell user what is going on   SET PROPERTY OF H_MAP 'NAME' = 'COPY'.   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'      EXPORTING *           PERCENTAGE = 0            TEXT       = TEXT-009        EXCEPTIONS             OTHERS     = 1. * output column headings to active Excel sheet   PERFORM FILL_CELL USING 1 1 1 'Flug'(001).   PERFORM FILL_CELL USING 1 2 0 'Nr'(002).   PERFORM FILL_CELL USING 1 3 1 'Von'(003).   PERFORM FILL_CELL USING 1 4 1 'Nach'(004).   PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).   LOOP AT IT_SPFLI. * copy flights to active EXCEL sheet     H = SY-TABIX + 1.     PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.     PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.     PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.     PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.     PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.   ENDLOOP. * changes by Kishore  - end * disconnect from Excel *      CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.   FREE OBJECT H_EXCEL.   PERFORM ERR_HDL. *---------------------------------------------------------------------* *       FORM FILL_CELL                                                * *---------------------------------------------------------------------* *       sets cell at coordinates i,j to value val boldtype bold       * *---------------------------------------------------------------------* FORM FILL_CELL USING I J BOLD VAL.   CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.   PERFORM ERR_HDL.   SET PROPERTY OF H_ZL 'Value' = VAL .   PERFORM ERR_HDL.   GET PROPERTY OF H_ZL 'Font' = H_F.   PERFORM ERR_HDL.   SET PROPERTY OF H_F 'Bold' = BOLD .   PERFORM ERR_HDL. ENDFORM. *&---------------------------------------------------------------------* *&      Form  ERR_HDL *&---------------------------------------------------------------------* *       outputs OLE error if any                                       * *----------------------------------------------------------------------* *  -->  p1        text *  <--  p2        text *----------------------------------------------------------------------* FORM ERR_HDL. IF SY-SUBRC <> 0.   WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.   STOP. ENDIF. ENDFORM.                    " ERR_HDL Please note that this example maybe slow at filling the excel table (perhaps four fields per second on a 900 MHz machine - almost 30 seconds for a short example). To get the data on properties and methods - there is a bit of smoke and mirrors going on here; they are EXCEL properties and methods, not sap ones - so you need to look at excel help to determine how a particular function is structured. then build the block in sap, as shown in the example. If you only want to transfer the data to Excel like when you transfer the data from ALV to Excel simply use the Function Modules: XXL_SIMPLE_API If you want more modifications when you transfer it to Excel use: XXL_FULL_API 
Do you have a ABAP Question?

Best regards, 
SAP Basis, ABAP Programming and Other IMG Stuff 
http://www.erpgreat.com


0 0