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

56 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.IO;
using NPOI.XSSF.UserModel;
using PhxhSDK;
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);
_CreateSheet(newExcel, "cn2", strs);
_CreateSheet(newExcel, "en", strs);
_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);
var headers = new string[]
{
"Hash Code",
$"多语言值({sheetName})",
};
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++)
{
var row = newSheet.CreateRow(i);
var cellHash = row.CreateCell(0);
var cellValue = row.CreateCell(1);
var str = strs[i - 1];
var hash = HashUtils.SHA256(str);
cellHash.SetCellValue(hash);
cellValue.SetCellValue(str);
}
}
}
}