前言:
公司软件最近在做多语言版本,而又来一个西班牙文版本的,之前已经做过中文版本,英文版本和法文版本,之前是同事做的,现在安排我做,之前的做法,使用wps表格,翻译好,然后一个一个复制粘贴到ini文件里面,然后在软件里面读取。这种做法,后期维护起来挺麻烦的,所以自己研究了表格宏。之前也没接触过VB,所以只能自己网上学习

首先先下载VBA模块,下载链接 VBA 7.0

首先学习下VB语言的基本语法
定义变量
Dim i As Integer
Dim str As String
输出语句
Debug.Print "导出成功"
弹框
MsgBox "弹框"
打开视图--立即窗口查看输出

循环语句
for循环

For i = 0 To 5
Debug.Print i
Next i
while循环

Dim i As Integer
i = 0

While i < 5
Debug.Print i
i = i + 1
Wend
条件语句
if

If 1 = 1 Then

End If
if else

If 1 = 1 Then

Else

End If
if   else if    else

If 1 = 1 Then

ElseIf 2 = 2 Then

Else

End If
字符串连接
str = strA & strB
不等于使用<>

新建xlsm格式的表格,只有xlsm格式的文件才能保存宏

开发工具--宏,新建宏

编写代码
首先需要读写ini文件的接口

Private Declare Function GetPrivateProfileString Lib "Kernel32" _
Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal Key As Any, _
ByVal Value As String, _
ByVal ReturnedString As String, _
ByVal Size As Long, _
ByVal FilePath As String) As Long
Private Declare Function WritePrivateProfileString Lib "Kernel32" _
Alias "WritePrivateProfileStringA" _
(ByVal Section As String, _
ByVal Key As Any, _
ByVal Value As Any, _
ByVal FilePath As String) As Long
进一步封装接口

Public Function ReadFromIni(ByVal Section As String, ByVal Key As String, ByVal Value As String, ByVal FilePath As String) As String
Dim str As String
str = Space(256)
Dim ln As Long
ln = GetPrivateProfileString(Section, Key, Value, str, 255, FilePath)
If ln > 0 Then
str = Trim(str)
ReadFromIni = Mid(str, 1, Len(str) - 1)
Else
ReadFromIni = Value
End If
End Function
Public Function WriteToIni(ByVal Section As String, ByVal Key As String, ByVal Value As String, ByVal FilePath As String) As String
Dim l As Long
l = WritePrivateProfileString(Section, Key, Value, FilePath)
End Function
读取表格数据写入ini文件

Sub ExcelToIni()
'ini文件的路径
Dim strIniFile As String
strIniFile = "C:\Users\VULCAN\Desktop\Lang.ini"

'xls表格文件
Dim ExApp As New Excel.Application
'工作簿
Dim Exb As Excel.Workbook
'工作表
Dim Exsh As Excel.Worksheet

ExApp.Workbooks.Open "C:\Users\VULCAN\Desktop\Lang.xlsm"
Set Exb = ExApp.Workbooks(1)
Set Exsh = Exb.Worksheets("Sheet1")

'数据总数
Dim count As Integer
count = Exsh.UsedRange.Rows.count
Debug.Print count

'Value 5表示中文 6表示英文 7表示法文 8表示西班牙文
Dim langCol As Integer
langCol = 7

Dim i As Integer
i = 4
While i < count
If Exsh.Cells(i, 4).Value <> "" Then
a = WriteToIni(Exsh.Cells(i, 3).Value, Exsh.Cells(i, 4).Value, Exsh.Cells(i, langCol).Value, strIniFile)
End If
i = i + 1
Wend

Debug.Print "导出成功"

End Sub
上面三部分代码就是全部代码

下面为测试数据

中文版本

英文版本

法文版本

---------------------

