Forum Discussion

FICO's avatar
FICO
Community Manager
5 years ago

I am trying to write to Excel from mosel. I want this write to always append to the existing content in the excel workbook. I read that the 'grow' attribute would work this way. However, does not app

I am using the following mosel code: to write to a given excel workbook output file. The output is written, but it does not append correctly. Note, the output table being written can be sparse (empty cells).

  initializations to "mmsheet.xlsx:grow;" + output_file

3 Replies

  • FICO's avatar
    FICO
    Community Manager

    Writing to an Excel spreadsheet with any of the mmsheet spreadsheet drivers does not affect the definition of ranges within the spreadsheet. Via the 'grow' option you indicate that output can continue under the row that is specified as (start of) the output range without modifying the range definition itself.

    This means that any follow-up output will start at the same position as the original output (hence overwriting any existing contents) - any changes to the output location need to be implemented programmatically, either on the Mosel level (keeping track of the number of lines written, eg. via a call to 'getsize' for the entity that is written and calculating the next output location correspondingly: the row-column notation for explicit range definitions lends itself best for this purpose) or within the Excel spreadsheet using some VBA code (in this case it is recommended to work with the I/O driver mmsheet.excel).

    Alternatively, it is possible to use the ODBC interface of Excel (NB: this interface is not well supported by Excel, so we don't normally recommend its use) - when selecting the header line of a table as output location you can replace

    initializations to "mmsheet.xlsx:grow;skiph;myfile.xlsx"

    AnArray as "MyOutRange"

    end-initializations

    by

    initializations to "mmodbc.odbc:myfile.xlsx"

    AnArray as "MyOutRange"

    end-initializations

    after running the latter version the area referred to by the range 'MyOutRange' is updated to the full output area so that the next output using the same range name will get appended to it.

  • FICO's avatar
    FICO
    Community Manager

    Thanks Susanne. I ended up coding this to work as you suggested. This is working as I want it to work now.

    However, I am still not totally finished. I was planning to write to an excel file that is an application attachment. But not I realize that I may not be able to update the app attachment. I notice that there is no insightputappattachment. Is it possible to update the application attachment after I finish writing to a file?

    Gary

  • FICO's avatar
    FICO
    Community Manager

    An Insight scenario is not allowed to modify the app data - you can only upload scenario attachments. Note that there is a possibility to access data from other Insight scenarios via the inter-scenario data access, that is by using the mminsight.scenariodata I/O driver (see the Insight Mosel Reference: https://www.fico.com/fico-xpress-optimization/docs/latest/mminsight/mminsightiodrv_sec_secmminsightiodrv.html).

    Otherwise, if you really need to upload app attachments you probably need to work directly with the Insight REST API (see https://www.fico.com/fico-xpress-optimization/docs/latest/insight/rest_api/resource_ProjectResource.html?scroll=path__v1_data_project_-id-_attachments.html) using the functionality of Mosel's mmhttp module.