Creating Excel Using OLE through ABAP
Hi Experts,
Can anyone help me in running an abap program to give an Excel file using OLE..
Regards,
Seshadri
Hi Seshadri,
Here is ur expected coding...
REPORT ZCREATEEXCEL.
TYPE-POOLS OLE2.
DATA: EXCEL TYPE OLE2_OBJECT,
WORKBOOKS TYPE OLE2_OBJECT,
WORKBOOK TYPE OLE2_OBJECT.
DATA: FILENAME LIKE RLGRAP-FILENAME.
START THE EXCEL APPLICATION
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
PUT EXCEL IN FRONT
SET PROPERTY OF EXCEL 'VISIBLE' = 1.
PERFORM ERR_HDL.
INFORM USER OF THE CURRENT STATUS
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-I08
EXCEPTIONS
OTHERS = 1.
CREATE AN EXCEL WORKBOOK OBJECT
CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOKS.
PERFORM ERR_HDL.
CALL METHOD OF WORKBOOKS 'ADD' = WORKBOOK.
PERFORM ERR_HDL.
EXCEL FILENAME
CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'
SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = FILENAME.
FORM ERR_HDL.
IF SY-SUBRC <> 0.
WRITE: / 'OLE ERROR: RETURN CODE ='(I10), SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
hope it helps..
Similar Messages
-
Populating graph in excel using ole
Hi All,
I am able to populate the graph from abap into excel using OLE.
But I am not able to take x-axis and y-axis according to my requirement, its taking by its own as default. please see the below code:
<b>CALL METHOD OF GS_EXCEL 'Cells' = GS_CELL1
EXPORTING
#1 = GV_LINE_CNTR
#2 = 1.
CALL METHOD OF GS_EXCEL 'Cells' = GS_CELL2
EXPORTING
#1 = GV_LINNO1
#2 = GV_COLNO.
CALL METHOD OF GS_EXCEL 'Range' = GS_CELLS
EXPORTING
#1 = GS_CELL1
#2 = GS_CELL2.
CALL METHOD OF GS_CELLS 'Select' .
GET PROPERTY OF GS_APPLICATION 'Charts' = GS_CHARTS .
CALL METHOD OF GS_CHARTS 'Add' = GS_CHART .
CALL METHOD OF GS_CHART 'Activate' .
SET PROPERTY OF GS_CHART 'ChartType' = '93' .</b>Now I want to give my own range. But i am not able to.
I am also not able to give labels of x-axis and y-axis.
Please help, its very urgent............Hello,
try this code. It creates macro as a file, and than uses that macro to show the chart
Regards,
Naimesh
REPORT ZTEST_NP .
INCLUDE OLE2INCL. " OLE objects include
*export data variables
DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
WORKBOOKS TYPE OLE2_OBJECT, " list of workbooks
THIS_WORKBOOK TYPE OLE2_OBJECT, " workbook
CELL TYPE OLE2_OBJECT, " cell
BOOK_FONT TYPE OLE2_OBJECT. " font
*chart creation DATA: variables
DATA: MODULE TYPE OLE2_OBJECT, "macro
NEWMODULE TYPE OLE2_OBJECT. "macrotab with VB source code
INternal tableTABLES: no_table.
DATA H TYPE I.
table that contains Visual Basic source code
DATA: BEGIN OF MACROFILE OCCURS 0,
LINE(80) ,
END OF MACROFILE.
*Internal table with Months and related Profits
DATA: BEGIN OF NO_TABLE OCCURS 10, "Internal table with no's
MONTH(8) TYPE C,
PROFIT(8) TYPE C,
END OF NO_TABLE.
*Months added to table as well as Profits
NO_TABLE-MONTH = 'June'.
NO_TABLE-PROFIT = '1000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'July'.
NO_TABLE-PROFIT = '4000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'August'.
NO_TABLE-PROFIT = '3000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'September'.
NO_TABLE-PROFIT = '7000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'October'.
NO_TABLE-PROFIT = '7000'. APPEND NO_TABLE. "Update table
NO_TABLE-MONTH = 'November'.
NO_TABLE-PROFIT = '6000'. APPEND NO_TABLE. "Update table
CALL METHOD OF THIS_WORKBOOK 'InsertFile'
EXPORTING #1 = 'C:\VBsource.tmp'.
*********Fill makro table with VB source code************************
the macro's name is draw_graph
MACROFILE-LINE = 'sub draw_graph()'. APPEND MACROFILE.
MACROFILE-LINE = 'Range("a1:a1").Font.Bold = True'.APPEND macrofile.
MACROFILE-LINE =
'Range("a1:a1").Value = "Net Profits for last few months.
"'. APPEND macrofile. "Bold heading at top of sheet.
MACROFILE-LINE = 'Range("A2:B7").Select'. APPEND macrofile.
MACROFILE-LINE = 'charts.add'. APPEND MACROFILE.
MACROFILE-LINE = 'activechart.charttype = xllinemarkersStacked
'. APPEND macrofile.
MACROFILE-LINE =
'Activechart.setsourcedata source:=sheets("Sheet1").range("A2:B7") ,
PLOTBY:= XLROWS'. APPEND macrofile.
MACROFILE-LINE = 'activechart.location where:=xllocationasobject, name:=
"sheet1"'. APPEND macrofile.
MACROFILE-LINE = 'With ActiveChart'. APPEND MACROFILE.
MACROFILE-LINE = '.hasLegend = false '. APPEND MACROFILE.
MACROFILE-LINE = ' .Axes(xlValue, xlPrimary).HasTitle = True'.
APPEND MACROFILE.
MACROFILE-LINE = '.axes(xlvalue, xlprimary).axistitle.characters.text =
"Net Profit ($)"'.
APPEND MACROFILE.
MACROFILE-LINE = 'End With'. APPEND MACROFILE.
MACROFILE-LINE = 'msgbox ("Chart completed!")'. APPEND macrofile.
MACROFILE-LINE = 'end sub '. APPEND MACROFILE.
*******************vb source code end********************************
***********create file with visual basic source code *******************
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = 'c:\VBsource.tmp' "directory with temporary file
FILETYPE = 'ASC'
TABLES
DATA_TAB = MACROFILE
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
**********create file with visual basic source code end**************
**write info to screen (ABAP)
LOOP AT NO_TABLE.
WRITE: / SY-VLINE NO-GAP,
NO_TABLE-MONTH COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
NO_TABLE-PROFIT COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
ENDLOOP.
ULINE (61).
**********************START THE EXCEL APPLICATION*********************
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'. "type of application
PERFORM CHECK_ERRORS.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
PERFORM CHECK_ERRORS.
CALL METHOD OF H_EXCEL 'Workbooks' = WORKBOOKS.
PERFORM CHECK_ERRORS.
create a new workbook
CALL METHOD OF WORKBOOKS 'Add' = THIS_WORKBOOK.
PERFORM CHECK_ERRORS.
***********fill the Excel table with data*****************************
PERFORM FILL_EXC_TAB USING 1 1 1 'Profits:'(001). "initial heading
LOOP AT NO_TABLE.
H = SY-TABIX + 1.
PERFORM FILL_EXC_TAB USING H 1 0 NO_TABLE-MONTH.
ENDLOOP.
LOOP AT NO_TABLE.
H = SY-TABIX + 1.
PERFORM FILL_EXC_TAB USING H 2 0 NO_TABLE-PROFIT.
ENDLOOP.
***********fill the Excel table with data end*************************
************DRAW the CHART using the values exported *******************
CALL METHOD OF H_EXCEL 'Modules' = MODULE.
PERFORM CHECK_ERRORS.
CALL METHOD OF MODULE 'Add' = NEWMODULE. " the macro
PERFORM CHECK_ERRORS.
CALL METHOD OF NEWMODULE 'Activate'.
PERFORM CHECK_ERRORS.
get source code from temporary file
CALL METHOD OF NEWMODULE 'InsertFile' EXPORTING #1 = 'C:\VBsource.tmp'.
PERFORM CHECK_ERRORS.
executing VBA program code -> macro name = "draw_graph"
CALL METHOD OF H_EXCEL 'Run' EXPORTING #1 = 'draw_graph'.
PERFORM CHECK_ERRORS.
FREE OBJECT H_EXCEL. "free up memory
PERFORM CHECK_ERRORS.
FORM FILL_EXC_TAB USING I J BOLD VAL.
CALL METHOD OF H_EXCEL 'Cells' = CELL EXPORTING #1 = I #2 = J.
PERFORM CHECK_ERRORS.
SET PROPERTY OF CELL 'Value' = VAL .
PERFORM CHECK_ERRORS.
GET PROPERTY OF CELL 'Font' = BOOK_FONT.
PERFORM CHECK_ERRORS.
SET PROPERTY OF BOOK_FONT 'Bold' = BOLD .
PERFORM CHECK_ERRORS.
ENDFORM.
error handling subroutine
FORM CHECK_ERRORS.
IF SY-SUBRC NE 0.
WRITE: / 'OLE error:'(010), SY-SUBRC.
STOP.
ENDIF.
ENDFORM. -
Conditional formatting using OLE in ABAP
Hello all,
Is it possible to apply conditional format using OLE in ABAP?? for example if the cell value is greater than 10, then make it red...
Thanks in advance..
Regards,
MayaYes,Since we can do conditional format based on other columns for a column:
Assume you pulled A,B and wants to apply RED color on A
Pull columns A,A,B (A twice) for 2nd A expression something like
case when A>B then 1 else 0 end
On A(1st A) Conditional format
Add Condition->Choose 2nd A
add value 1 and set color RED.
Appreciate if you mark as correct/helpful -
Create Attachment in workflow through ABAP Class in ECC 5.0
Hi,
Wr are using SAP ECC 5.0 and i am trying to create attachment through ABAP class.
Here in ECC 5.0, macro INCLUDE cntn01_swc is not available.
I am getting an error in declaration of SOFM object, because again SWC0_OBJECT is not available.
I've tried creating the parameter as type SOFM and of type table of SOFM but it also not working.
Can anybody help me how i can create SOFM instance in ABAP class in ECC 5.0?
Regards,
SmitHi
I am not very much sure about ECC 5.0 environment. Firstly are you looking to create a SOFM object inside any class or program or Function module , If yes then you need to include a include INCLUDE CNTN01_SWC (No arrow brackets) if this include is not available then use INCLUDE<CNTN01> then declare a variable of type SWC0_OBJECT if you are using first include or declare of type SWC_OBJECT.
Once you include any of the includes then by making use of SWC macros you can create a object
SWC0_CREATE_OBJECT <VARAIBLE> <BOR NAME> <BORKEY> for first include.
SWC_CREATE_OBJECT <VARAIBLE> <BOR NAME> <BORKEY> for second include.
Regards
Pavan -
Hi!
i want to color(yellow) the last line of an excel.
here is a part of the code :
DESCRIBE TABLE excel_2 LINES w_lines.
CREATE OBJECT application 'excel.application'.
SET PROPERTY OF application 'visible' = 1.
CALL METHOD OF application 'Workbooks' = workbook.
CALL METHOD OF workbook 'Open'
EXPORTING
#1 = pa_file.
CALL METHOD OF application 'Worksheets' = sheet
EXPORTING
#1 = 1.
SET PROPERTY OF sheet 'Name' = 'Employee Performance'.
CALL METHOD OF sheet 'Activate'.
DATA: w_test TYPE string.
DATA: w_test_lines TYPE string.
w_test_lines = w_lines.
CONCATENATE 'A' w_test_lines INTO w_test.
CONCATENATE w_test ':Z' w_test_lines INTO w_test.
CONDENSE w_test NO-GAPS.
*CALL METHOD OF application 'RANGE' = gs_range
* EXPORTING
* #1 = 'w_test'.
* SET PROPERTY OF gs_range 'HORIZONTALALIGNMENT' = 1.
* CALL METHOD OF gs_range 'FONT' = gs_font.
* SET PROPERTY OF gs_font 'BOLD' = 1.
CALL METHOD OF application 'RANGE' = gs_range
EXPORTING
#1 = 'A1:Z1'.
SET PROPERTY OF gs_range 'HORIZONTALALIGNMENT' = 1.
CALL METHOD OF gs_range 'FONT' = gs_font.
SET PROPERTY OF gs_font 'BOLD' = 1.
CALL METHOD OF application 'Columns' = h_columns
EXPORTING
#1 = 'A:Z'.
GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
SET PROPERTY OF h_entirecol 'Autofit' = 1.
CALL METHOD OF sheet 'SAVE' "'Save'
EXPORTING
#1 = pa_file
#2 = pa_file."filename
"fileFormatCheck out this code
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 -
File is corrupted error while creating excel using xml
Hi have created one excel file using XML code and sent it to mail as attachement. But when i open it, it displays error message - file is corrupted and cannot be opened.
below is my code - please review and tell what is wrong in it ASAP :
* Creating a ixml Factory
l_ixml = cl_ixml=>create( ).
* Creating the DOM Object Model
l_document = l_ixml->create_document( ).
* Create Root Node 'Workbook'
l_element_root = l_document->create_simple_element( name = 'Workbook' parent = l_document ).
l_element_root->set_attribute( name = 'xmlns' value = 'urn:schemas-microsoft-com:office:spreadsheet' ).
ns_attribute = l_document->create_namespace_decl( name = 'ss' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:spreadsheet' ).
l_element_root->set_attribute_node( ns_attribute ).
ns_attribute = l_document->create_namespace_decl( name = 'x' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:excel' ).
l_element_root->set_attribute_node( ns_attribute ).
* Create node for document properties.
r_element_properties = l_document->create_simple_element( name = 'TEST_REPORT' parent = l_element_root ).
l_value = sy-uname.
l_document->create_simple_element( name = 'Author' value = l_value parent = r_element_properties ).
* Styles
r_styles = l_document->create_simple_element( name = 'Styles' parent = l_element_root ).
* Style for Header
r_style = l_document->create_simple_element( name = 'Style' parent = r_styles ).
r_style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header' ).
r_format = l_document->create_simple_element( name = 'Font' parent = r_style ).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Interior' parent = r_style ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#92D050' ).
r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ).
r_format = l_document->create_simple_element( name = 'Alignment' parent = r_style ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).
r_border = l_document->create_simple_element( name = 'Borders' parent = r_style ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
* Style for Data
r_style1 = l_document->create_simple_element( name = 'Style' parent = r_styles ).
r_style1->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Data' ).
r_border = l_document->create_simple_element( name = 'Borders' parent = r_style1 ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
* Worksheet
r_worksheet = l_document->create_simple_element( name = 'Worksheet' parent = l_element_root ).
r_worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'Sheet1' ).
* r_worksheet->set_attribute_ns( name = 'Protected' prefix = 'ss' value = '1' ). " WORKING
* Table
r_table = l_document->create_simple_element( name = 'Table' parent = r_worksheet ).
r_table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ).
r_table->set_attribute_ns( name = 'FullRows' prefix = 'x' value = '1' ).
* Column Formatting
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '40' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '140' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ).
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ).
r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ).
* Blank Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
* Column Headers Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).
* RFQ No.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'RFQ No.' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* RFQ Line Item No
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'RFQ Line Item No.' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Material
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Material' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Quantity
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Quantity' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Order UNIT
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Order Unit' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Delivery Date
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Delivery Date' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* RFQ Creation Date
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'RFQ Creation Date' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* RFQ Deadline Date
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'RFQ Deadline Date' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Price
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'Net Price' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
** Login
* r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
* r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
* CONCATENATE 'Login - ' lv_date+6(2) '/' lv_date+4(2) '/' lv_date+0(4) INTO l_value.
* r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ).
* r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Blank Row after Column Headers
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
* Data Table
LOOP AT it_final1 INTO wa_final1.
CLEAR l_value.
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
* RFQ No.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
CLEAR l_value.
l_value = wa_final1-ebeln .
* CONDENSE l_value NO-GAPS.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format
* Line Item No
CLEAR l_value.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_final1-ebelp.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ). " Cell format
* Material
CLEAR l_value.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_final1-txz01.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format
* RFQ QTY
CLEAR l_value.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_final1-ktmng.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ). " Cell format
* UNIT
CLEAR l_value.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = wa_final1-meins.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cellHow to make a particular column non editable?
Make your style protected and pass that style name to your required column while passing data.
for example:
Find below the code for protection of a style.
Last two lines are very important.
* Style for Headert
r_style = l_document->create_simple_element( name = 'Style' parent = r_styles ).
r_style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Headert' ).
r_format = l_document->create_simple_element( name = 'Font' parent = r_style ).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Interior' parent = r_style ).
r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#B2FF64' ).
r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ).
r_format = l_document->create_simple_element( name = 'Alignment' parent = r_style ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).
r_border = l_document->create_simple_element( name = 'Borders' parent = r_style ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Border' parent = r_border ).
r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ).
r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ).
r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ).
r_format = l_document->create_simple_element( name = 'Protection' parent = r_style ).
r_format->set_attribute_ns( name = 'Protected' prefix = 'ss' value = '1' ). -
How to output a logo stored as standard text to excel using OLE
Hi Experts,
I have a requirement to write a program which creates an excel spreadsheet to download data from SAP. The client would like the spreadsheet formatted with merged cells, background colours, different size fonts and in the top left corner of the spreadsheet to show their logo.
They have similar functionality in another report, however, this requires a template (containing all of the formatting) to be stored on the user's PC. They do not want to have to do this with the new download.
After checking the many postings on this forum I have worked out how to do most of the requirements, but as yet have still not been able to work out how to populate their logo to the spreadsheet. They already have their logo stored as standard text (SO10), so would prefer to use this if possible.
Any advise and/or sample code would ge greatly appreciated.
Thanks
SandraHi Surendra,
We have the same requirement. We want to do some format changes to "Generic FSG Drill Template". I am able to do few changes. But when we run the report, we are able to see PDF, html output. But 'Exce' report comes with blank. Can you help on this. How were you able to see logo in excel file.
Can you send the suggestions if any to my mail ([email protected])
Thanks in advance.
Thanks,
Techie.
Edited by: user1138068 on May 30, 2011 7:04 AM -
Creating Excel using C# in SSIS Script task.
Hi Guys,
I need to dynamically create an excel (with rows and columns) from a script task in a foreach container and just send an email to a group..
Can anyone guide me on this..
Thanks in advance...Hi,
There are a number of things wrong with this request.
1. This is a scripting forum, not a C# development forum.
2. This is not an SSIS forum.
3. You show nothing about what you have already tried, what has worked, and what hasn't worked.
Your question is far too broad and vague, and you're not even asking in the right place.
You need to break down your requirements into small pieces and ask very specific questions in the correct forums. If you need for someone to design a solution for you, it's better to hire a paid consultant.
Bill -
Need screen-shot for create mm01 using BAPI(Through lsmw or ecording)
hi,
could u give screen-shot of the lsmw using bapi.for material master data create using t.code (mm01')
i will be waiting for eply.
regards
eswar.Check this link dude.....
http://www.****************/Tutorials/LSMW/LSMWMainPage.htm
It has all different types of LSMW with the screen shots.... keep doin
Regards,
Pavan -
How to crete Button through ABAP programming
Hello Friends,
I am creating 2 selection screens through ABAP code and using them in my Tabstrip control also created through ABAP programming.
Can I also create button on the selection screen through abap programming. If yes then how, and how to assign funtion code and capture the Function Code???
Moderator Message: Read the below advice.
Edited by: kishan P on Dec 30, 2010 7:44 PMHave a look at F1 help on SELECTION-SCREEN. There should be an example as well.
-
Reports Generation in Microsoft Excel using Forms Server
How can I generate reports in Microsoft Excel from an web-enabled forms application, as using Dynamic Data Exchange invokes Excel on the Application Server? My work-around was to generate the file on the application server, save it ,exit the Excel application and then display the excel document using Web.Show_Document. Though this method is successful, the processing time is very high.
nullUse text_io package of developer to write records to excel using OLE
Thanks
null -
Row Grouping in Excel through ABAP OLE
Hi Experts,
I am downloading some ALV report output using OLE with different formatting. The downloaded file has to show data
in the grouping format.
For example;
Interanl table contains fields : Customer Number and sales Order, Amount,
Customer Number sales Order Amount
1000 120000001 3000.30
1000 120000002 3400.00
1001 122000001 2000.00
1001 122000002 3440.00
After it downloaded the Excel should contains only two line(by dfaultt)
+ 1000 120000001 3000.30
+ 1001 122000001 2000.00
When you click on symbol(+) then hidden rows will shown.
We can do it in Excel by using Group. Just select few rows(row number 1 to 5) and then go to
DATA->GROUP AND OUTLINE->GROUP.
Then u will see one line for the selected rows.
Can anybody tell me how to achieve it through OLE in ABAP. Your inputs are highly needed for me. Thank you so mush!
Regards,
Meera.We can do it, Can anybody tell me OLE Mehod which should I use in the reprot?
-
Is it possible to create Excel Sheet using OLE automation in App server
Hi,
Is it possible to create Excel Sheet using OLE automation in Application server(Open Dataset)
Thanks in advance...Unless your application server is on Windows OS, or it is connected to a Windows server by RFC. What is the requirement exactly, I don't understand?
-
Excel from abap using OLE, trying to make an excel cell-property currency
Hello everyone,
I have build an abap application which generates a price list as a MS Excel file using OLE techniques (ole2incl).
One small thing in the excel file is lacking and I hope some one can help me out:
I want to give certain cells in excel the "cell property - currency", so that excel shows the amounts as currency values.
Has anyone done or seen that before?
Thanks a lot in advance.
Kind regard, Archie OomenHi,
I am having a similiar problem trying to fix the CELL format as TEXT.
No matter how I try, it often ends up as 'GENERAL.
Have you resolved your issue?
Prehaps, you could share it if you had already rectify your problem.
Thanks a lot -
Hi All,
Can any one help me to create an multiple excel sheet in an work book using OLE. I want to create more than 3 sheets in excel, which is default sheets in excel when we one excel.Hi,
Check the below sample code.
Here I'm downloading the same table twice into 2 different sheets for example purpose.
TYPE-POOLS ole2.
DATA: wf_cell_from TYPE ole2_object,
wf_cell_from1 TYPE ole2_object,
wf_cell_to TYPE ole2_object,
wf_cell_to1 TYPE ole2_object,
wf_excel TYPE ole2_object, " Excel object
wf_mapl TYPE ole2_object, " list of workbooks
wf_map TYPE ole2_object, " workbook
wf_worksheet TYPE ole2_object, " Worksheet
wf_cell TYPE ole2_object, " Cell Range
wf_cell1 TYPE ole2_object,
wf_range TYPE ole2_object, " Range of cells to be formatted
wf_range2 TYPE ole2_object,
wf_column1 TYPE ole2_object. " Column to be Autofit
DATA: BEGIN OF t_hex,
l_tab TYPE x,
END OF t_hex.
DATA: wf_deli(1) TYPE c, "delimiter
wf_action TYPE i,
wf_file TYPE string,
wf_path TYPE string,
wf_fullpath TYPE string.
TYPES: t_data1(1500) TYPE c,
int_ty TYPE TABLE OF t_data1. "line type internal table
*All the data was prepared as line type internal tables for faster
*download
DATA: int_matl TYPE int_ty ,
int_matl1 TYPE int_ty ,
wa_matl TYPE t_data1.
TYPES: BEGIN OF ty_mara,
matnr TYPE matnr,
mtart TYPE mtart,
matkl TYPE matkl,
meins TYPE meins,
END OF ty_mara.
DATA: int_mara TYPE STANDARD TABLE OF ty_mara,
wa_mara TYPE ty_mara.
FIELD-SYMBOLS: <fs> .
DATA: wc_sheets LIKE sy-index. "no.of sheets
DATA: it_tabemp TYPE filetable,
gd_subrcemp TYPE i.
CONSTANTS wl_c09(2) TYPE n VALUE 09.
CLEAR wc_sheets.
DEFINE ole_check_error.
if &1 ne 0.
message e001(zz) with &1.
exit.
endif.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
PARAMETERS: p_file LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK block1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
REFRESH: it_tabemp.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Select File'
* default_extension = 'xls'
default_file_name = 'Material Details'
* with_encoding =
file_filter = '*.xls'
initial_directory = 'C:\'
prompt_on_overwrite = ' '
CHANGING
filename = wf_file
path = wf_path
fullpath = wf_fullpath
user_action = wf_action
* file_encoding =
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF wf_action EQ 9.
MESSAGE 'No File have been Selected' TYPE 'S'.
ELSE.
p_file = wf_fullpath.
PERFORM create_excel.
ENDIF.
*& Form create_excel
* text
FORM create_excel.
LOOP AT it_tabemp INTO p_file.
ENDLOOP.
* START THE EXCEL APPLICATION
CREATE OBJECT wf_excel 'EXCEL.APPLICATION'.
PERFORM err_hdl.
* PUT EXCEL IN FRONT
SET PROPERTY OF wf_excel 'VISIBLE' = 1.
PERFORM err_hdl.
* CREATE AN EXCEL WORKBOOK OBJECT
CALL METHOD OF wf_excel 'WORKBOOKS' = wf_mapl.
PERFORM err_hdl.
SET PROPERTY OF wf_excel 'SheetsInNewWorkbook' = 3. "no of sheets
PERFORM err_hdl.
CALL METHOD OF wf_mapl 'ADD' = wf_map.
PERFORM err_hdl.
*Assign the Delimiter to field symbol.
ASSIGN wf_deli TO <fs> TYPE 'X'.
t_hex-l_tab = wl_c09.
<fs> = t_hex-l_tab.
CLEAR int_matl.
REFRESH int_matl.
SELECT matnr
mtart
matkl
meins
FROM mara
INTO CORRESPONDING FIELDS OF TABLE int_mara.
*first the headings will be displayed in the excel sheet
CONCATENATE 'Material Number'
'Material type'
'Material Group'
'Base Unit of Measure'
INTO wa_matl
SEPARATED BY wf_deli.
APPEND wa_matl TO int_matl.
LOOP AT int_mara INTO wa_mara.
CONCATENATE wa_mara-matnr
wa_mara-mtart
wa_mara-matkl
wa_mara-meins
INTO wa_matl
SEPARATED BY wf_deli.
APPEND wa_matl TO int_matl.
CLEAR wa_matl.
ENDLOOP.
*Copyng thae same contents to another table to display in
*new sheet
MOVE int_matl TO int_matl1.
PERFORM f_material_details
TABLES int_matl
USING 1.
PERFORM f_material_details
TABLES int_matl
USING 2.
GET PROPERTY OF wf_excel 'ActiveSheet' = wf_map.
GET PROPERTY OF wf_excel 'ActiveWorkbook' = wf_mapl.
CALL FUNCTION 'FLUSH'
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2
OTHERS = 3.
IF sy-subrc = 0.
CALL METHOD OF wf_map 'SAVEAS'
EXPORTING #1 = p_file.
ENDIF.
CALL METHOD OF wf_mapl 'CLOSE'.
CALL METHOD OF wf_excel 'QUIT'.
FREE OBJECT wf_mapl.
FREE OBJECT wf_map.
FREE OBJECT wf_excel.
ENDFORM. "create_excel
*& Form ERR_HDL
* text
FORM err_hdl.
IF sy-subrc <> 0.
WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
STOP.
ENDIF.
ENDFORM. "ERR_HDL
*-- End of Program
*& Form f_material_details
* text
* --> p1 text
* <-- p2 text
FORM f_material_details
TABLES lint_matl
USING l_sheet_no TYPE i.
DATA: lv_lines TYPE i,
lv_sheet_name(50) TYPE c.
wc_sheets = l_sheet_no.
CASE l_sheet_no.
WHEN 1.
lv_sheet_name = 'Material_sheet1'.
WHEN 2.
lv_sheet_name = 'Material_sheet2'.
ENDCASE.
*-- activating the worksheet and giving a name to it
CALL METHOD OF wf_excel 'WORKSHEETS' = wf_worksheet
EXPORTING
#1 = wc_sheets.
CALL METHOD OF wf_worksheet 'ACTIVATE'.
SET PROPERTY OF wf_worksheet 'NAME' = lv_sheet_name.
*--formatting the cells
CALL METHOD OF wf_excel 'Cells' = wf_cell_from
EXPORTING
#1 = 1
#2 = 1.
DESCRIBE TABLE lint_matl LINES lv_lines.
CALL METHOD OF wf_excel 'Cells' = wf_cell_to
EXPORTING
#1 = lv_lines
#2 = 4.
*--range of cells to be formatted (in this case 1 to 4)
CALL METHOD OF wf_excel 'Range' = wf_cell
EXPORTING
#1 = wf_cell_from
#2 = wf_cell_to.
*--formatting the cells
CALL METHOD OF wf_excel 'Cells' = wf_cell_from1
EXPORTING
#1 = 1
#2 = 1.
DESCRIBE TABLE lint_matl LINES lv_lines.
CALL METHOD OF wf_excel 'Cells' = wf_cell_to1
EXPORTING
#1 = lv_lines
#2 = 1.
CALL METHOD OF wf_excel 'Range' = wf_cell1 " Cell range for first
" column(Material)
EXPORTING
#1 = wf_cell_from1
#2 = wf_cell_to1.
SET PROPERTY OF wf_cell1 'NumberFormat' = '@' . "To disply zeros
"in Material number
DATA l_rc TYPE i.
*DATA download into excel first sheet
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = lint_matl[]
CHANGING
rc = l_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 4.
CALL METHOD OF wf_worksheet 'Paste'.
CALL METHOD OF wf_excel 'Columns' = wf_column1.
CALL METHOD OF wf_column1 'Autofit'.
FREE OBJECT wf_column1.
ENDFORM. " f_material_details
Regards,
Manoj Kumar P
Edited by: Manoj Kumar on Mar 5, 2009 11:25 AM
Maybe you are looking for
-
After recent iPhone update why does my phone no longer work with my car's bluetooth?
Recently I updated my iPhone 5 and my wife's iPhone 4s. My wife and I attempted to use the bluetooth connection in out car to listen to some music and it will not work. On our screen we get a message "No Data." Since the same is true for both of my i
-
Exchange 2010 accepted domain and email address policy
So I need some help as to which accepted domain is right for us. We are a single forest single domain that is subbed to a parent domain. sub.domain.com We run our own exchange 2010 separate from domain.com. We want all mail to show up as @domain.co
-
Forgot to sync 3G before connecting iphone 4
Hi, I just messed up. I had just brought home my new iPhone 4 and without thinking about what I was doing I connected it to my iMac and synced it (at this point I had pulled the new SIM card I got apart so that it would fit in the new phone, no usabl
-
Creative cloud app wont install on iMac
I'm the admin for our group and I have a user who can't seem to download the creative cloud app, she can run the install and pick which programs she wants but it wont put the actual Creative cloud icon on her machine. Without this she can't run any a
-
Apps won't install via App Store
A week ago I got a used iphone 5 for my GF so she could log our newborn's daily achievements, but the phone won't allow the download of apps from the App Store. If I click on the price/install button, it circles as if it's downloading, and then it r