报错内容
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: length
ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputBuffer.ReadClearTextBuffer (System.Byte[] outBuffer, System.Int32 offset, System.Int32 length) (at <a758e8e2279140dd9f3bb220779a924c>:0)
ICSharpCode.SharpZipLib.Zip.ZipInputStream.BodyRead (System.Byte[] b, System.Int32 off, System.Int32 len) (at <a758e8e2279140dd9f3bb220779a924c>:0)
ICSharpCode.SharpZipLib.Zip.ZipInputStream.InitialRead (System.Byte[] destination, System.Int32 offset, System.Int32 count) (at <a758e8e2279140dd9f3bb220779a924c>:0)
ICSharpCode.SharpZipLib.Zip.ZipInputStream.Read (System.Byte[] destination, System.Int32 index, System.Int32 count) (at <a758e8e2279140dd9f3bb220779a924c>:0)
NPOI.OpenXml4Net.Util.ZipInputStreamZipEntrySource+FakeZipEntry..ctor (ICSharpCode.SharpZipLib.Zip.ZipEntry entry, ICSharpCode.SharpZipLib.Zip.ZipInputStream inp) (at <c6780665df34471e91913ce1f74d81b5>:0)
NPOI.OpenXml4Net.Util.ZipInputStreamZipEntrySource..ctor (ICSharpCode.SharpZipLib.Zip.ZipInputStream inp) (at <c6780665df34471e91913ce1f74d81b5>:0)
NPOI.OpenXml4Net.OPC.ZipPackage..ctor (System.IO.Stream in1, NPOI.OpenXml4Net.OPC.PackageAccess access) (at <c6780665df34471e91913ce1f74d81b5>:0)
NPOI.OpenXml4Net.OPC.OPCPackage.Open (System.IO.Stream in1) (at <c6780665df34471e91913ce1f74d81b5>:0)
NPOI.Util.PackageHelper.Open (System.IO.Stream is1) (at <08e1d243fed64b64963f43e2e9d81cff>:0)
NPOI.XSSF.UserModel.XSSFWorkbook..ctor (System.IO.Stream is1) (at <08e1d243fed64b64963f43e2e9d81cff>:0)
TextPrinter.LoadCharacterMapping () (at Assets/scripts/TextPrinter.cs:97)
代码
附上TextPrinter定位的代码
void LoadCharacterMapping() { string mappingFilePath = Path.Combine(Application.streamingAssetsPath, "characterMapping.xlsx"); if (File.Exists(mappingFilePath)) { using (FileStream stream = new FileStream(mappingFilePath, FileMode.Open, FileAccess.Read)) { IWorkbook workbook = new XSSFWorkbook(stream); //此处报错 ISheet sheet = workbook.GetSheetAt(0); for (int i = 1; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); if (row != null) { int id = (int)(row.GetCell(0)?.NumericCellValue ?? 0); string avatarName = row.GetCell(2)?.StringCellValue; if (!characterMapping.ContainsKey(id)) { characterMapping.Add(id, avatarName); } } } } } else { Debug.LogError($"未能找到角色映射Excel文件:{mappingFilePath}"); } }
问题分析
直接原因是xlsx表格内需要读取的string是中文,经过测试把表格内文字从英文变成中文就报错了。## 失败的尝试
把表格里的中文改回英文,报错没有消失。(失败)
在streamingAssetsPath新建表格并重命名。(失败)
解决
问题出现时使用NPOI版本为2.5.6*,在vs的NuGet里升级为2.6.2后解决。

ps:记得把升级后的sll添加到plugins里
报错问题本来都发csdn但刚才写完发现发布要强制绑定vx那还是发这边吧。。。
plugins参考:


浙公网安备 33010602011771号