Skip to content

Commit

Permalink
add scripting example
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanwerner committed Oct 6, 2016
1 parent 27e587b commit 7e77c12
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Examples/excel-scripting.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

#
# Here's an example of using the Excel scripting interface
# (paste this code into the shell).
#
# For more information, see
#
# https://bert-toolkit.com/excel-scripting-interface-in-r
#

#
# get a reference to the workbook
#
wb <- EXCEL$Application$get_ActiveWorkbook();

#
# add a sheet
#
new.sheet <- wb$get_Sheets()$Add();

#
# change the name of the new sheet. note that this will
# fail if a sheet with this name already exists.
#
new.sheet$put_Name( "R Data Set" );

#
# add some data. use matrices.
#
range <- new.sheet$get_Range( "B3:F152" );
range$put_Value( as.matrix( iris ));

#
# add column headers
#
header.range <- new.sheet$get_Range( "B2:F2" );
header.range$put_Value( colnames( iris ));

0 comments on commit 7e77c12

Please sign in to comment.