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
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
        if char.isalnum() or char in translation_map.keys():
            clean_id += char
    # Delete leading and trailing char which are not alpha-numerics
    # This prevent having IDs with starting underscores
    while len(clean_id) > 0 and not clean_id[0].isalnum():
        clean_id = clean_id[1:]
    while len(clean_id) > 0 and not clean_id[-1].isalnum():
        clean_id = clean_id[:-1]

    return clean_id


parser.openFromString(str(document.getData()))

# Extract tables from the speadsheet file
filename = parser.getFilename()
spreadsheet_list = parser.getSpreadsheetsMapping(no_empty_lines=True)

spreadsheet_line_list = []

for table_name in spreadsheet_list.keys():
    if table_name != table:
        continue
    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
if hasattr(import_file, 'headers'):
  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)