3.3.3 Sending Data To Worksheet

Introduction

This example puts the data from a Python dictionary object into a worksheet. Each worksheet column is filled with data by using the SetData method.

Examples

import PyOrigin

my_table = { 
     'xdata' : [1,1.1,1.2],
     'ydata' : [20, 21.3, 22.5],
     'yerr': [0.1, 0.3, 0.2]
}

wks = PyOrigin.ActiveLayer();
wks.Cols=len(my_table)
#or wks.SetColCount(len(my_table))
for i, key in enumerate(my_table):
	wks.Columns(i).SetData(my_table[key])
	wks.Columns(i).SetLongName(key)

To run this sample:

  1. Open Code Builder.
  2. Create a new Python file in the User Files Folder, like test1.py
  3. After putting in the code above and saving the file test1.py, open the script window and execute:
run -pyf test1.py