没外网,对于一个做IT的来说,真是相当于脱了水的鱼啊
代码语言:javascript复制type-pools ole2 .
data: count type i,
count_real type i,
application type ole2_object,
workbook type ole2_object,
excel type ole2_object,
sheet type ole2_object,
cells type ole2_object.
constants: row_max type i value 256.
data index type i.
data:
h_cell type ole2_object, " cell
h_f type ole2_object, " font
h_int type ole2_object,
h_width type ole2_object,
h_columns type ole2_object,
h_rows type ole2_object,
h_font type ole2_object,
h_entirecol type ole2_object.
.
create object excel 'EXCEL.APPLICATION'.
if sy-subrc ne 0.
write: / 'No EXCEL creation possible'.
stop.
endif.
set property of excel 'DisplayAlerts' = 0.
call method of excel 'WORKBOOKS' = workbook .
set property of excel 'VISIBLE' = 1.
set property of excel 'SheetsInNewWorkbook' = 1.
call method of workbook 'ADD'.
call method of excel 'WORKSHEETS' = sheet
exporting
#1 = 1.
set property of sheet 'NAME' = 'Color Palette'.
call method of sheet 'ACTIVATE'.
data: col type i value 1,
row type i value 2,
col1 type i value 2,
col_real type i value 1.
row = 1.
col = 2.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'No.'.
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Background'.
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Foreground with white background'.
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Foreground with black background'.
call method of excel 'Rows' = h_rows
exporting
#1 = '2:2'.
set property of h_rows 'WrapText' = 1.
col = 8.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'No.'.
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Background'.
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Foreground with white background'.
set property of h_cell 'Bold' = 1.
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Foreground with black background'.
call method of excel 'Rows' = h_rows
exporting
#1 = '1:1'.
set property of h_rows 'WrapText' = 1.
get property of h_rows 'Font' = h_font.
set property of h_font 'Bold' = 1.
count = 1.
count_real = count.
row = 2.
col = 2.
do 56 times.
perform write_num_and_color.
enddo.
call method of excel 'Columns' = h_columns
exporting
#1 = 'B:K'.
get property of h_columns 'EntireColumn' = h_entirecol.
set property of h_entirecol 'Autofit' = 1.
*&---------------------------------------------------------------------*
*& Form write_num_and_color
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form write_num_and_color.
" write the color number
index = row_max * ( row - 1 ) col.
call method of sheet 'Cells' = cells
exporting
#1 = index.
set property of cells 'Value' = count_real.
" write the color as the background
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
get property of h_cell 'Interior' = h_int.
set property of h_int 'ColorIndex' = count_real.
" write the color as the foreground with a white background
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
set property of h_cell 'Value' = 'Sample Text'.
get property of h_cell 'Font' = h_f.
set property of h_f 'ColorIndex' = count_real.
" write the color as the foreground with a black background
col = col 1.
call method of excel 'Cells' = h_cell
exporting
#1 = row
#2 = col.
get property of h_cell 'Interior' = h_int.
set property of h_int 'ColorIndex' = 1.
set property of h_cell 'Value' = 'Sample Text'.
get property of h_cell 'Font' = h_f.
set property of h_f 'ColorIndex' = count_real.
row = row 1.
col = col - 3.
count = count 1.
if count = 29.
count = 1.
row = 2.
col = col 6.
endif.
count_real = count_real 1.
endform. "write_num_and_color