NLDClient-yudde/ProjectNLD/Assets/Editor/Story/Utils/ExcelWriter.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2023-10-24 14:02:34 +08:00
using System.Collections.Generic;
using System.IO;
using NPOI.XSSF.UserModel;
2026-01-13 13:20:29 +08:00
using PhxhSDK;
2023-10-24 14:02:34 +08:00
namespace Gameplay.Story.Cmp.Utils
{
public static class ExcelWriter
{
public static void WriteToExcel(string filePath, List<string> strs)
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
var newExcel = new XSSFWorkbook();
_CreateSheet(newExcel, "cn", strs);
2024-08-05 19:20:30 +08:00
_CreateSheet(newExcel, "cn2", strs);
_CreateSheet(newExcel, "en", strs);
2024-08-05 19:20:30 +08:00
_CreateSheet(newExcel, "tw", strs);
using (var fs = System.IO.File.OpenWrite(filePath))
{
newExcel.Write(fs);
}
}
private static void _CreateSheet(XSSFWorkbook newExcel, string sheetName, List<string> strs)
{
var newSheet = newExcel.CreateSheet(sheetName);
2023-10-24 14:02:34 +08:00
var headers = new string[]
{
"Hash Code",
$"多语言值({sheetName})",
2023-10-24 14:02:34 +08:00
};
var headerRow = newSheet.CreateRow(0);
for (var i = 0; i < headers.Length; i++)
{
var cell = headerRow.CreateCell(i);
cell.SetCellValue(headers[i]);
}
for (var i = 1; i < strs.Count + 1; i++)
2023-10-24 14:02:34 +08:00
{
var row = newSheet.CreateRow(i);
var cellHash = row.CreateCell(0);
var cellValue = row.CreateCell(1);
var str = strs[i - 1];
2026-01-13 13:20:29 +08:00
var hash = HashUtils.SHA256(str);
cellHash.SetCellValue(hash);
cellValue.SetCellValue(str);
2023-10-24 14:02:34 +08:00
}
}
}
}