text: import os
  import re
  import zipfile
  import tempfile
  
  # pythonnet
  import clr
  dll = os.path.abspath(os.path.join(os.getenv('APPVEYOR_BUILD_FOLDER', '..'), "aspose.cells", "lib", "net40", "Aspose.Cells.dll"))
  clr.AddReference(dll)
  from Aspose.Cells import Workbook, License
  
  
  this_dir = os.path.dirname(os.path.abspath(__file__))
  par_dir = os.path.join(this_dir, os.path.pardir)
  addin_path = os.path.join(par_dir, 'xlwings', 'addin', 'xlwings.xlam')
  standalone_win_path = os.path.join(par_dir, 'xlwings', 'quickstart_standalone_win.xlsm')
  standalone_mac_path = os.path.join(par_dir, 'xlwings', 'quickstart_standalone_mac.xlsm')
  xlwings_bas_path = os.path.join(par_dir, 'xlwings', 'xlwings.bas')
  version = os.getenv('APPVEYOR_BUILD_VERSION', 'dev')
  
  if os.getenv('ASPOSE_LICENSE'):
      license = License()
      license.SetLicense(os.path.abspath(os.path.join(this_dir, 'Aspose.Cells.lic')))
  
  
  def set_version_strings(code):
      code = re.sub(r'XLWINGS_VERSION As String = ".*"',
                    'XLWINGS_VERSION As String = "{}"'.format(version),
                    code)
      code = code.replace("xlwings32-dev.dll", "xlwings32-{}.dll".format(version))
      code = code.replace("xlwings64-dev.dll", "xlwings64-{}.dll".format(version))
      return code
  
  
  # Get vba modules from addin
  addin_wb = Workbook(addin_path)
  addin_modules = addin_wb.VbaProject.get_Modules()
  
  # Update Main module in addin
  main_code = addin_modules['Main'].get_Codes()
  main_code = set_version_strings(main_code)
  addin_modules['Main'].set_Codes(main_code)
  addin_wb.Save(addin_path)
  
  # Update standalone files with a single vba module containing the concatenated addin modules
  standalone_code = ''
  for m in ['License', 'Main', 'Config', 'Extensions', 'Utils']:
      standalone_code += addin_modules[m].get_Codes()
  
  standalone_code = set_version_strings(standalone_code)
  standalone_code = "'Version: {}\n".format(version) + standalone_code
  standalone_code = standalone_code.replace("ActiveWorkbook", "ThisWorkbook")
  standalone_code = standalone_code.replace("ActiveDocument", "ThisDocument")
  standalone_code = standalone_code.replace('Attribute VB_Name = "License"', "")
  standalone_code = standalone_code.replace("Attribute VB_Name", "\n'Attribute VB_Name")
  standalone_code = standalone_code.replace("Option Explicit", "")
  standalone_code = standalone_code.replace("""#Const App = "Microsoft Excel" 'Adjust when using outside of Excel""", "")
  
  # Re-add the Compiler Constant
  standalone_code = ('Attribute VB_Name = "xlwings"\n' +
                     """#Const App = "Microsoft Excel" 'Adjust when using outside of Excel\n""" +
                     '\n'.join(standalone_code.splitlines()))
  
  for path in [standalone_mac_path, standalone_win_path]:
      wb = Workbook(path)
      wb.VbaProject.get_Modules()['xlwings'].set_Codes(standalone_code)
      wb.Save(path)
  
  # Save standalone as xlwings.bas to be included in python package
  with open(xlwings_bas_path, 'w') as f:
      f.write(standalone_code)
  
  
  # Hack to fix the _rels/.rels file in the built add-in so the ribbon also shows up in Excel 2007
  def update_zip(zipname, filename, data):
      # generate a temp file
      tmpfd, tmpname = tempfile.mkstemp(dir=os.path.dirname(zipname))
      os.close(tmpfd)
  
      # create a temp copy of the archive without filename
      with zipfile.ZipFile(zipname, 'r') as zin:
          with zipfile.ZipFile(tmpname, 'w') as zout:
              for item in zin.infolist():
                  if item.filename != filename:
                      zout.writestr(item, zin.read(item.filename))
  
      # replace with the temp archive
      os.remove(zipname)
      os.rename(tmpname, zipname)
  
      # now add filename with its new data
      with zipfile.ZipFile(zipname, mode='a', compression=zipfile.ZIP_DEFLATED) as zf:
          zf.writestr(filename, data)
  
  content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/><Relationship Id="R09696ac1de4341b9" Type="http://schemas.microsoft.com/office/2006/relationships/ui/extensibility" Target="customUI/customUI.xml"/></Relationships>'
  update_zip(addin_path, '_rels/.rels', content)
  
  