.netcore 操作aspose.words导出pdf

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

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";// 你用pathstring 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) || x.sd1 < ((decimal)Listdto[0].sdLowLimit) || x.sd1 > ((decimal)Listdto[0].sdHghLimit));ReportDto.alarmCount = alarmList.Count().ToString();var alarmArry = alarmList.Take(20).Select(x => new { x.wd1, x.dt }.ToString()).ToArray();alarmArry = (from a in alarmListselect "温度:" + a.wd1 + " 湿度:" + a.sd1 + " 时间:" + a.dt.ToString("yyyy-MM-dd HH:mm:ss") + "").Take(20).ToArray();ReportDto.alarmData = string.Join(" , ", alarmArry);builder.InsertImage(Logpicurl, RelativeHorizontalPosition.Margin, 1, RelativeVerticalPosition.Margin, 1, double.Parse(ComLogoWidth), double.Parse(ComLogoHeight), WrapType.Square);for (int i = 0; i < 10; i++){builder.InsertBreak(BreakType.LineBreak); }for (int i = 0; i < 3; i++){builder.InsertBreak(BreakType.LineBreak);}ParagraphFormat paragraphFormat = builder.ParagraphFormat;paragraphFormat.Alignment = ParagraphAlignment.Center; builder.Font.Size = 18;builder.Font.Name = "Arial";builder.Font.Bold = false;//paragraphFormat.FirstLineIndent = 8;//paragraphFormat.Alignment = ParagraphAlignment.Center;//paragraphFormat.KeepTogether = true;//builder.Writeln($"时间区间:{ReportDto.StartTime} 到 {ReportDto.EndTime}");builder.CellFormat.ClearFormatting(); for (int i = 0; i < 5; i++){builder.InsertBreak(BreakType.LineBreak); }builder.Font.Size = 35;builder.Font.Bold = true;builder.Writeln("温湿度报表");builder.Font.Size = 20;builder.Font.Bold = false;builder.Writeln($"报告人:{ReportDto.ReportMan} 制表人:{ReportDto.CreateManBottom}");builder.Writeln($"时间:{ReportDto.ReportTime}");builder.InsertBreak(BreakType.SectionBreakNewPage); builder.PageSetup.Orientation = Orientation.Landscape; builder.StartTable(); builder.CellFormat.ClearFormatting(); builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.CellFormat.Width = builder.PageSetup.PageWidth - 140; builder.Font.Size = 15;builder.Font.Name = "Arial";builder.Font.Bold = true;builder.InsertCell();builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;builder.Write($"{ReportDto.eqno}--温湿度\r\n");builder.EndRow();builder.InsertCell();builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;builder.Font.Size = 15;builder.Font.Name = "Arial";builder.Font.Bold = true;builder.Writeln("监测对象描述");builder.Write("\r\n");builder.Font.Name = "宋体";builder.Font.Bold = false;builder.Writeln($"\t监测对象名称:{ReportDto.Testname}");builder.Write("\r\n");builder.Writeln($"\t监测条件:{ReportDto.Condition}");builder.Write("\r\n");builder.Writeln($"\t监测对象类型:{ReportDto.Testboxtype}");builder.Write("\r\n");builder.Writeln($"\t监测对象编号:{ReportDto.Testboxno}");builder.Write("\r\n");builder.Writeln($"\t监测对象批号:{ReportDto.Pihao}");builder.Write("\r\n");//builder.EndRow();//builder.InsertCell();builder.Font.Name = "Arial";builder.Font.Bold = true;builder.Writeln("各项统计");builder.Write("\r\n");builder.Font.Name = "宋体";builder.Font.Bold = false;builder.Writeln($"\t平均温度:{ReportDto.aveWD}  最高温度:{ReportDto.highWD}   最低温度:{ReportDto.lowWD}  设定门限:{ReportDto.WDLimit}");builder.Write("\r\n");builder.Writeln($"\t平均湿度:{ReportDto.aveSD}  最高湿度:{ReportDto.highSD}   最低湿度:{ReportDto.lowSD}  设定门限:{ReportDto.SDLimit}");builder.Write("\r\n");builder.Writeln($"\t温度告警总数:{ReportDto.alarmCount}");builder.Write("\r\n");builder.Write("\r\n"); builder.EndRow();builder.InsertCell();paragraphFormat = builder.ParagraphFormat;paragraphFormat.Alignment = ParagraphAlignment.Center;//居中builder.Font.Size = 15;builder.Font.Name = "Arial";builder.Font.Bold = true;builder.Writeln($"\t时间区间:{ReportDto.StartTime} 到 {ReportDto.EndTime}");builder.Write("\r\n");//builder.Writeln("温度曲线图(横轴:时间;纵轴:温度、湿度)");Shape shape = builder.InsertChart(ChartType.Line, double.Parse(RepImageWidth) + 80, double.Parse(RepImageHeight)+100);shape.FillColor = Color.Transparent;//背景透明var chart = shape.Chart;chart.Title.Text = "温湿度曲线图(横轴:时间;纵轴:温度、湿度)";chart.Title.Show = true; chart.Series.Clear();chart.Legend.Position = LegendPosition.Top;var dataTimeList = Listdto.Select(x => x.dt.ToString("yyyy-MM-dd HH:mm:ss")).ToList();var dataList = Listdto.Select(x => Convert.ToDouble(x.wd1)).ToList();var dataListwdlowlimit = Listdto.Select(x => Convert.ToDouble(x.wdlowLimit)).ToList();var dataListwdhghlimit = Listdto.Select(x => Convert.ToDouble(x.wdHghLimit)).ToList();var series_wd = chart.Series.Add("温度",dataTimeList.ToArray(),dataList.ToArray());//series_wd.Name = "温度";series_wd.Marker.Symbol = MarkerSymbol.Circle;series_wd.Marker.Size = 3;//series_wd. = "";//series = chart.Series.Add("wd1",// dataTimeList.ToArray(),// dataList.ToArray());var series_wdlow = chart.Series.Add("温度下限",dataTimeList.ToArray(),dataListwdlowlimit.ToArray());//series_wdlow.Name = "温度下限";series_wdlow.Marker.Symbol = MarkerSymbol.Circle;series_wdlow.Marker.Size = 2;var series_wdhgh = chart.Series.Add("温度上限",dataTimeList.ToArray(),dataListwdhghlimit.ToArray());//series_wdhgh.Name = "温度上限";series_wdhgh.Marker.Symbol = MarkerSymbol.Circle;series_wdhgh.Marker.Size =2;//dataTimeList = Listdto.Select(x => x.dt.ToString("yyyy-MM-dd HH:mm:ss")).ToList();dataList = Listdto.Select(x => Convert.ToDouble(x.sd1)).ToList();var dataListsdlowlimit = Listdto.Select(x => Convert.ToDouble(x.sdLowLimit)).ToList();var dataListsdhghlimit = Listdto.Select(x => Convert.ToDouble(x.sdHghLimit)).ToList();var series_sd = chart.Series.Add("sd1",dataTimeList.ToArray(),dataList.ToArray());series_sd.Name = "湿度";series_sd.Marker.Symbol = MarkerSymbol.Circle;series_sd.Marker.Size = 3;var series_sdlow=chart.Series.Add("sdlowlimit",dataTimeList.ToArray(),dataListsdlowlimit.ToArray());series_sdlow.Name = "湿度下限";series_sdlow.Marker.Symbol = MarkerSymbol.Circle;series_sdlow.Marker.Size = 2;var series_sdhgh = chart.Series.Add("sdhghlimit",dataTimeList.ToArray(),dataListsdhghlimit.ToArray());series_sdhgh.Name = "湿度上限";series_sdhgh.Marker.Symbol= MarkerSymbol.Circle;series_sdhgh.Marker.Size = 2;ChartDataPointCollection dataPoints = series.DataPoints;默认给每个数据点样式series.InvertIfNegative = true;//chart.Series[0].Marker.Symbol = MarkerSymbol.Circle;//chart.Series[0].Marker.Size = 5;//chart.Series[0].Name = "温度曲线图";ChartAxis xAxis = chart.AxisX;xAxis.TickLabelSpacingIsAuto = true;xAxis.Hidden = true;//隐藏x轴标签ChartAxis yAxis = chart.AxisY;yAxis.TickLabelPosition = AxisTickLabelPosition.NextToAxis;//坐标轴位置paragraphFormat = builder.ParagraphFormat;paragraphFormat.Alignment = ParagraphAlignment.Center;//居中builder.Font.Size = 12;builder.Font.Name = "Arial";builder.Font.Bold = true;builder.Font.Color = Color.Red;builder.Writeln("本图形时间顺序是从左到右");builder.EndRow();//builder.InsertCell();//paragraphFormat = builder.ParagraphFormat;//paragraphFormat.Alignment = ParagraphAlignment.Center;//居中//builder.Font.ClearFormatting();//builder.Font.Size = 15;//builder.Font.Name = "Arial";//builder.Font.Bold = true;//builder.Writeln("绘制湿度曲线(横轴:时间;纵轴:湿度)");//shape = builder.InsertChart(ChartType.Line, double.Parse(RepImageWidth) + 80, double.Parse(RepImageHeight));//chart = shape.Chart;//shape.FillColor = Color.Transparent;//chart.Title.Text = "绘制湿度曲线(横轴:时间;纵轴:湿度)";//chart.Title.Show = false;//chart.Series.Clear();//chart.Legend.Position = LegendPosition.None;//dataTimeList = Listdto.Select(x => x.dt.ToString("yyyy-MM-dd HH:mm:ss")).ToList();//dataList = Listdto.Select(x => Convert.ToDouble(x.sd1)).ToList();//var dataListsdlowlimit = Listdto.Select(x => Convert.ToDouble(x.sdLowLimit)).ToList();//var dataListsdhghlimit = Listdto.Select(x => Convert.ToDouble(x.sdHghLimit)).ToList();//series = chart.Series.Add("sd1",//   dataTimeList.ToArray(),//   dataList.ToArray());//chart.Series.Add("sdlowlimit",//   dataTimeList.ToArray(),//   dataListsdlowlimit.ToArray());//chart.Series.Add("sdhghlimit",//   dataTimeList.ToArray(),//   dataListsdhghlimit.ToArray());//chart.Series[0].Marker.Symbol = MarkerSymbol.Circle;//chart.Series[0].Marker.Size = 5;//chart.Series[0].Name = "  ";//chart.Series[0].DataLabels.Clear();//xAxis = chart.AxisX;//xAxis.Hidden = true;//yAxis = chart.AxisY;//yAxis.TickLabelPosition = AxisTickLabelPosition.NextToAxis;//paragraphFormat = builder.ParagraphFormat;//paragraphFormat.Alignment = ParagraphAlignment.Center;//居中//builder.Font.Size = 12;//builder.Font.Name = "Arial";//builder.Font.Bold = true;//builder.Font.Color = Color.Red;//builder.Writeln("本图形时间顺序是从左到右");//builder.EndRow();builder.InsertCell();builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;builder.Font.ClearFormatting();builder.Font.Name = "Arial";builder.Font.Size = 15;builder.Font.Bold = true;builder.Writeln($"最近20组告警数据");builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//居左builder.Font.Name = "宋体";builder.Font.Bold = false;builder.Writeln($"{ReportDto.alarmData}");for (int i = 0; i < 2; i++){builder.InsertBreak(BreakType.LineBreak);// }builder.EndRow();builder.InsertCell();builder.Font.Name = "Arial";builder.Font.Size = 15;builder.Font.Bold = true;builder.Writeln($"制表人:{ReportDto.CreateMan}");builder.Writeln($"时   间 :{ReportDto.ReportTime}");builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;builder.Writeln($"签名:\t\t\t");builder.EndRow();builder.EndTable();var docDir = Regex.Split(strSavePath, ".docx", RegexOptions.IgnoreCase)[0] + ".docx";doc.Save(docDir, SaveFormat.Docx);Document doct = new Document(docDir);var pdfDir = Regex.Split(strSavePath, ".docx", RegexOptions.IgnoreCase)[0] + ".pdf";PdfSaveOptions saveOption = new PdfSaveOptions();saveOption.SaveFormat = SaveFormat.Pdf;var passwd = string.IsNullOrEmpty(ReportDto.passwd) ? string.Empty : ReportDto.passwd;PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(passwd, "owner", PdfEncryptionAlgorithm.RC4_128);encryptionDetails.Permissions = PdfPermissions.DisallowAll;encryptionDetails.Permissions = PdfPermissions.Printing | PdfPermissions.HighResolutionPrinting;saveOption.EncryptionDetails = encryptionDetails;var saveret=  doct.Save(pdfDir, saveOption);string returnHtppurl = "";if (!string.IsNullOrEmpty(pdfDir)){//var myhttprequest = IOCProvider.GetService<IHttpContextAccessor>().HttpContext.Request;//var httpHost = myhttprequest.Scheme + "://" + myhttprequest.Host;//string httpHost = AppDomain.CurrentDomain.BaseDirectory;string FullFileName = "";string nowDirection = "";string[] fileUrlArr = pdfDir.Split('\\');FullFileName = fileUrlArr[fileUrlArr.Length - 1];nowDirection = fileUrlArr[fileUrlArr.Length - 2];returnHtppurl = myconfiguration["Report:ReportFileUrl"].ToString().Replace("\\", "/") + "/" + nowDirection + "/" + FullFileName;//returnHtppurl =  filePath;}else{}return returnHtppurl;}catch (Exception ex){throw new Exception(ex.Message);}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/238362.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

京东数据运营-京东数据开放平台-鲸参谋10月粮油调味市场品牌店铺销售数据分析

鲸参谋监测的京东平台10月份料油调味市场销售数据已出炉&#xff01; 根据鲸参谋数据显示&#xff0c;今年10月份&#xff0c;京东平台粮油调味市场的销量将近4600万&#xff0c;环比增长约10%&#xff0c;同比降低约20%&#xff1b;销售额将近19亿&#xff0c;环比增长约4%&am…

VT-VRPA2-1-1X/V0/T5控制4WRE6比例方向阀放大板

带阀芯位移反馈不带集成式放大器比例方向阀控制放大器&#xff0c;替代力士乐同型号产品&#xff0c;可以完全互换使用&#xff1b;适用于控制力士乐系列带电位置反馈的4WRE6通径和4WRE10通径2X系列比例方向阀&#xff1b;0~10V、4~20mA指令控制信号任意可选&#xff1b;直接安…

Docker 镜像及其命令

文章目录 镜像Docker 镜像加载原理联合文件系统bootfs和rootfs镜像分层 镜像分层的优势容器层常用命令 镜像 镜像是一种轻量级、可执行的独立软件包&#xff0c;它包含运行某个软件所需的所有内容&#xff0c;我们把应用程序和配置依赖打包好形成一个可交付的运行环境&#xff…

