如何使excel在CSV文件中解释汉字

时间:2016-03-14 22:04:23

标签: excel shell csv sendmail

我从包含中文字符的unix shell脚本发送报告。

当我在文本编辑器中打开CSV报告时,我会看到中文字符,但是当我在Excel中打开CSV报告文件时,我看不到中文字符,但有些胡言乱语。

我如何"告诉" excel该文件包含中文字符集?

以下是发送邮件并附加CSV文件的代码。

send_mail() {

v_mailpart="ZZ_/afg6432dfgkl.94531q"
echo "Mail to be sent to $RPT_SEND_TO"
echo "To: $RPT_SEND_TO
Subject: Blah Report as of $report_date_format;
Content-Type: multipart/mixed; boundary=\"$v_mailpart\"
MIME-Version: 1.0

This is a multi-part message in MIME format.
--$v_mailpart
Content-Type: text/html
Content-Disposition: inline

<html><body><p>Hi All,<p>Please find attached, the daily report <p>Thanks,
<br/>Blah Team</br/><br/><br/></p><p>NOTE: This is an auto-generated email. Do not reply to it. Please send an email to blah-group@mycompany.com in
 case of any issues.<p></body></html>

--$v_mailpart
Content-Transfer-Encoding:UTF-8;
Content-Type: text/plain;charset=\"UTF-8\";
Content-Disposition: attachment; filename=blah-report.csv
`cat $spool_file5`" | /usr/sbin/sendmail -t
}

1 个答案:

答案 0 :(得分:1)

这是一个编码问题。一个简单的解决方法是使用谷歌表打开文件并从谷歌表保存为csv。

Windows中文操作系统使用GBK作为默认中文编码。您应该下载excel的中文并通过选项设置编码。

所以你应该把它编码为GBK或GB18130

  • (1)下载Open Office(免费安装快速,有更高版本 文件大小比Ubuntu中的Cals)。

  • (2)检测您的CSV编码。只是 使用Open office打开你的csv并选择一种编码方法 显示你的汉字。

  • (3)将您的csv保存到正确的位置 根据您的操作系统编码。默认Windows编码 中文为GBK,Ubuntu为UTF8。