上传下载附件方法
This commit is contained in:
parent
1d2f68b645
commit
c22aa88fe5
36
需求/上传.txt
Normal file
36
需求/上传.txt
Normal file
@ -0,0 +1,36 @@
|
||||
public async Task<IActionResult> FileSave()
|
||||
{
|
||||
var files = Request.Form.Files;
|
||||
long size = files.Sum(f => f.Length);
|
||||
string webRootPath = _hostingEnvironment.WebRootPath;
|
||||
string contentRootPath = _hostingEnvironment.ContentRootPath;
|
||||
|
||||
List<Tuple<string, string, string>> result = new List<Tuple<string, string, string>>();
|
||||
|
||||
foreach (var formFile in files)
|
||||
{
|
||||
if (formFile.Length > 0)
|
||||
{
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
|
||||
long fileSize = formFile.Length; //获得文件大小,以字节为单位
|
||||
string newFileName = formFile.FileName.Replace(fileExt, "") + '_' + System.Guid.NewGuid().ToString() + fileExt;//随机生成新的文件名
|
||||
|
||||
//物理路径
|
||||
var phyfilePath = $"{webRootPath}\\upload\\";
|
||||
|
||||
if (System.IO.Directory.Exists(phyfilePath) == false)//如果不存在就创建file文件夹
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(phyfilePath);
|
||||
}
|
||||
using (var stream = new FileStream(phyfilePath + newFileName, FileMode.Create))
|
||||
{
|
||||
await formFile.CopyToAsync(stream);
|
||||
}
|
||||
//前台访问路径
|
||||
var filePath = $"{Request.Host}/upload/{newFileName}";
|
||||
result.Add(Tuple.Create(formFile.FileName, fileExt, filePath));
|
||||
}
|
||||
}
|
||||
return Ok(new { files.Count, result });
|
||||
}
|
95
需求/下载.txt
Normal file
95
需求/下载.txt
Normal file
@ -0,0 +1,95 @@
|
||||
#region 年度考核互评(评价)模板下载
|
||||
public FileResult DownEvaluateTemplate()
|
||||
{
|
||||
string filePath = _hostingEnvironment.WebRootPath + "\\upload\\" + System.Guid.NewGuid().ToString() + ".xls";
|
||||
try
|
||||
{
|
||||
HSSFWorkbook workBook = new HSSFWorkbook();
|
||||
CreateAssessmentTemplateDto result = new CheckResultManagementAppService(_orgRepository, _tExemptExamEntity, _tCheckResultEntity, _tGroupDeclarationEntity).CreateAssessmentTemplate();
|
||||
var gList = _tGroupDeclarationEntity.GetAll().Where(s => s.IsDeleted == false && s.Year == DateTime.Now.Year).GroupBy(s => s.GroupTime);
|
||||
string sheetName = "";
|
||||
foreach (var rekey in gList)
|
||||
{
|
||||
var rekeyLsts = rekey.ToList();
|
||||
string sheet1 = rekeyLsts.Count() > 0 ? rekeyLsts[0].DeclareTypeName : "";
|
||||
sheetName = rekey.Key == null ? "未分组" : sheet1 + Convert.ToDateTime(rekey.Key).ToString("yyyy年MM月dd日HH时mm分ss秒");
|
||||
CreateEvaluateSheet(workBook, sheetName + "互评表", rekeyLsts, "互评表");
|
||||
}
|
||||
foreach (var rekey in gList)
|
||||
{
|
||||
var rekeyLsts = rekey.ToList();
|
||||
string sheet1 = rekeyLsts.Count() > 0 ? rekeyLsts[0].DeclareTypeName : "";
|
||||
sheetName = rekey.Key == null ? "未分组" : sheet1 + Convert.ToDateTime(rekey.Key).ToString("yyyy年MM月dd日HH时mm分ss秒");
|
||||
CreateEvaluateSheet(workBook, sheetName + "专家打分表", rekeyLsts, "专家打分表");
|
||||
}
|
||||
|
||||
|
||||
if (Directory.Exists(filePath))
|
||||
{
|
||||
Directory.Delete(filePath);
|
||||
}
|
||||
using (FileStream file = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
workBook.Write(file); //创建Excel文件。
|
||||
file.Close();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string msg = ex.Message;
|
||||
}
|
||||
return File(new FileStream(filePath, FileMode.Open), "application/octet-stream", (DateTime.Now.Year + "年互评表模板" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"));
|
||||
|
||||
}
|
||||
|
||||
private ISheet CreateEvaluateSheet(HSSFWorkbook workBook, string sheetName, List<TGroupDeclarationEntity> list, string ScoreTypeName)
|
||||
{
|
||||
ISheet sheet = workBook.CreateSheet(sheetName);
|
||||
IRow RowHead = sheet.CreateRow(0);
|
||||
string[] rows = new string[] { "序号", "单位名称", "互评分数" };
|
||||
#region 标题合并单元格
|
||||
ICellStyle cellStyle = workBook.CreateCellStyle();//声明样式
|
||||
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;//水平居中
|
||||
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//垂直居中
|
||||
IFont font = workBook.CreateFont();//声明字体
|
||||
font.Boldweight = (Int16)FontBoldWeight.Bold;//加粗
|
||||
font.FontHeightInPoints = 14;//字体大小
|
||||
cellStyle.SetFont(font);//加入单元格
|
||||
IRow row0 = sheet.CreateRow(0);//创建行
|
||||
row0.HeightInPoints = 20;//行高
|
||||
NPOI.SS.UserModel.ICell cell0 = row0.CreateCell(0);//创建单元格
|
||||
cell0.SetCellValue(ScoreTypeName);//赋值
|
||||
cell0.CellStyle = cellStyle;//设置样式
|
||||
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 2));//合并单元格(第几行,到第几行,第几列,到第几列)
|
||||
#endregion
|
||||
#region 表头
|
||||
IRow RowBody1 = sheet.CreateRow(1);
|
||||
|
||||
RowBody1.CreateCell(0).SetCellValue("序号");
|
||||
sheet.AutoSizeColumn(0);
|
||||
|
||||
RowBody1.CreateCell(1).SetCellValue("单位名称");
|
||||
sheet.AutoSizeColumn(1);
|
||||
|
||||
RowBody1.CreateCell(2).SetCellValue("互评分数");
|
||||
sheet.AutoSizeColumn(2);
|
||||
#endregion
|
||||
|
||||
for (int iRowIndex = 0; iRowIndex < list.Count; iRowIndex++)
|
||||
{
|
||||
IRow RowBody = sheet.CreateRow(iRowIndex + 2);
|
||||
|
||||
RowBody.CreateCell(0).SetCellValue((iRowIndex + 1).ToString());
|
||||
sheet.AutoSizeColumn(0);
|
||||
|
||||
RowBody.CreateCell(1).SetCellValue(list[iRowIndex].OrganizationName);
|
||||
sheet.AutoSizeColumn(1);
|
||||
|
||||
RowBody.CreateCell(2).SetCellValue("");
|
||||
sheet.AutoSizeColumn(2);
|
||||
}
|
||||
return sheet;
|
||||
|
||||
}
|
||||
#endregion
|
Loading…
x
Reference in New Issue
Block a user