cmake和vscode 下的cmake的使用详解(二)

第四讲&#xff1a; GDB 调试器 前言&#xff1a; GDB(GNU Debugger) 是一个用来 调试 C/C 程序 的功能强大的 调试器 &#xff0c;是 Linux 系统开发 C/C 最常用的调试器 程序员可以 使用 GDB 来跟踪程序中的错误 &#xff0c;从而减少程序员的工作量。 Linux 开发 C/C …

SQL Sever 基础知识 - 限制行数

SQL Sever 基础知识 - 三、限制行数 三、限制行数第1节 OFFSET FETCH - 限制查询返回的行数1.1 OFFSET 和 FETCH 子句1.2 SQL Server OFFSET 和 FETCH 示例 第2节 SELECT TOP - 限制查询结果集中返回的行数或行的百分比2.1 SELECT TOP 子句2.2 PERCENT2.3 WITH TIES2.4 SELECT …

Excel导入操作

<template><el-dialogwidth"500px"title"员工导入":visible"showExcelDialog"close"$emit(update:showExcelDialog, false)"><el-row type"flex" justify"center"><div class"upload-e…

计算机毕业设计 基于SpringBoot的敬老院管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解

博主介绍&#xff1a;✌从事软件开发10年之余&#xff0c;专注于Java技术领域、Python人工智能及数据挖掘、小程序项目开发和Android项目开发等。CSDN、掘金、华为云、InfoQ、阿里云等平台优质作者✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精…

