.netcore 操作aspose.words导出pdf

本文主要讲述了作者在使用ExpReport类生成包含温湿度曲线图的PDF报告过程中遇到的问题,如控制图例位置和隐藏x轴标签,以及如何设置图表样式和数据展示。

个人重点关注的是生成曲线图的部分,浪费了我很多时间

chart.Legend.Position = LegendPosition.Top; 

控制图形的显示位置,这个地方好像必须要选一个位置,否则会内容显示不全,我开始用的LegendPosition.None,他就显示不了那几条线的颜色和名称说明文字。为了搞出这个效果浪费了我一天时间。

 

xAxis.Hidden = true;//隐藏x轴标签

public class ExpReport
{
    //IWebHostEnvironment _webHostEnvironment;

    //public ExpReport(IWebHostEnvironment webHostEnvironment)
    //{
    //    _webHostEnvironment = webHostEnvironment;
    //}
 
    public static string ReportChartPdf(List<TahmCJ_wdDto> Listdto, ExpReportDto ReportDto)
    {
        try
        {
            IConfiguration myconfiguration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();

            Document doc = new Document();

            DocumentBuilder builder = new DocumentBuilder(doc);
            
            builder.PageSetup.Orientation = Orientation.Portrait;

            //var parentPath = AppContext.BaseDirectory.ToString()+@"\wwwroot\";
            var parentPath = Path.Combine(IOCProvider.GetService<IHostEnvironment>().ContentRootPath,"wwwroot"); 
            //
            string strReportFileUrl = myconfiguration["Report:ReportFileUrl"].ToString();
            string dateDir = DateTime.Now.Date.ToString("yyyyMMdd");
            string saveFileStr = "温湿度曲线报表_" + DateTime.Now.Date.ToString("yyyyMMddHHmmss") + new Random().Next(1, 1000).ToString() + ".docx";
            // 你用path

             
            string strSavePath = Path.Combine(parentPath, strReportFileUrl, dateDir);
            FolderAndFile.FolderCreate(strSavePath);

            strSavePath = Path.Combine(strSavePath, saveFileStr);  


            string strCompanyLogo = myconfiguration["Report:CompanyLogo"].ToString();  
            string Logpicurl =  Path.Combine(parentPath, strCompanyLogo);


            string ComLogoWidth = myconfiguration["Report:CompanyLogoWidth"].ToString();
            string ComLogoHeight = myconfiguration["Report:CompanyLogoHeight"].ToString();
            //Logpicurl = FolderAndFile.SetImageSize(float.Parse(ComLogoWidth), float.Parse(ComLogoHeight), Logpicurl, "");


            string RepImageWidth = myconfiguration["Report:ReportImageWidth"].ToString();
            string RepImageHeight = myconfiguration["Report:ReportImageHeight"].ToString();
       

            
            ReportDto.LogoPicUrl = Logpicurl;
            ReportDto.aveWD = Math.Round((decimal)Listdto.Average(x => x.wd1), 1).ToString("0.0");
            ReportDto.aveSD = Math.Round((decimal)Listdto.Average(x => x.sd1), 1).ToString("0.0");
            ReportDto.highWD = Listdto.Max(x => (decimal)x.wd1).ToString("0.0");
            ReportDto.highSD = Listdto.Max(x => (decimal)x.sd1).ToString("0.0");
            ReportDto.lowWD = Listdto.Min(x => (decimal)x.wd1).ToString("0.0");
            ReportDto.lowSD = Listdto.Min(x => (decimal)x.sd1).ToString("0.0");
            ReportDto.WDLimit = ((decimal)Listdto[0].wdlowLimit).ToString("0.0") + "--" + ((decimal)Listdto[0].wdHghLimit).ToString("0.0");
            ReportDto.SDLimit = ((decimal)Listdto[0].sdLowLimit).ToString("0.0") + "--" + ((decimal)Listdto[0].sdHghLimit).ToString("0.0");
            var alarmList = Listdto.Select(x => new { x.wd1, x.sd1, x.dt }).Where(x => x.wd1 < ((decimal)Listdto[0].wdlowLimit) || x.wd1 > ((decimal)Listdto[0].wdHghLimit)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值