文件是通过openoffice和pdf2html配合转换的,但excel文件却没有这样处理,而是用了网上开源的java代码实现的,架构看了代码后发现在转换excel文件的时候这段代码读取了宿主系统的语言配置,所以确定了问题的原因就是系统字符编码设置。

解决方法

查看系统字符编码没问题(注意前三行),看来字符集设置正确。排查一下前三行的问题,网上说是没有安装中文字符集导致的
[root@4273aa460888 opt]# locale locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL=
我们看一本机都安装了哪些字符集,我擦,果然没有安装中文字符集.....(没有安装就算你设置了也没用)
[root@4273aa460888 opt]# locale -a locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_COLLATE to default locale: No such file or directory C POSIX en_US.utf8
再看一下/etc/locale.conf的内容,干,还是英文字符集......
[root@4273aa460888 opt]# cat /etc/locale.conf LANG="en_US.UTF-8"
好,我们接下来安装一下中文字符集
删除yum.conf文件中的语言配置
sed -i '13'd /etc/yum.conf
安装字体和glibc
yum install -y kde-l10n-Chinese glibc-common
我们再看一下,终于有了
[root@35b0e9b16498 opt]# locale -a|grep zh zh_CN zh_CN.gb18030 zh_CN.gb2312 zh_CN.gbk zh_CN.utf8 zh_HK zh_HK.big5hkscs zh_HK.utf8 zh_SG zh_SG.gb2312 zh_SG.gbk zh_SG.utf8 zh_TW zh_TW.big5 zh_TW.euctw zh_TW.utf8
我们再修改一下/etc/locale.conf文件
echo -e 'export LANG="zh_CN.UTF-8"\nexport LC_ALL="zh_CN.UTF-8"' > /etc/locale.conf source /etc/locale.conf
我们再看一下字符编码,好了,没有报错,且一切正常。
[root@35b0e9b16498 opt]# locale LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL=zh_CN.UTF-8