示例#1
0
def xls2xform_convert():
    # Warnings.
    warnings = []
    
    json_survey = xls2json.parse_file_to_json(argv[1], warnings=warnings)
    survey = builder.create_survey_element_from_dict(json_survey)
    #Setting validate to false will cause the form not to be processed by ODK Validate.
    #This may be desirable since ODK Validate requires launching a subprocess that runs some java code.
    survey.print_xform_to_file(argv[2], validate=False, warnings=warnings)
    
    return warnings
示例#2
0
def xls2xform_convert():
    # Warnings.
    warnings = []

    json_survey = xls2json.parse_file_to_json(argv[1], warnings=warnings)
    survey = builder.create_survey_element_from_dict(json_survey)
    # Setting validate to false will cause the form not to be processed by
    # ODK Validate.
    # This may be desirable since ODK Validate requires launching a subprocess
    # that runs some java code.
    survey.print_xform_to_file(argv[2], validate=True, warnings=warnings)

    return warnings
示例#3
0
def xls2xform_convert(xlsform_path, xform_path, validate=True):
    warnings = []

    json_survey = xls2json.parse_file_to_json(xlsform_path, warnings=warnings)
    survey = builder.create_survey_element_from_dict(json_survey)
    # Setting validate to false will cause the form not to be processed by
    # ODK Validate.
    # This may be desirable since ODK Validate requires launching a subprocess
    # that runs some java code.
    survey.print_xform_to_file(xform_path, validate=validate, warnings=warnings)
    output_dir = os.path.split(xform_path)[0]
    if has_external_choices(json_survey):
        itemsets_csv = os.path.join(output_dir, "itemsets.csv")
        choices_exported = sheet_to_csv(xlsform_path, itemsets_csv, "external_choices")
        if not choices_exported:
            warnings.append("Could not export itemsets.csv, perhaps the external choices sheet is missing.")
    return warnings
示例#4
0
def xls2xform_convert(xlsform_path, xform_path, validate=True):
    warnings = []

    json_survey = xls2json.parse_file_to_json(xlsform_path, warnings=warnings)
    survey = builder.create_survey_element_from_dict(json_survey)
    # Setting validate to false will cause the form not to be processed by
    # ODK Validate.
    # This may be desirable since ODK Validate requires launching a subprocess
    # that runs some java code.
    survey.print_xform_to_file(xform_path, validate=validate, warnings=warnings)
    output_dir = os.path.split(xform_path)[0]
    if has_external_choices(json_survey):
        itemsets_csv = os.path.join(output_dir, "itemsets.csv")
        choices_exported = sheet_to_csv(xlsform_path, itemsets_csv, "external_choices")
        if not choices_exported:
            warnings.append("Could not export itemsets.csv, perhaps the external choices sheet is missing.")
        else:
            print 'External choices csv is located at:', itemsets_csv
    return warnings
示例#5
0
"""
xls2xform converts properly formatted Excel documents into XForms for
use with ODK Collect.
"""
import os, sys
import xls2json
import builder

if __name__ == '__main__':
    argv = sys.argv
    if len(argv) < 3:
        print __doc__
        print 'Usage:'
        print argv[0] + ' path_to_XLSForm output_path'
    else:
        warnings = []
        json_survey = xls2json.parse_file_to_json(argv[1], warnings=warnings)
        survey = builder.create_survey_element_from_dict(json_survey)
        #Setting validate to false will cause the form not to be processed by ODK Validate.
        #This may be desirable since ODK Validate requires launching a subprocess that runs some java code.
        survey.print_xform_to_file(argv[2], validate=True, warnings=warnings)
        for w in warnings:
            print w
        print 'Conversion complete!'