當前位置: 首頁>>代碼示例>>Python>>正文


Python OOoParser.openFile方法代碼示例

本文整理匯總了Python中Products.ERP5OOo.OOoUtils.OOoParser.openFile方法的典型用法代碼示例。如果您正苦於以下問題:Python OOoParser.openFile方法的具體用法?Python OOoParser.openFile怎麽用?Python OOoParser.openFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Products.ERP5OOo.OOoUtils.OOoParser的用法示例。


在下文中一共展示了OOoParser.openFile方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getSpreadsheet

# 需要導入模塊: from Products.ERP5OOo.OOoUtils import OOoParser [as 別名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFile [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()
開發者ID:ccwalkerjm,項目名稱:erp5,代碼行數:27,代碼來源:Base_importFile.py

示例2: convert

# 需要導入模塊: from Products.ERP5OOo.OOoUtils import OOoParser [as 別名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFile [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
開發者ID:MarkTang,項目名稱:erp5,代碼行數:59,代碼來源:extension.erp5.ConfigurationTemplate_readOOoCalcFile.py

示例3: test_getSpreadSheetMappingText

# 需要導入模塊: from Products.ERP5OOo.OOoUtils import OOoParser [as 別名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFile [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'])
開發者ID:Verde1705,項目名稱:erp5,代碼行數:11,代碼來源:testOOoParser.py

示例4: test_getSpreadSheetMappingEmptyCells

# 需要導入模塊: from Products.ERP5OOo.OOoUtils import OOoParser [as 別名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFile [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',],
     ])
開發者ID:Verde1705,項目名稱:erp5,代碼行數:13,代碼來源:testOOoParser.py

示例5: hasattr

# 需要導入模塊: from Products.ERP5OOo.OOoUtils import OOoParser [as 別名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFile [as 別名]
# if the file is not an open office format, try to convert it using oood
# FIXME: use portal_transforms
content_type = 'unknown'
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
開發者ID:ccwalkerjm,項目名稱:erp5,代碼行數:33,代碼來源:Base_getCategoriesSpreadSheetMapping.py


注:本文中的Products.ERP5OOo.OOoUtils.OOoParser.openFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。