【WPS】表格使用VBA宏编程写入ini文件实现软件多语言的更多相关文章

  1. MFC写入.ini文件的策略

    在使用WritePrivateProfileString的时候, 如果前两个参数已经在INI文件中存在,那该函数的作用就是修改键值,即楼主说的覆盖 如果第一个参数存在,第二个参数不存在,那作用是在IN ...

  2. 用C#读取,写入ini文件

    [DllImport("kernel32.dll")] private static extern bool WritePrivateProfileString(string se ...

  3. C语言实现<读取>和<写入> *.ini文件(转)

    原地址:https://blog.csdn.net/niha1993825jian/article/details/41086403 #include <stdio.h> #include ...

  4. C语言实现 读取写入ini文件实现(转)

    #include <stdio.h> #include <string.h> /* * 函数名: GetIniKeyString * 入口参数: title * 配置文件中一组 ...

  5. INI文件的读取(C语言:GetPrivateProfileString/GetPrivateProfileInt)

    INI文件格式说明 /********************************************* ini文件说明 ini文件是文本文件,由节点(Section)和键值对(key=val ...

  6. INI文件的写入与读取

    INI文件的写入与读取 [节名]         '[]中的节名对应此API的第一参数 Name=内容      'Nmae对应此API的第二参数 API的第三参数是没有取到匹配内容时返回的字符串; ...

  7. 配置信息写入到.ini文件中的方法

    在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下: 一.将信息写入.INI文件中 1.所用的WINAP ...

  8. 91.生成ini文件并写入和读取ini文件

    写入 WritePrivateProfileStringA("hello money", infx[i].name, money, "1.ini"); 按照字符 ...

  9. C# 创建INI文件,写入并可读取。----转载

    基于C#winform设计. 首先创建一个类,我命名为IniFiles.并引入命名空间using System.Runtime.InteropServices; 接着,声明API函数 [DllImpo ...

随机推荐

  1. 20180703mysql运维专题一:利用etl监控mysql日志

    参考地址: https://www.elastic.co/solutions/logging https://www.elastic.co/guide/en/beats/filebeat/curren ...

  2. mbr gpt

    超过2T硬盘的磁盘要用gpt格式,准确地说,应该是分区超过2T地硬盘要选用GPT模式. 做个小推广:程序员经常久坐,颈椎毛病比较多,特别推荐ventry颈椎保健枕

  3. HDU 4891 The Great Pan (字符串处理)

    题目链接:HDU 4891 The Great Pan 求一串字符有多少种不同的意思,当中关心'{','}'之间的'|'. 和'$','$'之间的空格,连续N个空格算N+1种. AC代码: #incl ...

  4. ZOJ 3213

    /* ZOJ 3213 好吧,看过那种括号表示法后,就崩溃了,实在受不了.情况复杂,写了两天,人也有点傻X了,只能放弃,转而用最小表示法. 最小表示法不难写: 1)首先,要承认路径上有格子不选的情况, ...

  5. 跨平台C++开源码的两种经常使用编译方式

    作者:朱金灿 来源:http://blog.csdn.net/clever101 跨平台C++开源代码为适应各种编译器的编译,採用了两种方式方面来适配.一种是makefile方式.以著名的空间数据格式 ...

  6. Android实战简易教程-第二十四枪(基于Baas的用户表查询功能实现!)

    接着上一篇,我们注冊了几个用户,用户表例如以下: 以下我们用ListView将表中数据显示出来吧. 首先看一下main.xml: <RelativeLayout xmlns:android=&q ...

  7. Mac关闭Iphone更新系统iTunes强制自动备份文件

    在任何时候iOS设备一连结苹果Mac电脑,电脑中的iTunes软件将自动对iOS设备进行同步和备份.虽然备份非常有用,当我们的iPhone/iPad出现问题的时候,可以直接恢复iPhone/iPad的 ...

  8. HDU 5536/ 2015长春区域 J.Chip Factory Trie

    Chip Factory Problem Description John is a manager of a CPU chip factory, the factory produces lots ...

  9. Linux下使用popen()执行shell命令【转】

    本文转载自:https://my.oschina.net/u/727148/blog/262987 函数原型: #include “stdio.h” FILE popen( const char co ...

  10. PCB Genesis原点坐标转换关系

    一.Genesis原点坐标转换关系: 1.读取Genesis坐标转换:   UI界面坐标 = 文件坐标 - 偏移值 2.写入Genesis坐标转换:   文件坐标 = UI界面坐标 + 偏移值 3.为 ...