本文整理汇总了Python中onadata.libs.utils.export_tools.ExportBuilder.to_xls_export方法的典型用法代码示例。如果您正苦于以下问题:Python ExportBuilder.to_xls_export方法的具体用法?Python ExportBuilder.to_xls_export怎么用?Python ExportBuilder.to_xls_export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onadata.libs.utils.export_tools.ExportBuilder
的用法示例。
在下文中一共展示了ExportBuilder.to_xls_export方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_child_record_parent_table_is_updated_when_sheet_is_renamed
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_child_record_parent_table_is_updated_when_sheet_is_renamed(self):
survey = create_survey_from_xls(_logger_fixture_path(
'childrens_survey_with_a_very_long_name.xls'))
export_builder = ExportBuilder()
export_builder.set_survey(survey)
xls_file = NamedTemporaryFile(suffix='.xlsx')
filename = xls_file.name
export_builder.to_xls_export(filename, self.long_survey_data)
xls_file.seek(0)
wb = load_workbook(filename)
# get the children's sheet
ws1 = wb.get_sheet_by_name('childrens_survey_with_a_very_l1')
# parent_table is in cell K2
parent_table_name = ws1.cell('K2').value
expected_parent_table_name = 'childrens_survey_with_a_very_lo'
self.assertEqual(parent_table_name, expected_parent_table_name)
# get cartoons sheet
ws2 = wb.get_sheet_by_name('childrens_survey_with_a_very_l2')
parent_table_name = ws2.cell('G2').value
expected_parent_table_name = 'childrens_survey_with_a_very_l1'
self.assertEqual(parent_table_name, expected_parent_table_name)
xls_file.close()
示例2: test_to_xls_export_respects_custom_field_delimiter
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_to_xls_export_respects_custom_field_delimiter(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = ExportBuilder.GROUP_DELIMITER_DOT
export_builder.set_survey(survey)
xls_file = NamedTemporaryFile(suffix='.xls')
filename = xls_file.name
export_builder.to_xls_export(filename, self.data)
xls_file.seek(0)
wb = load_workbook(filename)
# check header columns
main_sheet = wb.get_sheet_by_name('childrens_survey')
expected_column_headers = [
u'name', u'age', u'geo.geolocation', u'geo._geolocation_latitude',
u'geo._geolocation_longitude', u'geo._geolocation_altitude',
u'geo._geolocation_precision', u'tel.tel.office',
u'tel.tel.mobile', u'_id', u'meta.instanceID', u'_uuid',
u'_submission_time', u'_index', u'_parent_index',
u'_parent_table_name', u'_tags', '_notes', '_version',
'_duration', '_submitted_by']
column_headers = [c[0].value for c in main_sheet.columns]
self.assertEqual(sorted(column_headers),
sorted(expected_column_headers))
xls_file.close()
示例3: test_xls_convert_dates_before_1900
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_xls_convert_dates_before_1900(self):
survey = create_survey_from_xls(viewer_fixture_path("test_data_types/test_data_types.xls"))
export_builder = ExportBuilder()
export_builder.set_survey(survey)
data = [{"name": "Abe", "when": "1899-07-03"}]
# create export file
temp_xls_file = NamedTemporaryFile(suffix=".xlsx")
export_builder.to_xls_export(temp_xls_file.name, data)
temp_xls_file.close()
示例4: test_xls_convert_dates_before_1900
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_xls_convert_dates_before_1900(self):
survey = create_survey_from_xls(viewer_fixture_path(
'test_data_types/test_data_types.xls'))
export_builder = ExportBuilder()
export_builder.set_survey(survey)
data = [
{
'name': 'Abe',
'when': '1899-07-03',
}
]
# create export file
temp_xls_file = NamedTemporaryFile(suffix='.xlsx')
export_builder.to_xls_export(temp_xls_file.name, data)
temp_xls_file.close()
示例5: test_xls_export_works_with_unicode
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_xls_export_works_with_unicode(self):
survey = create_survey_from_xls(_logger_fixture_path("childrens_survey_unicode.xls"))
export_builder = ExportBuilder()
export_builder.set_survey(survey)
temp_xls_file = NamedTemporaryFile(suffix=".xlsx")
export_builder.to_xls_export(temp_xls_file.name, self.data_utf8)
temp_xls_file.seek(0)
# check that values for red\u2019s and blue\u2019s are set to true
wb = load_workbook(temp_xls_file.name)
children_sheet = wb.get_sheet_by_name("children.info")
data = dict([(r[0].value, r[1].value) for r in children_sheet.columns])
self.assertTrue(data[u"children.info/fav_colors/red\u2019s"])
self.assertTrue(data[u"children.info/fav_colors/blue\u2019s"])
self.assertFalse(data[u"children.info/fav_colors/pink\u2019s"])
temp_xls_file.close()
示例6: test_to_xls_export_generates_valid_sheet_names
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_to_xls_export_generates_valid_sheet_names(self):
survey = create_survey_from_xls(_logger_fixture_path(
'childrens_survey_with_a_very_long_name.xls'))
export_builder = ExportBuilder()
export_builder.set_survey(survey)
xls_file = NamedTemporaryFile(suffix='.xls')
filename = xls_file.name
export_builder.to_xls_export(filename, self.data)
xls_file.seek(0)
wb = load_workbook(filename)
# check that we have childrens_survey, children, children_cartoons
# and children_cartoons_characters sheets
expected_sheet_names = ['childrens_survey_with_a_very_lo',
'childrens_survey_with_a_very_l1',
'childrens_survey_with_a_very_l2',
'childrens_survey_with_a_very_l3']
self.assertEqual(wb.get_sheet_names(), expected_sheet_names)
xls_file.close()
示例7: test_to_xls_export_respects_custom_field_delimiter
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_to_xls_export_respects_custom_field_delimiter(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = ExportBuilder.GROUP_DELIMITER_DOT
export_builder.set_survey(survey)
xls_file = NamedTemporaryFile(suffix=".xls")
filename = xls_file.name
export_builder.to_xls_export(filename, self.data)
xls_file.seek(0)
wb = load_workbook(filename)
# check header columns
main_sheet = wb.get_sheet_by_name("childrens_survey")
expected_column_headers = [
u"name",
u"age",
u"geo.geolocation",
u"geo._geolocation_latitude",
u"geo._geolocation_longitude",
u"geo._geolocation_altitude",
u"geo._geolocation_precision",
u"tel.tel.office",
u"tel.tel.mobile",
u"_id",
u"meta.instanceID",
u"_uuid",
u"_submission_time",
u"_index",
u"_parent_index",
u"_parent_table_name",
u"_tags",
"_notes",
]
column_headers = [c[0].value for c in main_sheet.columns]
self.assertEqual(sorted(column_headers), sorted(expected_column_headers))
xls_file.close()
示例8: test_to_xls_export_works
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_to_xls_export_works(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.set_survey(survey)
xls_file = NamedTemporaryFile(suffix='.xls')
filename = xls_file.name
export_builder.to_xls_export(filename, self.data)
xls_file.seek(0)
wb = load_workbook(filename)
# check that we have childrens_survey, children, children_cartoons
# and children_cartoons_characters sheets
expected_sheet_names = ['childrens_survey', 'children',
'children_cartoons',
'children_cartoons_characters']
self.assertEqual(wb.get_sheet_names(), expected_sheet_names)
# check header columns
main_sheet = wb.get_sheet_by_name('childrens_survey')
expected_column_headers = [
u'name', u'age', u'geo/geolocation', u'geo/_geolocation_latitude',
u'geo/_geolocation_longitude', u'geo/_geolocation_altitude',
u'geo/_geolocation_precision', u'tel/tel.office',
u'tel/tel.mobile', u'_id', u'meta/instanceID', u'_uuid',
u'_submission_time', u'_index', u'_parent_index',
u'_parent_table_name', u'_tags', '_notes', '_version']
column_headers = [c[0].value for c in main_sheet.columns]
self.assertEqual(sorted(column_headers),
sorted(expected_column_headers))
childrens_sheet = wb.get_sheet_by_name('children')
expected_column_headers = [
u'children/name', u'children/age', u'children/fav_colors',
u'children/fav_colors/red', u'children/fav_colors/blue',
u'children/fav_colors/pink', u'children/ice.creams',
u'children/ice.creams/vanilla', u'children/ice.creams/strawberry',
u'children/ice.creams/chocolate', u'_id', u'_uuid',
u'_submission_time', u'_index', u'_parent_index',
u'_parent_table_name', u'_tags', '_notes', '_version']
column_headers = [c[0].value for c in childrens_sheet.columns]
self.assertEqual(sorted(column_headers),
sorted(expected_column_headers))
cartoons_sheet = wb.get_sheet_by_name('children_cartoons')
expected_column_headers = [
u'children/cartoons/name', u'children/cartoons/why', u'_id',
u'_uuid', u'_submission_time', u'_index', u'_parent_index',
u'_parent_table_name', u'_tags', '_notes', '_version']
column_headers = [c[0].value for c in cartoons_sheet.columns]
self.assertEqual(sorted(column_headers),
sorted(expected_column_headers))
characters_sheet = wb.get_sheet_by_name('children_cartoons_characters')
expected_column_headers = [
u'children/cartoons/characters/name',
u'children/cartoons/characters/good_or_evil', u'_id', u'_uuid',
u'_submission_time', u'_index', u'_parent_index',
u'_parent_table_name', u'_tags', '_notes', '_version']
column_headers = [c[0].value for c in characters_sheet.columns]
self.assertEqual(sorted(column_headers),
sorted(expected_column_headers))
xls_file.close()
示例9: test_to_xls_export_works
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import to_xls_export [as 别名]
def test_to_xls_export_works(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.set_survey(survey)
xls_file = NamedTemporaryFile(suffix=".xls")
filename = xls_file.name
export_builder.to_xls_export(filename, self.data)
xls_file.seek(0)
wb = load_workbook(filename)
# check that we have childrens_survey, children, children_cartoons
# and children_cartoons_characters sheets
expected_sheet_names = ["childrens_survey", "children", "children_cartoons", "children_cartoons_characters"]
self.assertEqual(wb.get_sheet_names(), expected_sheet_names)
# check header columns
main_sheet = wb.get_sheet_by_name("childrens_survey")
expected_column_headers = [
u"name",
u"age",
u"geo/geolocation",
u"geo/_geolocation_latitude",
u"geo/_geolocation_longitude",
u"geo/_geolocation_altitude",
u"geo/_geolocation_precision",
u"tel/tel.office",
u"tel/tel.mobile",
u"_id",
u"meta/instanceID",
u"_uuid",
u"_submission_time",
u"_index",
u"_parent_index",
u"_parent_table_name",
u"_tags",
"_notes",
]
column_headers = [c[0].value for c in main_sheet.columns]
self.assertEqual(sorted(column_headers), sorted(expected_column_headers))
childrens_sheet = wb.get_sheet_by_name("children")
expected_column_headers = [
u"children/name",
u"children/age",
u"children/fav_colors",
u"children/fav_colors/red",
u"children/fav_colors/blue",
u"children/fav_colors/pink",
u"children/ice.creams",
u"children/ice.creams/vanilla",
u"children/ice.creams/strawberry",
u"children/ice.creams/chocolate",
u"_id",
u"_uuid",
u"_submission_time",
u"_index",
u"_parent_index",
u"_parent_table_name",
u"_tags",
"_notes",
]
column_headers = [c[0].value for c in childrens_sheet.columns]
self.assertEqual(sorted(column_headers), sorted(expected_column_headers))
cartoons_sheet = wb.get_sheet_by_name("children_cartoons")
expected_column_headers = [
u"children/cartoons/name",
u"children/cartoons/why",
u"_id",
u"_uuid",
u"_submission_time",
u"_index",
u"_parent_index",
u"_parent_table_name",
u"_tags",
"_notes",
]
column_headers = [c[0].value for c in cartoons_sheet.columns]
self.assertEqual(sorted(column_headers), sorted(expected_column_headers))
characters_sheet = wb.get_sheet_by_name("children_cartoons_characters")
expected_column_headers = [
u"children/cartoons/characters/name",
u"children/cartoons/characters/good_or_evil",
u"_id",
u"_uuid",
u"_submission_time",
u"_index",
u"_parent_index",
u"_parent_table_name",
u"_tags",
"_notes",
]
column_headers = [c[0].value for c in characters_sheet.columns]
self.assertEqual(sorted(column_headers), sorted(expected_column_headers))
xls_file.close()