public void ExportDoctorLearn(RowNumModel <DoctorLearnViewModel> rowNum)
        {
            HttpContext curContext = HttpContext.Current;
            var         ret        = _iADDoctorService.GetDoctorLearn(rowNum, true);

            if (ret.Success)
            {
                var _filePath             = HostingEnvironment.MapPath("/ExcelTemplate/" + "学习时间模板.xlsx");
                var data                  = ret.Result as List <DoctorLearnViewModel>;
                List <DoctorLearnDto> dto = new List <DoctorLearnDto>();
                foreach (var item in data)
                {
                    dto.Add(new DoctorLearnDto
                    {
                        DoctorName       = item.DoctorName,
                        Title            = item.Title,
                        HospitalName     = item.HospitalName,
                        DepartmentName   = item.DepartmentName,
                        DocLearnTime     = KBS.Tool.SecondsToDateTime(item.DocLearnTime.GetValueOrDefault()),
                        PodcastLearnTime = KBS.Tool.SecondsToDateTime(item.PodcastLearnTime.GetValueOrDefault()),
                        VideoLearnTime   = KBS.Tool.SecondsToDateTime(item.VideoLearnTime.GetValueOrDefault()),
                        MeetCount        = item.MeetCount,
                        BroadcastTime    = KBS.Tool.SecondsToDateTime(item.BroadcastTime.GetValueOrDefault()),
                        GuidVistTime     = KBS.Tool.SecondsToDateTime(item.GuidVistTime.GetValueOrDefault()),
                        MedicineVistTime = KBS.Tool.SecondsToDateTime(item.MedicineVistTime.GetValueOrDefault()),
                        BookVisitTime    = KBS.Tool.SecondsToDateTime(item.BookVisitTime.GetValueOrDefault()),
                        DocTags          = string.Join(",", item.DocTags),
                    });
                }

                var bytes = AsposeExcelTool.ExportTemplate(_filePath, "H", "医生学习时间", dto);

                string fileName = DateTime.Now.ToString("yyyyMMssff");

                curContext.Response.Clear();
                curContext.Response.Buffer  = true;
                curContext.Response.Charset = "UTF-8";
                curContext.Response.AddHeader("content-disposition", $"attachment; filename={fileName}.xlsx");
                curContext.Response.ContentEncoding = Encoding.UTF8;  //必须写,否则会有乱码
                curContext.Response.ContentType     = "application/octet-stream";
                curContext.Response.AddHeader("Content-Length", bytes.Length.ToString());
                curContext.Response.OutputStream.Write(bytes, 0, bytes.Length);
                curContext.Response.Flush();
                curContext.Response.Close();
            }


            //string path = HostingEnvironment.MapPath("/Upload/Export");

            //if (!Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}
            //FileStream fs = new FileStream(path + @"/" + fileName, FileMode.Create);
            //fs.Write(excell, 0, excell.Length);
            //fs.Dispose();
            //string _host = ConfigurationManager.AppSettings["HostUrl"];
            //return _host + "/Upload/Export/" + fileName;
        }
Esempio n. 2
0
        public void Test1()
        {
            var d = new RowNumModel <DoctorLearnViewModel>();

            d.SearchParams = new DoctorLearnViewModel();
            var ret       = _iADDoctorService.GetDoctorLearn(d, true);
            var _filePath = HostingEnvironment.MapPath("/ExcelTemplate/" + "学习时间模板.xlsx");
            var bytes     = AsposeExcelTool.ExportTemplate(_filePath, "H", "医生学习时间", ret.Result);

            HttpContext curContext = HttpContext.Current;

            curContext.Response.Clear();
            curContext.Response.Buffer  = true;
            curContext.Response.Charset = "UTF-8";
            curContext.Response.AddHeader("content-disposition", "attachment; filename=XiuJiaMonthlyHandel.xlsx");
            curContext.Response.ContentEncoding = Encoding.UTF8;  //必须写,否则会有乱码
            curContext.Response.ContentType     = "application/octet-stream";
            curContext.Response.AddHeader("Content-Length", bytes.Length.ToString());
            curContext.Response.OutputStream.Write(bytes, 0, bytes.Length);
            curContext.Response.Flush();
            curContext.Response.Close();
        }
Esempio n. 3
0
    public static DataTable readExcel(string filetoread, string title)
    {
#if !ASPOSE_READ && ASPOSE
        OdbcConnection oCon  = null;
        OdbcDataReader rData = null;
        try
        {
            DataTable dtYourData = new DataTable();
            string    con        = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dbq=" + filetoread + ";";
            string    yourQuery  = "SELECT * FROM [" + title + "$]";
            oCon = new OdbcConnection(con);
            OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon);
            oCon.Open();
            rData = oCmd.ExecuteReader();
            dtYourData.Load(rData);
            rData.Close();
            oCon.Close();
            return(dtYourData);
        }
        catch (System.Exception ex)
        {
            if (null != rData)
            {
                rData.Close();
            }
            if (null != oCon)
            {
                oCon.Close();
            }
            Debug.LogError(filetoread + "读取错误" + ex.Message);
            return(null);
        }
#else
        Debug.Log("readExcel");
        return(AsposeExcelTool.readExcel(filetoread, title));
#endif
    }