20220313 3张表格 导出excel功能
This commit is contained in:
107
20220313_Excel/TempTask.WebEntry/ApiController/Dto/DtoInput.cs
Normal file
107
20220313_Excel/TempTask.WebEntry/ApiController/Dto/DtoInput.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static TempTask.WebEntry.Tools.NumZjHelper;
|
||||
|
||||
namespace TempTask.WebEntry.ApiController.Dto
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DtoInput
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NumZjConfig
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public List<NumZjExcel> numZjExcels { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NumZjExcel
|
||||
{
|
||||
/// <summary>
|
||||
/// sheet编号 从1开始
|
||||
/// </summary>
|
||||
public ExcelType excel_no { get; set; }
|
||||
/// <summary>
|
||||
/// sheet名称
|
||||
/// </summary>
|
||||
public string excel_name { get; set; }
|
||||
/// <summary>
|
||||
/// sheet集合
|
||||
/// </summary>
|
||||
public List<NumZjConfigSheet> sheets { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NumZjConfigSheet
|
||||
{
|
||||
/// <summary>
|
||||
/// sheet编号,从1开始
|
||||
/// </summary>
|
||||
public int sheet_no { get; set; }
|
||||
/// <summary>
|
||||
/// shee名称
|
||||
/// </summary>
|
||||
public string sheet_name { get; set; }
|
||||
/// <summary>
|
||||
/// 开始行数 Excel中行号
|
||||
/// </summary>
|
||||
public int start_row { get; set; }
|
||||
/// <summary>
|
||||
/// 空行数
|
||||
/// </summary>
|
||||
public int null_row_count { get; set; }
|
||||
/// <summary>
|
||||
/// 开始列字母, A B C
|
||||
/// </summary>
|
||||
public string start_cell { get; set; }
|
||||
/// <summary>
|
||||
/// 空列数
|
||||
/// </summary>
|
||||
public int null_cell_count { get; set; }
|
||||
/// <summary>
|
||||
/// 接口地址
|
||||
/// </summary>
|
||||
public string url { get; set; }
|
||||
/// <summary>
|
||||
/// 跳过行 集合 行留空
|
||||
/// </summary>
|
||||
public List<int> skip_rows { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NumZjDownloadInput
|
||||
{
|
||||
/// <summary>
|
||||
/// Excel类型 1是总表,2是城市更新,3是房地产业
|
||||
/// </summary>
|
||||
public int type { get; set; }
|
||||
/// <summary>
|
||||
/// 年
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int year { get; set; }
|
||||
/// <summary>
|
||||
/// 月
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int month { get; set; }
|
||||
/// <summary>
|
||||
/// 周
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int week { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Furion;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TempTask.WebEntry.ApiController.Dto;
|
||||
using TempTask.WebEntry.Tools;
|
||||
|
||||
namespace TempTask.WebEntry.ApiController
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NumZjController : IDynamicApiController
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<dynamic> Download([FromBody] NumZjDownloadInput numZjDownloadInput)
|
||||
{
|
||||
//var asd = ExcelHelper.ToColumnIndex("C");
|
||||
//return null;
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var configs = App.GetConfig<NumZjConfig>("NumZjConfig");
|
||||
var current = configs.numZjExcels.Find(a => (int)a.excel_no == numZjDownloadInput.type);
|
||||
//var sheet_names = new Dictionary<int, string> { { 4, "房地产业分行业(项目信息)" }, { 5, "分地区(项目信息)" } };
|
||||
var filepath = NumZjHelper.WriteTemplate(numZjDownloadInput.year, numZjDownloadInput.month, numZjDownloadInput.week, current.excel_no, current.sheets);
|
||||
return new FileStreamResult(new FileStream(filepath, FileMode.Open), "application/octet-stream") { FileDownloadName = current.excel_name };
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TempTask.WebEntry.ApiController
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
[DynamicApiController]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
var rng = new Random();
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateTime.Now.AddDays(index),
|
||||
TemperatureC = rng.Next(-20, 55),
|
||||
Summary = Summaries[rng.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user