.. highlightlang:: us .. _excel_create: excel_create ============ .. index:: excel_create .. us.tag excel_create NOTREADYENGLISH excel excel-write New550 :ref:`excel_create` creates a Excel file in the Biff 12 format (Excel 2007 or newer with the extension .xlsx). .. function:: oExcel = excel_create(ssFile) oExcel = excel_create(ssFile, ssTemplateFile) .. us.return **Return Value** *oExcel* is a UniScript object or an error object, if an error occurred. See example. .. us.params **Parameters** .. uparam:: ssFile *ssFile* is the complete file name. If the file already exists it will be overwritten. .. uparam:: 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 :file:`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 :ref:`excel_sheet_put_rows` function. The example style file :file:`styles.xlsx` can be found in the UniPlot directory :file:`template/excel/`. See example. .. us.exampl **Example** **Beispiel** .. image:: S:/uniplot-obj/images/excel_create-style.* .. image:: S:/uniplot-obj/images/excel_create-result.* :: 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; } .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2013.15 - In case of an error, an error object is returned. * - 5.5.0 - New .. seealso:: :ref:`overview-excel-files`, :ref:`excel_open`, :ref:`excel_sheet_create`, :ref:`excel_sheet_put_rows`, :ref:`excel_sheet_close`, :ref:`excel_close`, :ref:`excel_get_style_map` :sub:`id-469683`