bazi

Unity NPOI ICSharpCode.SharpZipLib报错

unity版本2021.3.17f1

NPOI版本:2.21

报错原因:

使用NPOI进行Excel导入时ICSharpCode.SharpZipLib版本冲突,无法加载 ICSharpCode.SharpZipLib 库

解决办法:项目首页 - ICSharpCode.SharpZipLib资源文件下载:ICSharpCode.SharpZipLib 资源文件下载本仓库提供 ICSharpCode.SharpZipLib 的资源文件下载,包含两个版本:0.86.0.518 和 0.84.0.0 - GitCode

 

导出EXCEL表代码



try
{ var dir = Path.GetDirectoryName(filepath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (!File.Exists(filepath)) { using (FileStream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write)) { var wb = new XSSFWorkbook(); wb.Write(stream); wb.Close(); stream.Close(); } } workebook = new XSSFWorkbook(); ISheet sheet = workebook.CreateSheet("数据"); //设置表头 var row1 = sheet.CreateRow(0); row1.CreateCell(0).SetCellValue("id"); row1.CreateCell(1).SetCellValue("type"); row1.CreateCell(2).SetCellValue("name"); row1.CreateCell(3).SetCellValue("locklv"); row1.CreateCell(4).SetCellValue("position1"); row1.CreateCell(5).SetCellValue("position2"); row1.CreateCell(6).SetCellValue("hierarchy"); var row2 = sheet.CreateRow(1); row2.CreateCell(0).SetCellValue("int"); row2.CreateCell(1).SetCellValue("int"); row2.CreateCell(2).SetCellValue("string"); row2.CreateCell(3).SetCellValue("int"); row2.CreateCell(4).SetCellValue("int"); row2.CreateCell(5).SetCellValue("int"); row2.CreateCell(6).SetCellValue("int"); var row3 = sheet.CreateRow(2); row3.CreateCell(0).SetCellValue("唯一ID"); row3.CreateCell(1).SetCellValue("类型"); row3.CreateCell(2).SetCellValue("资源名称"); row3.CreateCell(3).SetCellValue("解锁等级"); row3.CreateCell(4).SetCellValue("位置1"); row3.CreateCell(5).SetCellValue("位置2"); row3.CreateCell(6).SetCellValue("层级"); //数据 int rowIndex = 3; for (int i = 0; i < listInfo.Count; i++) { var row = sheet.CreateRow(rowIndex++); row.CreateCell(0).SetCellValue(listInfo[i].id); row.CreateCell(1).SetCellValue(listInfo[i].type); row.CreateCell(2).SetCellValue(listInfo[i].TextureName); row.CreateCell(3).SetCellValue(listInfo[i].locklevel); row.CreateCell(4).SetCellValue(listInfo[i].x); row.CreateCell(5).SetCellValue(listInfo[i].y); row.CreateCell(6).SetCellValue(listInfo[i].z); } //自适应 sheet.AutoSizeColumn(0); sheet.AutoSizeColumn(1); using (fs = new FileStream(filepath, FileMode.Create, FileAccess.Write)) { workebook.Write(fs); } workebook.Close(); workebook = null; } catch (Exception ex) { Debug.Log($"发生异常:"+ex.Message); } finally { if (workebook != null) { workebook.Close(); } if (fs!=null) { fs.Close(); } }

 

posted on 2024-12-31 11:13  芭梓  阅读(143)  评论(0)    收藏  举报

导航