43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using NPOI.XSSF.UserModel;
|
|
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();
|
|
var newSheet = newExcel.CreateSheet("Sheet1");
|
|
var headers = new string[]
|
|
{
|
|
"中文",
|
|
"英语",
|
|
"繁体中文",
|
|
};
|
|
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; i++)
|
|
{
|
|
var row = newSheet.CreateRow(i);
|
|
var cell = row.CreateCell(0);
|
|
cell.SetCellValue(strs[i]);
|
|
}
|
|
|
|
using (var fs = System.IO.File.OpenWrite(filePath))
|
|
{
|
|
newExcel.Write(fs);
|
|
}
|
|
}
|
|
}
|
|
}
|