clear
version 14.1
set more off
//Putexcel example
sysuse auto, clear
keep make price mpg
/* let's export this into a file called Testing.xlsx in a sheet called
All_Data with the first row as variables */
export excel using "Testing.xlsx", sheet("All_Data") first(var) replace
//Let's use putexcel, but first let's see the help file:
help putexcel
//Step 1:
putexcel set "Testing.xlsx", sheet("All_Data") modify
/* This is the same file we exported above, let's modify this file
by changing cell formats for column B and let's highlight it too */
putexcel B2:B74, nformat(account_d2_cur ) fpattern(solid, yellow)
//We could start using putexcel for a new sheet called "new" in Testing:
putexcel set "Testing.xlsx", sheet("new") modify
//Write in "This is data" which covers cell range A1-A2
putexcel A1:A2 = "This is data"
//We could make a new file too, let's call it Blank.xlsx:
putexcel set "Blank.xlsx", sheet("new") modify
// Let's put an equation in cell B which summs up A1-A5
putexcel B1 = formula(sum(A1:A5))
//We can also put a matrix of data using putexcel into our file
help matrix
//Let's make variable mpg into matrix A
mkmat mpg, matrix(A)
matrix list A
//Let's put this matrix into column C starting at C1.
putexcel set "Blank.xlsx", sheet("new") modify
putexcel C1 = matrix(A)