Assuming the stub is saved to `xlsx.stub.js`, the following handler creates a
context and evaluates the standalone library:
```applescript
on getContext()
-- get contents of xlsx.stub.js
set UnixPath to POSIX path of ((path to me as text) & "::")
set libpath to POSIX path of (UnixPath & "xlsx.stub.js")
set {src, err} to current application's NSString's stringWithContentsOfFile:libpath encoding:(current application's NSISOLatin1StringEncoding) |error|:(reference)
if src is missing value then error (err's localizedDescription()) as text
-- create scripting context and evaluate the stub
set lang to current application's OSALanguage's languageForName:"JavaScript"
set osa to current application's OSAScript's alloc()'s initWithSource:src language:lang
return osa
end getContext
```
_Evaluating JS Code_
When calling a function, the result is an array whose first item is the value of
the evaluated code. A small helper function extracts the raw result:
```applescript
on extractResult(res)
return item 1 of ((current application's NSArray's arrayWithObject:res) as list)
end extractResult
```
With everything defined, `executeHandlerWithName` will run functions defined in
the stub. For example:
```applescript
set osa to getContext()
set {res, err} to osa's executeHandlerWithName:"wb_to_csv" arguments:{"pres.numbers"} |error|:(reference)
extractResult(res)
```
</TabItem>
</Tabs>
## Complete Demo
This example will read from a specified filename and print the first worksheet
set {src, err} to current application's NSString's stringWithContentsOfFile:libpath encoding:(current application's NSISOLatin1StringEncoding) |error|:(reference)
set lang to current application's OSALanguage's languageForName:"JavaScript"
set osa to current application's OSAScript's alloc()'s initWithSource:src language:lang
return osa
end getContext
on extractResult(res)
return item 1 of ((current application's NSArray's arrayWithObject:res) as list)