本文整理汇总了Python中Products.ERP5OOo.OOoUtils.OOoParser.getSpreadsheetsMapping方法的典型用法代码示例。如果您正苦于以下问题:Python OOoParser.getSpreadsheetsMapping方法的具体用法?Python OOoParser.getSpreadsheetsMapping怎么用?Python OOoParser.getSpreadsheetsMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.ERP5OOo.OOoUtils.OOoParser
的用法示例。
在下文中一共展示了OOoParser.getSpreadsheetsMapping方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSpreadsheet
# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import getSpreadsheetsMapping [as 别名]
def getSpreadsheet(file):
ooo_parser = OOoParser()
# Extract tables from the speadsheet file
if file is None:
return {}
elif hasattr(file, 'headers'):
# if the file is not an open office format, try to convert it using oood
content_type = file.headers.get('Content-Type', '')
if not (content_type.startswith('application/vnd.sun.xml')
or content_type.startswith('application/vnd.oasis.opendocument')):
from Products.ERP5Type.Document import newTempOOoDocument
tmp_ooo = newTempOOoDocument(context, file.filename)
tmp_ooo.edit(data=file.read(), content_type=content_type)
tmp_ooo.convertToBaseFormat()
ignored, import_file_content = tmp_ooo.convert('ods')
ooo_parser.openFromString(str(import_file_content))
else:
ooo_parser.openFile(file)
else:
ooo_parser.openFromString(file)
return ooo_parser.getSpreadsheetsMapping()
示例2: convert
# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import getSpreadsheetsMapping [as 别名]
def convert(self, filename, data=None):
from Products.ERP5OOo.OOoUtils import OOoParser
OOoParser = OOoParser()
import_file = read(self, filename, data)
# Extract tables from the speadsheet file
OOoParser.openFile(import_file)
filename = OOoParser.getFilename()
spreadsheets = OOoParser.getSpreadsheetsMapping()
table_dict = {}
for table_name, table in spreadsheets.items():
if not table:
continue
# Get the header of the table
columns_header = table[0]
# Get the mapping to help us to know the property according a cell index
property_map = {}
column_index = 0
for column in columns_header:
column_id = getIdFromString(column)
# The column has no header information
# The column has a normal header
property_map[column_index] = column_id
column_index += 1
# Construct categories data (with absolut path) from table lines
object_list = []
for line in table[1:]:
object_property_dict = {}
# Exclude empty lines
if line.count('') + line.count(None) == len(line):
continue
# Analyse every cells of the line
cell_index = 0
for cell in line:
# Ignore empty cells, do the test on the generated id
# because getIdFromString() is more restrictive
cell_id = getIdFromString(cell)
if cell_id not in ('', None):
# Get the property corresponding to the cell data
property_id = property_map[cell_index]
# Convert the value to something like '\xc3\xa9' not '\xc3\xa9'
object_property_dict[property_id] = cell.encode('UTF-8')
cell_index += 1
if len(object_property_dict) > 0:
object_list.append(object_property_dict)
table_dict[table_name.encode('UTF-8')] = object_list
if len(table_dict.keys()) == 1:
return object_list
else:
return table_dict
示例3: test_getSpreadSheetMappingText
# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import getSpreadsheetsMapping [as 别名]
def test_getSpreadSheetMappingText(self):
parser = OOoParser()
parser.openFile(open(makeFilePath('complex_text.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Feuille1'], mapping.keys())
self.assertEqual(mapping['Feuille1'][0], [' leading space'])
self.assertEqual(mapping['Feuille1'][1], [' leading space'])
self.assertEqual(mapping['Feuille1'][2], ['tab\t'])
self.assertEqual(mapping['Feuille1'][3], ['New\nLine'])
示例4: test_getSpreadSheetMappingEmptyCells
# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import getSpreadsheetsMapping [as 别名]
def test_getSpreadSheetMappingEmptyCells(self):
parser = OOoParser()
parser.openFile(open(makeFilePath('empty_cells.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Feuille1'], mapping.keys())
self.assertEqual(mapping['Feuille1'],
[
['A1', None, 'C1'],
[],
[None, 'B3',],
])
示例5: not
# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import getSpreadsheetsMapping [as 别名]
content_type = import_file.headers.get('Content-Type', '')
if not (content_type.startswith('application/vnd.sun.xml')
or content_type.startswith('application/vnd.oasis.opendocument')):
from Products.ERP5Type.Document import newTempOOoDocument
tmp_ooo = newTempOOoDocument(context, "_")
tmp_ooo.edit(data=import_file.read(),
content_type=content_type)
tmp_ooo.convertToBaseFormat()
ignored, import_file_content = tmp_ooo.convert('ods')
parser.openFromString(str(import_file_content))
else:
parser.openFile(import_file)
# Extract tables from the speadsheet file
filename = parser.getFilename()
spreadsheet_list = parser.getSpreadsheetsMapping(no_empty_lines=True)
for table_name in spreadsheet_list.keys():
sheet = spreadsheet_list[table_name]
if not sheet:
continue
# Get the header of the table
columns_header = sheet[0]
# Get the mapping to help us know the property according a cell index
property_map = {}
column_index = 0
path_index = 0
for column in columns_header:
column_id = getIDFromString(column)
# This give us the information that the path definition has started