Skip to content

Instantly share code, notes, and snippets.

@andybell
Created January 25, 2019 15:36
Show Gist options
  • Save andybell/5692f59c275e95d0c0c1a0fbdd61be7e to your computer and use it in GitHub Desktop.
Save andybell/5692f59c275e95d0c0c1a0fbdd61be7e to your computer and use it in GitHub Desktop.
MarinegeoTemplateBuilder Example Script
import MarinegeoTemplateBuilder # load the MarinegeoTemplateBuilder library
from MarinegeoTemplateBuilder.classes import Field, Vocab # load the objects to contstruct fields + vocab
# python dictionary of the metadata values to prefill
metadataValues = {"TemplateVersion": "v0.0.0",
"Title": "This is a demo workbook"}
# list of fields to construct
fields = [
Field(sheet="Data", fieldName="field1", fieldDefinition="example field", fieldType="list"),
Field(sheet="Data", fieldName="field2", fieldDefinition="example field", fieldType="integer", maxValue=10),
Field(sheet="Data", fieldName="field3", fieldDefinition="example field", fieldType="decimal", minValue=10)
]
# list of vocab terms
vocab = [
Vocab(fieldName="field1", code="Red", definition="red"),
Vocab(fieldName="field1", code="Yellow", definition="yellow"),
Vocab(fieldName="field1", code="Blue", definition="blue"),
]
# construct the workbook
MarinegeoTemplateBuilder.main(
'Demo_Data-Entry-Template.xlsx', # name of the output excel workbook
fields, # list of field objects to construct
vocab, # list of vocab object to use (optional - only needed for building list fieldTypes)
'DEFAULT', # use the MarineGEO logo for the default branding
metadataValues=metadataValues # seed the first sheet with the metatdata values defined above
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment