【Poi-tl Documentation】区块对标签显示隐藏改造

前置说明:

<dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.12.1</version>
</dependency>

模板:
删除行表格测试.docx
image.png

改造前测试效果

package run.siyuan.poi.tl.区对块的改造;import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.render.RenderContext;
import com.deepoove.poi.xwpf.BodyContainer;
import com.deepoove.poi.xwpf.BodyContainerFactory;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import run.siyuan.poi.tl.policy.CustomRenderPolicy;import java.io.*;
import java.util.HashMap;
import java.util.Map;public class Main {public static void main(String[] args) throws Exception {test1();}public static void test1() throws IOException {// 读取模板文件FileInputStream fileInputStream = new FileInputStream("/Users/wuzhiqian/Desktop/HY/删除行表格测试.docx");// 创建模板配置ConfigureBuilder configureBuilder = Configure.builder();configureBuilder.buildGrammerRegex("((#)?[\\w\\u4e00-\\u9fa5\\-]+(\\.[\\w\\u4e00-\\u9fa5\\-]+)*)?");configureBuilder.setValidErrorHandler(new Configure.ClearHandler() {@Overridepublic void handler(RenderContext<?> context) {System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");try {XWPFRun run = context.getRun();run.setText("/");BodyContainer bodyContainer = BodyContainerFactory.getBodyContainer(run);bodyContainer.clearPlaceholder(run);} catch (Exception e) {System.out.println("标签不存在-------------------------------------------");}}});// 创建模板上下文Map<String, Object> context = new HashMap<>();context.put("a_1", "1");context.put("b_1", "2");context.put("c_1", "3");context.put("a_2", "4");context.put("b_2", "5");context.put("c_2", "6");context.put("a_3", "7");context.put("b_3", "8");context.put("c_3", "9");context.put("a_4", "10");context.put("b_4", "11");context.put("c_4", "12");context.put("a_5", "13");context.put("b_5", "14");context.put("c_5", "15");context.put("d_1", "16");configureBuilder.addPlugin('!', new CustomRenderPolicy(context));// 使用模板引擎替换文本标签XWPFTemplate compile = XWPFTemplate.compile(fileInputStream, configureBuilder.build());compile.render(context);// 保存生成的文档FileOutputStream outputStream = new FileOutputStream("/Users/wuzhiqian/Desktop/HY/删除行表格测试_" + System.currentTimeMillis() + ".docx");compile.write(outputStream);outputStream.close();compile.close();fileInputStream.close();}}

运行后的效果:
image.png
显示没有问题,但是不是我想要的效果,我想要的效果
image.png
就是通过一个非bool的字段就能判断出我这个区块对的是否显示。

改造开始中

package run.siyuan.poi.tl.区对块的改造;import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.render.compute.RenderDataCompute;
import com.deepoove.poi.render.processor.DocumentProcessor;
import com.deepoove.poi.render.processor.IterableProcessor;
import com.deepoove.poi.resolver.Resolver;
import com.deepoove.poi.template.IterableTemplate;
import com.deepoove.poi.template.MetaTemplate;
import com.deepoove.poi.xwpf.BodyContainer;
import com.deepoove.poi.xwpf.BodyContainerFactory;import java.util.List;/*** @ClassName CustomIterableProcessor* @Description TODO 自定义迭代起处理方法* @Author siyuan* @Date 2024/3/14 23:32*/
public class CustomIterableProcessor extends IterableProcessor {public CustomIterableProcessor(XWPFTemplate template, Resolver resolver, RenderDataCompute renderDataCompute) {super(template, resolver, renderDataCompute);}public void visit(IterableTemplate iterableTemplate) {this.logger.info("【custom】 Process iterableTemplate:{}", iterableTemplate);
//        super.visit(iterableTemplate);BodyContainer bodyContainer = BodyContainerFactory.getBodyContainer(iterableTemplate);// 数据Object compute = this.renderDataCompute.compute(iterableTemplate.getStartMark().getTagName());if (null == compute || compute instanceof Boolean && !(Boolean) compute) {this.handleNever(iterableTemplate, bodyContainer);} else if (compute instanceof Iterable) { // 数据为集合时this.handleIterable(iterableTemplate, bodyContainer, (Iterable) compute);} else if (compute instanceof Boolean && (Boolean) compute) { // 数据为 bool 时this.handleOnceWithScope(iterableTemplate, this.renderDataCompute);} else if (compute instanceof String) { // TODO 数据为字符串时this.handleOnceWithScope(iterableTemplate, this.renderDataCompute);} else if (compute instanceof Number) { // TODO 数据为数字时this.handleOnceWithScope(iterableTemplate, this.renderDataCompute);} else {// 初上出两种类型意外的数据this.handleOnce(iterableTemplate, compute);}this.afterHandle(iterableTemplate, bodyContainer);}}

这块代码主要是新增了 String 和 Number 判断,this.renderDataCompute 相当于示例中的 context,conpute 相当于 a_1 对应的值 1。

package run.siyuan.poi.tl.区对块的改造;import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.render.compute.RenderDataCompute;
import com.deepoove.poi.render.processor.DocumentProcessor;
import com.deepoove.poi.render.processor.ElementProcessor;
import com.deepoove.poi.render.processor.InlineIterableProcessor;
import com.deepoove.poi.resolver.Resolver;
import com.deepoove.poi.template.*;
import com.deepoove.poi.template.run.RunTemplate;
import com.deepoove.poi.xwpf.XWPFTextboxContent;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;import java.util.HashSet;
import java.util.List;
import java.util.Set;/*** @ClassName CustomDocumentProcessor* @Description TODO* @Author siyuan* @Date 2024/3/16 15:27*/
public class CustomDocumentProcessor extends DocumentProcessor {private ElementProcessor elementProcessor;private CustomIterableProcessor iterableProcessor;private InlineIterableProcessor inlineIterableProcessor;public CustomDocumentProcessor(XWPFTemplate template, Resolver resolver, RenderDataCompute renderDataCompute) {super(template, resolver, renderDataCompute);this.elementProcessor = new ElementProcessor(template, resolver, renderDataCompute);this.iterableProcessor = new CustomIterableProcessor(template, resolver, renderDataCompute);this.inlineIterableProcessor = new InlineIterableProcessor(template, resolver, renderDataCompute);}public void process(List<MetaTemplate> templates) {templates.forEach((template) -> {template.accept(this);});Set<XWPFTextboxContent> textboxs = this.obtainTextboxes(templates);textboxs.forEach((content) -> {content.getXmlObject().set(content.getCTTxbxContent());});}private Set<XWPFTextboxContent> obtainTextboxes(List<MetaTemplate> templates) {Set<XWPFTextboxContent> textboxs = new HashSet();if (CollectionUtils.isEmpty(templates)) {return textboxs;} else {templates.forEach((template) -> {RunTemplate checkTemplate = template instanceof RunTemplate ? (RunTemplate) template : (template instanceof BlockTemplate ? ((BlockTemplate) template).getStartMark() : null);if (null != checkTemplate && checkTemplate.getRun().getParent() instanceof XWPFParagraph && checkTemplate.getRun().getParagraph().getBody() instanceof XWPFTextboxContent) {textboxs.add((XWPFTextboxContent) checkTemplate.getRun().getParagraph().getBody());}});return textboxs;}}public void visit(InlineIterableTemplate iterableTemplate) {iterableTemplate.accept(this.inlineIterableProcessor);}public void visit(IterableTemplate iterableTemplate) {iterableTemplate.accept(this.iterableProcessor);}public void visit(RunTemplate runTemplate) {runTemplate.accept(this.elementProcessor);}public void visit(PictureTemplate pictureTemplate) {pictureTemplate.accept(this.elementProcessor);}public void visit(PictImageTemplate pictImageTemplate) {pictImageTemplate.accept(this.elementProcessor);}public void visit(ChartTemplate chartTemplate) {chartTemplate.accept(this.elementProcessor);}
}

新增完 CustomIterableProcessor 类之后就是使用起来,在 CustomDocumentProcessor 中使用起来。

package run.siyuan.poi.tl.区对块的改造;import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.exception.RenderException;
import com.deepoove.poi.policy.DocxRenderPolicy;
import com.deepoove.poi.policy.RenderPolicy;
import com.deepoove.poi.render.DefaultRender;
import com.deepoove.poi.render.compute.RenderDataCompute;
import com.deepoove.poi.render.processor.DelegatePolicy;
import com.deepoove.poi.render.processor.LogProcessor;
import com.deepoove.poi.template.MetaTemplate;
import com.deepoove.poi.template.run.RunTemplate;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;/*** @ClassName CustomDefaultRender* @Description TODO* @Author siyuan* @Date 2024/3/16 15:25*/
public class CustomDefaultRender extends DefaultRender {private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRender.class);public CustomDefaultRender() {}public void render(XWPFTemplate template, Object root) {Objects.requireNonNull(template, "Template must not be null.");Objects.requireNonNull(root, "Data root must not be null");LOGGER.info("Render template start...");RenderDataCompute renderDataCompute = template.getConfig().getRenderDataComputeFactory().newCompute(root);StopWatch watch = new StopWatch();try {watch.start();this.renderTemplate(template, renderDataCompute);this.renderInclude(template, renderDataCompute);} catch (Exception var9) {if (var9 instanceof RenderException) {throw (RenderException)var9;}throw new RenderException("Cannot render docx template", var9);} finally {watch.stop();}LOGGER.info("Successfully Render template in {} millis", TimeUnit.NANOSECONDS.toMillis(watch.getNanoTime()));}private void renderTemplate(XWPFTemplate template, RenderDataCompute renderDataCompute) {(new LogProcessor()).process(template.getElementTemplates());// TODO 调用自定义的 DocumentProcessorCustomDocumentProcessor documentRender = new CustomDocumentProcessor(template, template.getResolver(), renderDataCompute);documentRender.process(template.getElementTemplates());}private void renderInclude(XWPFTemplate template, RenderDataCompute renderDataCompute) throws IOException {List<MetaTemplate> elementTemplates = template.getElementTemplates();long docxCount = elementTemplates.stream().filter((meta) -> {return meta instanceof RunTemplate && ((RunTemplate)meta).findPolicy(template.getConfig()) instanceof DocxRenderPolicy;}).count();if (docxCount >= 1L) {template.reload(template.getXWPFDocument().generate());this.applyDocxPolicy(template, renderDataCompute, docxCount);}}private void applyDocxPolicy(XWPFTemplate template, RenderDataCompute renderDataCompute, long docxItems) {RenderPolicy policy = null;NiceXWPFDocument current = template.getXWPFDocument();List<MetaTemplate> elementTemplates = template.getElementTemplates();int k = 0;while(true) {while(k < elementTemplates.size()) {for(int j = 0; j < elementTemplates.size(); k = j) {MetaTemplate metaTemplate = (MetaTemplate)elementTemplates.get(j);if (metaTemplate instanceof RunTemplate) {RunTemplate runTemplate = (RunTemplate)metaTemplate;policy = runTemplate.findPolicy(template.getConfig());if (policy instanceof DocxRenderPolicy) {DelegatePolicy.invoke(policy, runTemplate, renderDataCompute.compute(runTemplate.getTagName()), template);if (current != template.getXWPFDocument()) {current = template.getXWPFDocument();elementTemplates = template.getElementTemplates();k = 0;break;}}}++j;}}return;}}}

接着就是使用 CustomDocumentProcessor 类型了,CustomDefaultRender 中的 64 行。

package run.siyuan.poi.tl.区对块的改造;import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.exception.ResolverException;
import com.deepoove.poi.resolver.TemplateResolver;
import com.deepoove.poi.xwpf.NiceXWPFDocument;import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;/*** @ClassName CustomXWPFTemplate* @Description TODO* @Author siyuan* @Date 2024/3/16 15:23*/
public class CustomXWPFTemplate {/*** 模拟 {@link XWPFTemplate} 类 {@link #compile(InputStream, Configure)} 方法,通过反射的方式来创建 {@link XWPFTemplate} 并给属性赋值,** @param inputStream* @param config* @return {@link XWPFTemplate}*/public static XWPFTemplate compile(InputStream inputStream, Configure config) {try {Class<XWPFTemplate> xwpfTemplateClass = XWPFTemplate.class;Field docFiled = xwpfTemplateClass.getDeclaredField("doc");docFiled.setAccessible(true);NiceXWPFDocument niceXWPFDocument = new NiceXWPFDocument(inputStream);Field configFiled = xwpfTemplateClass.getDeclaredField("config");configFiled.setAccessible(true);Field resolverFiled = xwpfTemplateClass.getDeclaredField("resolver");resolverFiled.setAccessible(true);Field rendererFiled = xwpfTemplateClass.getDeclaredField("renderer");rendererFiled.setAccessible(true);Field eleTemplatesFiled = xwpfTemplateClass.getDeclaredField("eleTemplates");eleTemplatesFiled.setAccessible(true);Constructor<XWPFTemplate> declaredConstructor = xwpfTemplateClass.getDeclaredConstructor();declaredConstructor.setAccessible(true);XWPFTemplate xwpfTemplate = declaredConstructor.newInstance();docFiled.set(xwpfTemplate, niceXWPFDocument);configFiled.set(xwpfTemplate, config);TemplateResolver templateResolver = new TemplateResolver(config);resolverFiled.set(xwpfTemplate, templateResolver);// TODO 使用自定义的 CustomDefaultRenderrendererFiled.set(xwpfTemplate, new CustomDefaultRender());eleTemplatesFiled.set(xwpfTemplate, templateResolver.resolveDocument(niceXWPFDocument));return xwpfTemplate;} catch (Exception e) {throw new ResolverException("Compile template failed", e);}}}

最后就是用我们自定义的 CustomDefaultRender 了,因为 XWPFTemplate 构造函数是 private,不能使用继承的方式实现,最后我们通过反射的方式来处理,模拟 XWPFTemplate.compile(InputStream, Configure) 方法,通过反射的方式来创建 XWPFTemplate 并给属性赋值,renderer 使用我们自定会的 CustomDefaultRender。
这次改造过程中涉及到的很多方法都是从原有的方法中赋值,改动的部分很少。

改造后测试效果

package run.siyuan.poi.tl.区对块的改造;import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.render.RenderContext;
import com.deepoove.poi.xwpf.BodyContainer;
import com.deepoove.poi.xwpf.BodyContainerFactory;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import run.siyuan.poi.tl.policy.CustomRenderPolicy;import java.io.*;
import java.util.HashMap;
import java.util.Map;public class Main {public static void main(String[] args) throws Exception {test1();}public static void test1() throws IOException {// 读取模板文件FileInputStream fileInputStream = new FileInputStream("/Users/wuzhiqian/Desktop/HY/删除行表格测试.docx");// 创建模板配置ConfigureBuilder configureBuilder = Configure.builder();configureBuilder.buildGrammerRegex("((#)?[\\w\\u4e00-\\u9fa5\\-]+(\\.[\\w\\u4e00-\\u9fa5\\-]+)*)?");configureBuilder.setValidErrorHandler(new Configure.ClearHandler() {@Overridepublic void handler(RenderContext<?> context) {System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");try {XWPFRun run = context.getRun();run.setText("/");BodyContainer bodyContainer = BodyContainerFactory.getBodyContainer(run);bodyContainer.clearPlaceholder(run);} catch (Exception e) {System.out.println("标签不存在-------------------------------------------");}}});// 创建模板上下文Map<String, Object> context = new HashMap<>();context.put("a_1", "1");context.put("b_1", "2");context.put("c_1", "3");context.put("a_2", "4");context.put("b_2", "5");context.put("c_2", "6");context.put("a_3", "7");context.put("b_3", "8");context.put("c_3", "9");context.put("a_4", "10");context.put("b_4", "11");context.put("c_4", "12");context.put("a_5", "13");context.put("b_5", "14");context.put("c_5", "15");context.put("d_1", "16");configureBuilder.addPlugin('!', new CustomRenderPolicy(context));// 使用模板引擎替换文本标签XWPFTemplate compile = CustomXWPFTemplate.compile(fileInputStream, configureBuilder.build());compile.render(context);// 保存生成的文档FileOutputStream outputStream = new FileOutputStream("/Users/wuzhiqian/Desktop/HY/删除行表格测试_" + System.currentTimeMillis() + ".docx");compile.write(outputStream);outputStream.close();compile.close();fileInputStream.close();}}

image.png

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

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

c++入门学习⑨——STL(万字总结,超级超级详细版)看完这一篇就够了!!!

目录 &#x1f384;前言 &#x1f384;概念 引入 定义 优点 &#x1f384;六大组件 容器 算法 迭代器 仿函数 适配器 空间配置器 &#x1f384;三大组件 迭代器&#xff08;iterator&#xff09; 定义 分类&#xff1a; 正向迭代器&#xff1a; 常量正向迭代…

短视频矩阵系统/短视频矩阵系统技术saas研发

短视频矩阵系统SaaS研发是一个复杂且需要技术专业知识的工作。以下是一些关键步骤和建议&#xff0c;帮助你开发一个成功的短视频矩阵系统SaaS&#xff1a; 1. 明确需求&#xff1a;首先&#xff0c;你需要明确你的短视频矩阵系统的具体需求&#xff0c;例如用户规模、视频内容…

MATLAB:拟合与插值

一、关于多项式的基本操作 若要求非线性方程的根&#xff0c;则采用fzero, fminbnd函数 二、多项式拟合 clc, clear x0:0.2:10; y0.25*x20*sin(x); plot(x,y,k.,MarkerSize,15) grid on; hold on [p1,s1,mu1]polyfit(x,y,3); %3阶多项式拟合 y1polyval(p1,x,s1,mu1); [p2,s…

简易版 RPC 框架实现 1.0 -http实现

RPC 是“远程过程调用&#xff08;Remote Procedure Call&#xff09;”的缩写形式&#xff0c;比较通俗的解释是&#xff1a;像本地方法调用一样调用远程的服务。虽然 RPC 的定义非常简单&#xff0c;但是相对完整的、通用的 RPC 框架涉及很多方面的内容&#xff0c;例如注册发…

【jeecgboot】微服务实战LISM

目录 一、服务解决方案-Spring Cloud Alibaba1.1选用原因&#xff08;基于Spring Cloud Alibaba的试用场景&#xff09;1.2 核心组件使用前期规划 部署 nacos部署 mino使用JavaFreemarker模板引擎&#xff0c;根据XML模板文件生成Word文档使用JavaFlowable 工作流引擎前端 -vue…

瑞熙贝通打造智慧校园实验室安全综合管理平台

一、建设思路 瑞熙贝通实验室安全综合管理平台是基于以实验室安全&#xff0c;用现代化管理思想与人工智能、大数据、互联网技术、物联网技术、云计算技术、人体感应技术、语音技术、生物识别技术、手机APP、自动化仪器分析技术有机结合&#xff0c;通过建立以实验室为中心的管…

Java项目:54 springboot工资信息管理系统453

作者主页&#xff1a;源码空间codegym 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文中获取源码 项目介绍 本系统的使用角色可以被分为用户和管理员&#xff0c; 用户具有注册、查看信息、留言信息等功能&#xff0c; 管理员具有修改用户信息&#…

湖南麒麟SSH服务漏洞

针对湖南麒麟操作系统进行漏洞检测时&#xff0c;会报SSH漏洞风险提醒&#xff0c;具体如下&#xff1a; 针对这些漏洞&#xff0c;可以关闭SSH服务&#xff08;前提是应用已经部署完毕不再需要通过SSH远程访问传输文件的情况下&#xff0c;此时可以通过VNC远程登录方法&#x…

操作系统——cpu、内存、缓存介绍

一、内存是什么 内存就是系统资源的代名词&#xff0c;它是其他硬件设备与 CPU 沟通的桥梁&#xff0c; 计算机中的所有程序都在内存中运行。其作用是暂时存放CPU的运算数据&#xff0c;以及与硬盘交换的数据。也是相当于CPU与硬盘沟通的桥梁。只要计算机在运行&#xff0c;CP…

腾讯云2核4G服务器可以多少人同时访问?2核4G5M并发数计算

腾讯云轻量2核4G5M带宽服务器支持多少人在线访问&#xff1f;5M带宽下载速度峰值可达640KB/秒&#xff0c;阿腾云以搭建网站为例&#xff0c;假设优化后平均大小为60KB&#xff0c;则5M带宽可支撑10个用户同时在1秒内打开网站&#xff0c;并发数为10&#xff0c;经阿腾云测试&a…

电脑实现微信多开

电脑实现微信多开 现在很多人都有两个微信号&#xff0c;将工作与生活分开。工作上的伙伴用一个微信&#xff0c;生活中的朋友用一个微信。但是电脑只能打开一个微信&#xff0c;接下来简单三步教大家如何在电脑实现微信多开。 一、复制微信位置 右击单击微信&#xff0c;选…

Ubuntu 14.04:PaddleOCR基于PaddleHub Serving的服务部署(失败)

目录 一、为什么使用一键服务部署 二、安装 paddlehub 1.8 2.1 安装前的环境准备 2.2 安装paddlehub 1.8 2.2.1 安装paddlehub 2.2.2 检测安装是否成功 2.2.3 检查本地与远端PaddleHub-Server的连接状态 2.2.4 测试使用 2.3 其他 2.3.1 如何卸载、pip常用命令、常见…

Microsoft SQL Server2019占用大量磁盘空间的解决办法(占了我C盘120G的空间!!!)附SQL数据库定时清理代理作业

一、问题 安装Microsoft SQL Server2019后我的C盘在几天后少了100G&#xff0c;如图所示&#xff1a; 解决后&#xff1a; 出现这种情况&#xff0c;我在各种清理C盘后&#xff0c;空间还是没有太大变化 &#xff0c;且几乎每天都要少2个G&#xff0c;后来终于找见原因了&…

XCTF:level0[WriteUP]

PWN入门题目&#xff1a;XCTF攻防世界的level0 使用file、checksec命令查看文件详细信息 这是一个64bit的ELF文件&#xff08;后面编写EXP需要用到&#xff09; 从checksec中展示的信息看&#xff0c;该二进制文件只开启了NX&#xff08;数据执行保护&#xff09; 这样的话就…

【UE5】持枪状态站立移动的动画混合空间

项目资源文末百度网盘自取 创建角色在持枪状态站立移动的动画混合空间 在BlendSpace文件夹中单击右键选择动画(Animation)中的混合空间(Blend Space) 选择SK_Female_Skeleton 命名为BS_RifleStand 打开 水平轴表示角色的方向&#xff0c;命名为Direction&#xff0c;方…

想兼职赚钱?盘点6个靠谱兼职,赚钱更轻松!

1&#xff0c;微头条搬砖 微头条搬砖是一个门槛不高的赚钱方式&#xff0c;而且不需要你有多么好的原创能力&#xff0c;去收集一些热门文章的素材进行文章伪原创&#xff0c;十分钟就能搞定&#xff0c;只要你的文章有爆点&#xff0c;足够吸人眼球&#xff0c;就能够获取不低…

打造Python飞机大战游戏 - 从环境搭建到代码实现

一、环境搭建 要开发Python游戏&#xff0c;我们需要安装一些必要的库和工具。其中最常用的是pygame库&#xff0c;它提供了丰富的游戏开发功能。 目录 一、环境搭建 首先&#xff0c;确保你的计算机上已经安装了Python。然后&#xff0c;通过pip安装pygame库&#xff1a; 二…

蓝桥杯练习系统(算法训练)ALGO-969 N车

资源限制 内存限制&#xff1a;256.0MB C/C时间限制&#xff1a;1.0s Java时间限制&#xff1a;3.0s Python时间限制&#xff1a;5.0s 问题描述 给定NN的棋盘&#xff0c;问有多少种放置N个车使他们不互相攻击的方案。 输入格式 一行一个整数&#xff0c;N。 输出格式…

图像处理ASIC设计方法 笔记11 像素误差与字长优化

P108 P105 定点误差分析与字长优化 1 像素误差是什么原因导致的? 在本书所说的算法中,像素误差是由几次定点运算累加导致的: 首先由行(列)号与定点正弦/正切值计算出该行(列)的小数平移量,然后将这些小数平移量截取一定字长用来计算插值核,再将这些插值核也截取一…

修改NLog配置文件参数的方法

目录 一、背景 二、NLog配置文件 三、C#代码 四、验证结果 ​ 五、总结 一、背景 最近项目中要用到NLog记录日志&#xff0c;有一个要求是可以灵活地修改日志文件的存放位置&#xff0c;琢磨了一小会&#xff0c;发现可以使用XML文件的形式修改文件的参数&#xff0c;现将…