添加 共赴宁波之春 报名网页

This commit is contained in:
范露尧
2023-03-09 22:16:03 +08:00
parent 21dd025ab8
commit 5755e9d9b0
44 changed files with 1386 additions and 534 deletions

View File

@@ -11,6 +11,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Vote.Services.Dto;
using Vote.Services.Entities;
namespace Vote.Services.Tools
{
@@ -208,5 +209,63 @@ namespace Vote.Services.Tools
throw Oops.Oh("文件被占用,请检查文件模板");
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string WriteExcelNingBoZhiChun(List<nbzc_person> data)
{
try
{
string template_name = "共赴宁波之春模板.xlsx";
string excelFilePath = $"{App.WebHostEnvironment.WebRootPath}\\ExcelTemplate\\{template_name}";
string outputPath = string.Empty;
if (!string.IsNullOrEmpty(excelFilePath))
{
using (FileStream excelFileStream = System.IO.File.OpenRead(excelFilePath))
{
bool isCompatible = ExcelHelper.GetIsCompatible(excelFilePath);
IWorkbook workbook = ExcelHelper.CreateWorkbook(isCompatible, excelFileStream);
ISheet sheet = null;
sheet = workbook.GetSheetAt(0);
//从第几行开始 , 比如 行号是4 , 就写3
var startRowIndex = 1;
for (int i = 0; i < data.Count; i++)
{
var c_rowindex = startRowIndex + i;
var row = sheet.CreateRow(c_rowindex);
int cell_start_index = 0;
row.CreateCell(cell_start_index).SetCellValue(data[i].CreatedTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
row.CreateCell(cell_start_index + 1).SetCellValue(data[i].name);
row.CreateCell(cell_start_index + 2).SetCellValue(data[i].phone);
row.CreateCell(cell_start_index + 3).SetCellValue(data[i].weixin_number);
row.CreateCell(cell_start_index + 4).SetCellValue(data[i].cardno);
row.CreateCell(cell_start_index + 5).SetCellValue(data[i].hangye);
row.CreateCell(cell_start_index + 6).SetCellValue(data[i].date);
row.CreateCell(cell_start_index + 7).SetCellValue(data[i].line);
row.CreateCell(cell_start_index + 8).SetCellValue(data[i].address);
}
var file = new FileInfo(excelFilePath);
var savePath = file.DirectoryName + "\\OutPut\\";
if (!Directory.Exists(savePath))
Directory.CreateDirectory(savePath);
outputPath = savePath + DateTime.Now.ToString("yyyyMMddHHmmsss") + "-" + template_name;
using (var filess = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
workbook.Write(filess);
}
}
}
return outputPath;
}
catch (System.IO.IOException ioex)
{
throw Oops.Oh("文件被占用,请检查文件模板");
}
}
}
}