XLCreateFromTemplate(template As String) As Integer

 

Creates a copy of the Excel file template and returns an Integer handle to it.

 

A SaveAsDialog window is displayed, where the user can select location and filename for a new Excel file to be created.

 

Before calling any other XLÉ function, one needs to retrieve a handle to a new Excel file, by using XLCreateFromTemplate.

This function requires an existing Excel file in the database, which can serve as a blueprint (template) for the Excel file to be created.

 

In order to create a file from a template, one must previously have imported the template-file with Script Manager.

See menu 'Script -> Script ManagerÉ -> Templates.

 

A template can be a standard Excel file (*.xls)

 

 

Parameters:

 

Name

Type

Description

template

String

Name of an existing Excel file which has been imported into the database before. A copy of this file will be used to create a new Excel file from it.

 

Returns:

 

Type

Value

Description

Integer

0 - n

Handle to the Excel file which was successfully created

 

-1

File is not existing

 

-2

User aborted creation of the new file

 

Available in:

 

WindowMain

WindowLink

YES

NO

 

 Used in:

 

XojoScript Name

GUID

Create XL Sheet from template

9A8AAB31-6896-4968-BB1A-DCC61061C9DA

Save As Excel sheet : participants list

E50602AA-F1F7-42E6-A44A-78456DD9B778

Save as Excel sheet : seminar participants list

03C22A3D-FF28-4E22-BB99-D7626BF5F0A4

Save as Excel sheet : seminar invoice list

6DDAFA87-2862-4129-8416-CBD57C5CDF9A

Save As Excel : Seminar pricelist CHF

986A0CAA-4B89-4E04-8984-FBB28538E740

 

Hint: You can find more references to XojoScripts which make use of this function by sending the following SQL statement to the database:

Select id,GUID, ScriptName,ScriptCode from im_scripts where ScriptCode Like '%XLCreateFromTemplate%'

 

Example XojoScript:

 

Dim hXL As Integer

 

// Display SaveAs Dialog to create new file

// based on the document with the name passed in

// as a parameter. The document must be loaded

// in the TEMPLATES section beforehand.

 

// Get Handle to newly created Excel file

hXL = XLCreateFromTemplate("myXLtest.xls")

 

If hXL > -1 Then

Dim i As integer

For i = 2 To 100

XLWriteString(hXL,i,0,"Zeile " + Str(i))

XLWriteNumber(hXL,i,1,i)

XLWriteBoolean(hXL,i,2,i)

Next

 

XLSave(hXL)

XL(hXL,"launch")

 

End If