excel_createΒΆ
excel_create creates a Excel file in the Biff 12 format (Excel 2007 or newer with the extension .xlsx).
-
oExcel = excel_create(ssFile)
-
oExcel = excel_create(ssFile, ssTemplateFile)
Return Value
oExcel is a UniScript object or an error object, if an error occurred. See example.
Parameters
-
ssFile
ssFile is the complete file name. If the file already exists it will be overwritten.
-
ssTemplateFile
ssTemplateFile is the complete filename of an xlsx Excel file. The template file is a standard Excel file created with Excel 2007 or newer. The file contains a style table
styles.xml
which will be copied to the new file. Each style definition contains an index which can be used to select the cell style using the excel_sheet_put_rows function. The example style filestyles.xlsx
can be found in the UniPlot directorytemplate/excel/
. See example.
Example
Beispiel
def test_excel_write()
{
smData = ["Speed", "Torque";
"rpm", "Nm"];
rmData = [1000.0, 10.0;
2000.0, 20.0;
3000.0, 30.0;
4000.0, 40.0;
5000.0, 50.0];
ssExcelFile = GetSaveFileName("c:\test.xlsx", "Excel 2007 File|*.xlsx*|")
if (ssExcelFile == "") {
return;
}
ssStyleFile = GetProfileString_Policy("ExcelExport", "StyleTemplate", ..
GetRootDirectory() + "template/excel/styles.xlsx");
hMap = excel_get_style_map(ssStyleFile);
styNumber = excel_get_style_index(hMap, "0.0000");
styHeader = excel_get_style_index(hMap, "Channelnames");
MapDestroy(hMap);
oExcel = excel_create(ssExcelFile, ssStyleFile);
if (type(oExcel) == "error") {
MessageBoxError("Excel-Export\n\n%s\n\nFile: %s", oExcel.message, ssExcelFile);
return FALSE;
}
oSheet = excel_sheet_create(oExcel, "Data1", nr(smData) + nr(rmData), nc(smData));
n = excel_sheet_put_rows(oSheet, smData, zeros(size(smData)) + styHeader);
if (type(n) == "error") {
MessageBoxError("Excel-Export\n\n%s\n\nFile: %s", n.message, ssExcelFile);
return FALSE;
}
n = excel_sheet_put_rows(oSheet, rmData, zeros(size(rmData)) + styNumber);
if (type(n) == "error") {
MessageBoxError("Excel-Export\n\n%s\n\nFile: %s", n.message, ssExcelFile);
return FALSE;
}
excel_sheet_close(oSheet);
excel_close(oExcel);
ShellExecute(ssExcelFile);
return TRUE;
}
History
Version | Description |
---|---|
R2013.15 | In case of an error, an error object is returned. |
5.5.0 | New |
See also
Overview Excel Files, excel_open, excel_sheet_create, excel_sheet_put_rows, excel_sheet_close, excel_close, excel_get_style_map
id-469683