自动化word导出

embedded/2024/10/17 19:33:29/

c#

word">using (word">var document = DocX.Create(file))
{document.InsertParagraph().Append("故障报告").FontSize(18).Bold().Alignment = Xceed.Document.NET.Alignment.center;word">var table = document.InsertTable(1, 2);table.SetBorder(TableBorderType.Top, word">new Xceed.Document.NET.Border() { Color = Color.Transparent });table.SetBorder(TableBorderType.Bottom, word">new Xceed.Document.NET.Border() { Color = Color.Transparent });table.SetBorder(TableBorderType.Left, word">new Xceed.Document.NET.Border() { Color = Color.Transparent });table.SetBorder(TableBorderType.Right, word">new Xceed.Document.NET.Border() { Color = Color.Transparent });table.SetBorder(TableBorderType.InsideH, word">new Xceed.Document.NET.Border() { Color = Color.Transparent });table.SetBorder(TableBorderType.InsideV, word">new Xceed.Document.NET.Border() { Color = Color.Transparent });table.Rows[0].Cells[0].Paragraphs[0].Append("型号:" + uavtype.SelectedItem).Alignment=Alignment.left;table.Rows[0].Cells[1].Paragraphs[0].Append("故障名称:" + faultname.Text).Alignment=Alignment.right;MemoryStream memoryStream = word">new MemoryStream();edit.CaptureImage().Save(memoryStream);document.InsertParagraph().AppendPicture(document.AddImage(memoryStream).CreatePicture(300, document.PageWidth - document.MarginLeft - document.MarginRight));word">var word">group = edit._groups.Where(o => !word">string.IsNullOrEmpty(o.Text)).ToList();table = document.InsertTable(word">group.Count+2, 3);table.Alignment = Xceed.Document.NET.Alignment.center;table.SetBorder(TableBorderType.Top, word">new Xceed.Document.NET.Border() { Color = Color.PowderBlue });table.SetBorder(TableBorderType.Bottom, word">new Xceed.Document.NET.Border() { Color = Color.PowderBlue });table.SetBorder(TableBorderType.Left, word">new Xceed.Document.NET.Border() { Color = Color.PowderBlue });table.SetBorder(TableBorderType.Right, word">new Xceed.Document.NET.Border() { Color = Color.PowderBlue });table.SetBorder(TableBorderType.InsideH, word">new Xceed.Document.NET.Border() { Color = Color.PowderBlue });table.SetBorder(TableBorderType.InsideV, word">new Xceed.Document.NET.Border() { Color = Color.PowderBlue });table.Rows[0].MergeCells(0,2);table.Rows[0].Cells[0].FillColor = Color.PowderBlue;table.Rows[0].Cells[0].Paragraphs[0].Append("节点规则");table.Rows[1].Cells[0].Paragraphs[0].Append("节点");table.Rows[1].Cells[1].Paragraphs[0].Append("规则名称");table.Rows[1].Cells[2].Paragraphs[0].Append("规则内容");word">for (word">int i=0; i< word">group.Count; i++){table.Rows[i+2].Cells[0].Paragraphs[0].Append(word">group[i].Text);table.Rows[i+2].Cells[1].Paragraphs[0].Append(word">group[i].Name);table.Rows[i+2].Cells[2].Paragraphs[0].Append(word">group[i].Rule);}document.Save();
}

c++

CApplication word_app;
word">if (!word_app.CreateDispatch(_T("Word.Application"), NULL))//if (!word_app.CreateDispatch(_T("KWPS.Application"), NULL))
{//printf("本机没有安装word产品!");LOG_ERROR("该机器没有安装 MS WORD");word">return -1;
}
word_app.put_Visible(FALSE);//设置word可见
COleVariant vTrue((word">short)TRUE), vFalse((word">short)FALSE), VOpt((word">long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CDocuments docs;
CDocument0 doc;
docs = word_app.get_Documents();
doc = docs.Add(&CComVariant(_T("")), &CComVariant(false), &CComVariant(0), &CComVariant());
CPageSetup pagesetup = doc.get_PageSetup();
pagesetup.put_LeftMargin(50);
pagesetup.put_RightMargin(50);  //设置左右间距
try {CSelection sel = word_app.get_Selection();CParagraphs wordParagraphs = sel.get_ParagraphFormat();CString strShow = L"故障报告";CFont0 font = sel.get_Font();font.put_Size(16);font.put_Bold(1);font.put_Name(L"宋体");wordParagraphs.put_Alignment(1);sel.TypeText(strShow);sel.TypeParagraph();CTables0 tables = doc.get_Tables();CTable0 table = tables.Add(sel.get_Range(), 1, 2, vTrue, VOpt);CBorders borders = table.get_Borders();borders.put_InsideColor(RGB(255, 255, 255));borders.put_OutsideColor(RGB(255, 255, 255));word">auto input_cell = [](CCell cell, CString strShow, word">int align) {CRange range = cell.get_Range();CParagraphs oParagraphs = range.get_Paragraphs();CFont0 font = range.get_Font();font.put_Size(10);font.put_Bold(0);font.put_Name(L"宋体");oParagraphs.put_Alignment(align);range.InsertAfter(strShow);};CCell cell = table.Cell(1, 1);input_cell(cell, L"型号:" + record.uavtype, 0);cell = table.Cell(1, 2);input_cell(cell, L"故障名称:" + record.faultname, 2);sel.GoTo(COleVariant((word">short)3), COleVariant((word">short)-1),VOpt,VOpt);CnlineShapes shapes = sel.get_InlineShapes();CnlineShape shape = shapes.AddPicture(image.c_str(), vFalse, vTrue, VOpt);shape.put_Height(300);shape.put_Width(pagesetup.get_PageWidth()-100);vector<tuple<wstring, wstring, wstring, wstring>> item;recrusvie_tree(record.tree["tree"], item);tables = doc.get_Tables();table = tables.Add(sel.get_Range(), item.size()+5, 4, vTrue, VOpt);borders = table.get_Borders();borders.put_InsideColor(RGB(198, 217, 241));borders.put_OutsideColor(RGB(198, 217, 241));cell = table.Cell(1, 1);cell.Merge(table.Cell(1, 2));cell.Merge(table.Cell(1, 2));cell.Merge(table.Cell(1, 2));CShading shading = cell.get_Shading();shading.put_BackgroundPatternColor(RGB(198, 217, 241));input_cell(cell,  L"故障诊断结果建议", 0);cell = table.Cell(2, 1);cell.Merge(table.Cell(2, 2));input_cell(cell, L"诊断结果", 0);cell = table.Cell(2, 2);cell.Merge(table.Cell(2, 3));input_cell(cell, record.result,0);cell = table.Cell(3, 1);cell.Merge(table.Cell(3, 2));input_cell(cell, L"专家建议", 0);cell = table.Cell(3, 2);cell.Merge(table.Cell(3, 3));input_cell(cell, record.advise,0);cell = table.Cell(4, 1);cell.Merge(table.Cell(4, 2));cell.Merge(table.Cell(4, 2));cell.Merge(table.Cell(4, 2));shading = cell.get_Shading();shading.put_BackgroundPatternColor(RGB(198, 217, 241));input_cell(cell, L"故障各节点规则", 0);CString header[4] = { L"节点",L"规则名称",L"规则内容",L"状态"};word">for (word">int j = 0; j < item.size()+1; j++) {word">for (word">int i = 0; i < 4; i++) {cell = table.Cell(j+5, i + 1);strShow = j==0?header[i]:(i == 0?get<0>(item[j-1]).c_str() : i == 1 ? get<1>(item[j-1]).c_str() : i == 2 ? get<2>(item[j-1]).c_str() : get<3>(item[j-1]).c_str());input_cell(cell, strShow,1);}}sel.GoTo(COleVariant((word">short)3), COleVariant((word">short)-1), VOpt, VOpt);sel.TypeParagraph();word">for (word">int i = 0; i < record.faultcase.size(); i++) {table = tables.Add(sel.get_Range(), 7, 2, vTrue, VOpt);borders = table.get_Borders();borders.put_InsideColor(RGB(198, 217, 241));borders.put_OutsideColor(RGB(198, 217, 241));cell = table.Cell(1, 1);cell.Merge(table.Cell(1, 2));shading = cell.get_Shading();shading.put_BackgroundPatternColor(RGB(198, 217, 241));input_cell(cell, L"故障名称:"+ get<0>(record.faultcase[i])).c_str(), 0);cell = table.Cell(2, 1);input_cell(cell, L"案例主题", 0);cell = table.Cell(2, 2);input_cell(cell, get<0>(record.faultcase[i]).c_str(), 0);cell = table.Cell(3, 1);input_cell(cell, L"故障描述", 0);cell = table.Cell(3, 2);input_cell(cell, get<1>(record.faultcase[i]).c_str(), 0);cell = table.Cell(4, 1);input_cell(cell, L"案例内容", 0);cell = table.Cell(4, 2);input_cell(cell, get<2>(record.faultcase[i]).c_str(), 0);cell = table.Cell(5, 1);input_cell(cell, L"分析原因", 0);cell = table.Cell(5, 2);input_cell(cell, get<3>(record.faultcase[i]).c_str(), 0);cell = table.Cell(6, 1);input_cell(cell, L"问题定位", 0);cell = table.Cell(6, 2);input_cell(cell, get<4>(record.faultcase[i]).c_str(), 0);cell = table.Cell(7, 1);input_cell(cell, L"处理建议", 0);cell = table.Cell(7, 2);input_cell(cell, get<5>(record.faultcase[i]).c_str(), 0);}doc.SaveAs(COleVariant(filename), VOpt, VOpt, VOpt, VOpt, VOpt, VOpt, VOpt, VOpt,VOpt, VOpt, VOpt, VOpt, VOpt, VOpt, VOpt);
}

http://www.ppmy.cn/embedded/4070.html

相关文章

数据结构和算法(哈希表和图(A*算法精讲))

一 、哈希表 1.1 哈希表原理精讲 哈希表-散列表&#xff0c;它是基于快速存取的角度设计的&#xff0c;也是一种典型的“空间换时间”的做法 键(key)&#xff1a; 组员的编号如&#xff0c;1、5、19。。。 值(value)&#xff1a; 组员的其它信息&#xff08;包含性别、年龄和…

深入探究图像增强(C语言实现)

我们将从基础出发使用C语言进行图像处理与分析&#xff0c;重点讨论图像增强和平滑技术。图像增强技术旨在通过增加对比度、亮度和整体清晰度来改善图像的视觉质量。另一方面&#xff0c;图像平滑方法则用于减少噪声并减少图像中的突变&#xff0c;使图像更加均匀和视觉上吸引人…

开源大模型 Llama 3

开源大模型Llama 3是一个在多个领域都展现出卓越性能的大模型。下面将为您介绍Llama 3的特性和一些简单的使用案例。 一、Llama 3介绍 Llama 3在Meta自制的两个24K GPU集群上进行预训练&#xff0c;使用了超过15T的公开数据&#xff0c;其中5%为非英文数据&#xff0c;涵盖30多…

无风扇嵌入式车载电脑在矿山车辆行业应用

矿山车辆行业应用 背景介绍 现代的采矿业面临许多的挑战&#xff0c;其中最重要的就是安全性的问题&#xff0c;无论在矿井下或地面上的工作&#xff0c;都必须确保员工的安全保障。因此&#xff0c;先进的矿车必须整合专用的车载电脑&#xff0c;在极其恶劣的采矿环境中稳定运…

软件工程及开发模型

根据希赛相关视频课程汇总整理而成&#xff0c;个人笔记&#xff0c;仅供参考。 软件工程的基本要素包括方法、工具和&#xff08;过程&#xff09; 方法&#xff1a;完成软件开发的各项任务的技术方法&#xff1b; 工具&#xff1a;运用方法而提供的软件工程支撑环境&#xff…

Ubuntu 20.04 安装Nginx-1.25.4

操作系统&#xff1a;Ubuntu 20.04.5 LTS 软件版本&#xff1a;nginx-1.25.4 一、环境准备 安装GCC编译器 安装PCRE 安装OpenSSL 安装OpenSSL库 安装zlib库 # 安装GCC编译器&#xff08;build-essential 包会安装GCC编译器以及其他一些用于编译源代码的必须工具&#xff09;sud…

配置路由器实现互通

1.实验环境 实验用具包括两台路由器(或交换机)&#xff0c;一根双绞线缆&#xff0c;一台PC&#xff0c;一条Console 线缆。 2.需求描述 如图6.14 所示&#xff0c;将两台路由器的F0/0 接口相连&#xff0c;通过一台PC 连接设备的 Console 端口并配置P地址&#xff08;192.1…

安卓手机APP开发__媒体开发部分__直播流

安卓手机APP开发__媒体开发部分__直播流 目录 概述 检查和监控直播的播放 在直播流中的定位查找 直播播放的用户界面 配置直播播放的参数 播放速度调整 定制播放速度的调整算法 直播窗口背后的异常和ERROR_CODE_BEHIND_LIVE_WINDOW 概述 ExoPlayer没有任何特殊配置的…