Excel-Integration in cobol

i was able to find the correct syntax for many functions giving in msexcel.cpy

But not to set the topmargin, bottommargin, leftmargin, right margin

in VB the syntax found is

Worksheets("Sheet1").PageSetup.LeftMargin = _ Application.CentimetersToPoints(2)

The function for this in msexcel.cpy are:
*> Method: "getMarginBottom".
*> 01 MarginBottom comp-1.
*> invoke returning MarginBottom.
*> ----------------
*> Method: "setMarginBottom".
*> 01 MarginBottom comp-1.
*> invoke using
*> by value MarginBottom *> [IN].
*> ----------------
*> Method: "getMarginLeft".
*> 01 MarginLeft comp-1.
*> invoke returning MarginLeft.
*> ----------------
*> Method: "setMarginLeft".
*> 01 MarginLeft comp-1.
*> invoke using
*> by value MarginLeft *> [IN].
*> ----------------
*> Method: "getMarginRight".
*> 01 MarginRight comp-1.
*> invoke returning MarginRight.
*> ----------------
*> Method: "setMarginRight".
*> 01 MarginRight comp-1.
*> invoke using
*> by value MarginRight *> [IN].
*> ----------------
*> Method: "getMarginTop".
*> 01 MarginTop comp-1.
*> invoke returning MarginTop.
*> ----------------
*> Method: "setMarginTop".
*> 01 MarginTop comp-1.
*> invoke using
*> by value MarginTop *> [IN].

But all my tries are not successfull
May be in newer office version any invoke must be set otherwise

I can only hope that Chris know the solution!
Thanks for all help!

invoke Pagesetup "getMarginBottom" using ???


cg
  • The following appears to be equivalent to the statement:

    Worksheets("Sheet1").PageSetup.LeftMargin = _ Application.CentimetersToPoints(2)

    *> Create a new instance of Microsoft Excel
    invoke MSExcel "new" returning ExcelObject

    *> Get the collection of WorkBooks
    invoke ExcelObject "getWorkBooks"
        returning WorkBooksCollection


    invoke WorkbooksCollection "Open" using ExcelFileName
        returning Workbook

    invoke Workbook "getWorksheets"
        returning worksheets

    invoke Worksheets "getItem" using z"Sheet1"
       returning worksheet1

    *> Points is defined as COMP-1

    invoke ExcelObject "CentimetersToPoints" using by value 2
       returning points

    invoke worksheet1 "getPageSetup"
       returning pagesetup

    invoke pagesetup "setLeftMargin" using by value points

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • Thanks Chris, i will test this!
    But i had use this a "getLeftMargin" after the object getpageup don't work with Bottommargin declared as comp-1.

  • my tests this evening with your code was not successull

    what means value 2

  • I assume it means that you are converting 2 centimeters to points and using that as your margin. You should replace that with whatever your application requires.

    I am just following the example you provided.

    The code I provided to you works for me and if I make Excel visible and look at the margins set for the worksheet they have a custom size and the left margin has been changed.

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • hi Chris, i have found my errors, your commands run correctly!
    Sorry, i had invers the command and write for all "setMarginLeft" and not "setLeftmargin"
    here the complete command for margins:

    *> Points is defined as COMP-1
    invoke pagesetup "getBottomMargin" returning points
    invoke ExcelObject "CentimetersToPoints" using by value 2
    returning points
    invoke pagesetup "setBottomMargin" using by value points

    invoke ExcelObject "CentimetersToPoints" using by value 2
    returning points
    invoke Pagesetup "setLeftMargin" using by value points
    invoke ExcelObject "CentimetersToPoints" using by value 2
    returning points
    invoke Pagesetup "setRightMargin" using by value points
    invoke ExcelObject "CentimetersToPoints" using by value 2
    returning points
    invoke Pagesetup "setTopMargin" using by value points