遇到问题的代码
void ReasExcel()
{
FileStream fileStream = File.Open(Application.streamingAssetsPath + "/BiaoGe.xlsx ", FileMode.Open, FileAccess.Read);
IExcelDataReader excelDataReader = ExcelReaderFactory.CreateOpenXmlReader(fileStream);
// 表格数据全部读取到result里
DataSet result = excelDataReader.AsDataSet();
fileStream.Close();
// 获取表格列数
int columns = result.Tables[0].Columns.Count;
// 获取表格行数
int rows = result.Tables[0].Rows.Count;
allWangGeInfo = new List<WangGeInfoClass>();
// 根据行列依次打印表格中的每个数据
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
// 获取表格中指定行指定列的数据
string value = result.Tables[0].Rows[i][j].ToString();
Debug.Log(i + "行" + j + "列:" + value);
}
}
}
问题详情:
在引擎里运行,可以正常读取表格内容,打包出来后无法读取,运行报错
错误日志地址:
C:\Users\用户名\AppData\LocalLow\DefaultCompany\项目打包程序名\Player.log.txt
Player.log记录内容:
NotSupportedException: Encoding 1252 data could not be found. Make sure you have correct international codeset assembly installed and enabled.
引擎版本:2019.3.8f1
解决办法:
1、找到引擎安装目录内的:I18N.CJK.dll,I18N.dll,I18N.West.dll
具体地址:unity安装目录\Unity\Editor\Data\MonoBleedingEdge\lib\mono\unityjit
注:此目录在unity2019.3和2019.4版本路径相同,其他版本未测试
2、导入项目资源文件夹内
重新build,即可正常运行并读取本地表格文件内容
参考内容:恶性bug解决,Encoding 1252 data could not be found. Make sure you have correct international codeset asse..._a554671102的博客-CSDN博客
Resolved - NotSupportedException: Encoding 1252 data could not be found (2020.2.3.f1) - Unity Forum
CodePage 1252 not supported - works in editor but not in standalone player - Unity Answers
Invalid IL Code in Build - Unity Answers