View Raw SPL
/*****************************************************************************
* *
* XLSAVEAS.SPL Copyright (C) 2011 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Saves current Excel Workbook to specified file *
* *
* Revisions: 7 Jan 2011 RRR Creation *
* *
*****************************************************************************/
#include
#if @HELP_XLSAVEAS
XLSAVEAS
Purpose: Saves current Excel Workbook to a specified file.
Syntax: XLSAVEAS("filename", format, verbose)
filename - A string, the target file.
format - Optional, an integer. The file format of the file to
save. Defaults to -1, native type (XLS).
verbose - Optional, an integer. Message flag.
0: do not display Excel messages (default)
1: display Excel messages
Returns: 1 if successful, else an error
Example:
xlinit();
xlput("A1:C10", ravel(1..30, 10));
xlsaveas("C:\temp\test.xls");
xlclear();
The values 1..30 are shaped into a 10x3 array and written
to cells A1 through C10. The Workbook is saved in XLS format
to the file C:\temp\test.xls.
Example:
xlinit();
xlput("A1:C10", ravel(1..30, 10));
xlsaveas("C:\temp\test.csv", 6);
xlclear();
Same as above, except the file is saved to C:\temp\test.csv
in CSV format.
Remarks:
XLSAVEAS connects to the running instance of Excel.
The format parameter specifies the file format. The following
formats are supported:
Constant Value Description
-------- ----- -----------
xlWorkbook -4143 Microsoft Excel Workbook
xlHTML 44 Web Page
xlTemplate 17 Template
xlPlatformText -4158 Text (Tab Delimited)
xlUnicodeText 42 Unicode Text
xlExcel5 39 Microsoft Excel 5.0/95 Workbook
xlExcel7 39 Microsoft Excel 5.0/95 Workbook
xlExcel9795 43 Microsoft Excel 97-2000 & 5.0/95 Workbook
xlCSV 6 CSV (Comma Delimited)
xlExcel4 33 Microsoft Excel 4.0 Worksheet
xlExcel3 29 Microsoft Excel 3.0 Worksheet
xlExcel2 16 Microsoft Excel 2.1 Worksheet
xl4Workbook 35 Microsoft Excel 4.0 Workbook
xlWK4 38 WK4 (1-2-3)
xlWK3FM3 32 WK3, FM3 (1-2-3)
xlWK3FM3 15 WK3 (1-2-3)
xlWK1FMT 30 WK1, FMT (1-2-3)
xlWK1ALL 31 WK1, ALL (1-2-3)
xlWK1 5 WK1 (1-2-3)
xlWKS 4 WKS (1-2-3)
xlWQ1 34 WQ1 (Quattro Pro/DOS)
xlDBF4 11 DBF 4 (dBASE IV)
xlDBF3 8 DBF 3 (dBASE III)
xlDBF2 7 DBF 2 (dBASE II)
xlTextPrinter 36 Formatted Text (Space Delimited)
xlTextMac 19 Text (Macintosh)
xlTextMSDOS 21 Text (MS-DOS)
xlCSVMac 22 CSV (Macintosh)
xlCSVMSDOS 24 CSV (MS-DOS)
xlDIF 9 DIF (Data Interchange Format)
xlSYLK 2 SYLK (Symbolic Link)
See XLSAVE to save to the original file.
See Also:
Xlclear
Xlget
Xlinit
Xlput
Xlsave
#endif
/* save running Excel workbook to file in specified format */
xlsaveas(filename, format, verbose)
{
local xl, status = -1;
if (argc < 3)
{
if (argc < 2)
{
if (argc < 1) return(0);
format = -1;
}
verbose = 0;
}
/* current instance */
xl = xlconnect();
if (isobject(xl))
{
/* Excel messages */
xl.displayalerts = verbose;
if (format == -1)
{
/* native format */
status = xl.activeworkbook.saveas(filename);
}
else
{
/* specified format */
status = xl.activeworkbook.saveas(filename, format);
}
}
return(status);
}