示例#1
0
        /// <summary>
        ///     生成模板
        /// </summary>
        /// <returns></returns>
        public async Task <ExportFileInfo> GenerateTemplateFileAsync <T>(string filePath) where T : class, new()
        {
            FileUtil.DeleteFile(filePath);
            var result = await ExcelImporter.GenerateTemplate <T>(filePath);

            return(result);
        }
        public IActionResult GetGenerateCameraImportTemplate()
        {
            IImporter Importer = new ExcelImporter();
            var       pathname = $"{System.AppDomain.CurrentDomain.BaseDirectory}Basics\\InExcel.xlsx";

            var requst = Importer.GenerateTemplate <ImportCameraDto>(pathname);

            var    stream     = System.IO.File.OpenRead(pathname);
            string fileExt    = Path.GetExtension(pathname);
            var    provider   = new FileExtensionContentTypeProvider();
            var    meni       = provider.Mappings[fileExt];
            var    returnFile = File(stream, meni, Path.GetFileName(pathname));

            return(returnFile);
        }
示例#3
0
        static async Task Main(string[] args)
        {
            IImporter importer = new ExcelImporter();

            var filePath = Path.Combine(Directory.GetCurrentDirectory(), "tmp.xlsx");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var result = await importer.GenerateTemplate <ImportStudentDTO>(filePath);

            Console.WriteLine(result.FileName);
        }
示例#4
0
 /// <summary>
 ///     根据模板Dto生成导入Excel模板文件
 /// </summary>
 /// <param name="filePath">保存路径</param>
 /// <returns></returns>
 public async Task GenerateImportTemplateAsync <T>(string filePath = "") where T : class, new()
 {
     FileUtil.DeleteFile(filePath);
     await ExcelImporter.GenerateTemplate <T>(filePath);
 }