Posted: Mon Feb 04, 2008 3:36 pm Post subject: Автоподбор высоты в Excel
Создаю таблицу в Excel.
Надо некоторые строки сделать с оптимальной высотой, т.е. высотой длинейшего текста (текст расположен вертикально).
Написал следующее:
Code:
FORM set_height USING range_top_1 TYPE i
range_left_1 TYPE i
range_top_2 TYPE i
range_left_2 TYPE i.
DATA:
o_cells TYPE ole2_object,
o_sheet TYPE ole2_object,
o_start TYPE ole2_object,
o_end TYPE ole2_object,
o_row TYPE ole2_object,
o_selection TYPE ole2_object,
o_range TYPE ole2_object.
CALL METHOD OF h_excel 'Cells' = o_cells.
CALL METHOD OF o_cells 'Select'.
CALL METHOD OF h_excel 'ActiveSheet' = o_sheet.
AutoFitHeight не срабатывает.
Если делать по аналогии с этим кодом оптимальную ширину столбца, используя
CALL METHOD OF o_column 'Autofit'.
то все нормально...
Age: 175 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Mon Feb 04, 2008 6:25 pm Post subject:
Может о разном говорим.
Запускаю код.
Когда останавливается на BREAK-POINT, форматирую ячейки, как на первой картинке.
Продолжаю выполнение и получаю состояние, как на второй картинке.
Code:
REPORT Z_VGA_EXCEL 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.
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.
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 1 '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).
DATA: range_top_1 TYPE i VALUE 1,
range_left_1 TYPE i VALUE 1,
range_top_2 TYPE i VALUE 1,
range_left_2 TYPE i VALUE 1.
DATA:
o_cells TYPE ole2_object,
o_sheet TYPE ole2_object,
o_start TYPE ole2_object,
o_end TYPE ole2_object,
o_row TYPE ole2_object,
o_selection TYPE ole2_object,
o_range TYPE ole2_object.
CALL METHOD OF h_excel 'Cells' = o_cells.
CALL METHOD OF o_cells 'Select'.
CALL METHOD OF h_excel 'ActiveSheet' = o_sheet.
* disconnect from Excel
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
*&---------------------------------------------------------------------*
Ну ладно, буду пока без автовысоты...
А вот еще вопрос. Я открываю уже готовый экселевский файл с шапкой и хочу вставить в него таблицу после шапки. С этим проблемы нет.
Потом я хочу пересохранитьэтот файл но под другим именем. И тут что-то у меня не выходит...
Code:
*------------------------------ start Excel
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
SET PROPERTY OF h_excel 'Visible' = 1.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Open new folder ...'
EXCEPTIONS
OTHERS = 1.
*------------------------------ get list of workbooks, initially empty
CALL METHOD OF h_excel 'Workbooks' = h_mapl.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.