View Raw SPL
/*****************************************************************************
*                                                                            *
*   XLSAVE.SPL   Copyright (C) 2011 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Saves current Excel Workbook via Automation                 *
*                                                                            *
*   Revisions:    7 Jan 2011  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_XLSAVE

    XLSAVE

    Purpose: Saves current Excel Workbook via ActiveX Automation

    Syntax:  XLSAVE(verbose)

               verbose - Optional integer, the message flag.
                           0: do not display Excel messages (default)
                           1: display Excel messages

    Returns: 1 if successful, else an error

    Example:
             xlinit("C:\temp\myfile.xls");
             xlput("A1:C10", ravel(1..30, 10));
             xlsave();
             xlclear();

             The file C:\temp\myfile.xls is opened and the values
             1..30 are shaped into a 10x3 array and written to cells
             A1 through C10. The Workbook is saved to the original file
             C:\temp\myfile.xls.

    Remarks:
             XLSAVE connects to the running instance of Excel.

             See XLSAVEAS to save to a specified file in an optional
             file format.
  
    See Also:
             Xlclear
             Xlget
             Xlinit
             Xlput
             Xlsaveas
#endif


/* save running Excel workbook to file in specified format */
xlsave(verbose)
{
        local xl, status = -1;

        if (argc < 1)
        {
                verbose = 0;
        }

        /* current instance */
        xl = xlconnect();

        if (isobject(xl))
        {
                /* Excel messages */
                xl.displayalerts = verbose;

                /* native format */
                status = xl.activeworkbook.save();
        }

        return(status);
}