计算机视觉(OpenCV+TensorFlow)

计算机视觉&#xff08;OpenCVTensorFlow&#xff09; 文章目录 计算机视觉&#xff08;OpenCVTensorFlow&#xff09;前言7. 图像直方图绘制直方图绘制直方图有两种方式&#xff1a; 掩膜 8. 直方图均衡化直方图均衡化的介绍直方图均衡化的步骤自适应直方图均衡化 9. 图像转换…

HarmonyOS ArkTS与c++交互通信

一、创建Native C Module 1、右键项目->new->module 如图&#xff1a; 2、修改build-profile.json5配置 "externalNativeOptions": {"path": "./src/main/cpp/CMakeLists.txt","arguments": "-v -DOHOS_STLc_shared&quo…

re:Invent大会,亚马逊云科技为用户提供端到端的AI服务

11月末&#xff0c;若是你降落在拉斯维加斯麦卡伦国际机场&#xff0c;或许会在大厅里看到一排排AI企业和云厂商相关的夸张标语。走向出口的路上&#xff0c;你的身边会不断穿梭过穿着印有“AI21Lab”“Anthropic”等字样的AI企业员工。或许&#xff0c;你还会被机场工作人员主…

cocos 关于多个摄像机,动态添加节点的显示问题,需要动态修改layer。(跟随摄像机滚动)(神坑官网也不说明一下)

参考文章&#xff1a;Cocos 3.x 层级Layer - 简书 2D镜头跟随应该怎么实现呢 - Creator 3.x - Cocos中文社区 关于多个摄像机&#xff0c;动态添加节点的显示问题&#xff0c;需要动态修改layer&#xff1f; 场景&#xff1a;在制作摄像机跟随角色移动功能时&#xff0c;新增…

[数据结构]深入浅出讲解二叉树-平衡二叉树-左右旋转

树是一种数据结构&#xff0c;单位为Node(节点)。不同于链表的直线排列&#xff0c;树呈现一种自上而下的分层排序规则。 树->数据结构&#xff1a; 单元为Node(节点)->当这样的节点多了 就可以关联出不同的形态 一个父节点有一个左子节点&#xff0c;有…