'Function to get the strings by module(s)/file(s), merge with
those strings from existing w2p language file which are already
translated and call the "write_xls()" method if the
default filetype "xls" is chosen. If "po" is chosen, then the
write_po()" method is called.'

def export_file(self, langfile, modlist, filelist, filetype, all_template_flag):

    request = current.request
    settings = current.deployment_settings
    appname = request.application
    folder = request.folder
    join = os.path.join
    langcode = langfile[:(-3)]
    langfile = join(folder, 'languages', langfile)
    if (not os.path.exists(langfile)):
        f = open(langfile, 'w')
        f.write('')
        f.close()
    NewStrings = []
    A = TranslateAPI()
    if (all_template_flag == 1):
        A.grp.group_files(join(folder, 'modules', 'templates'))
    else:
        templates = settings.get_template()
        if (not isinstance(templates, (tuple, list))):
            templates = (templates,)
        group_files = A.grp.group_files
        for template in templates:
            template_folder = join(folder, 'modules', 'templates', template)
            group_files(template_folder)
    R = TranslateReadFiles()
    core_modules = ('auth', 'default')
    for mod in core_modules:
        modlist.append(mod)
    if ('admin' in modlist):
        modlist.append('appadmin')
        modlist.append('error')
    models = current.models
    for mod in modlist:
        if hasattr(models, mod):
            obj = getattr(models, mod)
            if hasattr(obj, 'depends'):
                for element in obj.depends:
                    if (element not in modlist):
                        modlist.append(element)
    get_strings_by_module = A.get_strings_by_module
    for mod in modlist:
        NewStrings += get_strings_by_module(mod)
    get_strings_by_file = A.get_strings_by_file
    for f in filelist:
        NewStrings += get_strings_by_file(f)
    NewStrings = self.remove_quotes(NewStrings)
    NewStrings += R.get_database_strings(all_template_flag)
    NewStrings += R.get_user_strings()
    NewStrings = self.remove_duplicates(NewStrings)
    NewStrings.sort(key=(lambda tup: tup[1]))
    OldStrings = self.read_w2p(langfile)
    OldStrings.sort(key=(lambda tup: tup[0]))
    Strings = []
    sappend = Strings.append
    i = 0
    lim = len(OldStrings)
    for (l, s) in NewStrings:
        while ((i < lim) and (OldStrings[i][0] < s)):
            i += 1
        if ((i != lim) and (OldStrings[i][0] == s) and (OldStrings[i][1].startswith('***    ') == False)):
            sappend((l, s, OldStrings[i][1]))
        else:
            sappend((l, s, ''))
    if (filetype == 'xls'):
        return self.write_xls(Strings, langcode)
    elif (filetype == 'po'):
        return self.write_po(Strings)
