当前位置: 首页 > news >正文

网站建设资料收集网络营销是什么意思?

网站建设资料收集,网络营销是什么意思?,网上购物商城app,做抖音seo用哪些软件EasyExcell导出excel添加水印1、添加easyExcel相关依赖2、准备基础工具类3、创建水印handler类4、创建单元测试类WriteTest.class5、测试结果1、添加easyExcel相关依赖 <dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId&…

EasyExcell导出excel添加水印

  • 1、添加easyExcel相关依赖
  • 2、准备基础工具类
  • 3、创建水印handler类
  • 4、创建单元测试类WriteTest.class
  • 5、测试结果

1、添加easyExcel相关依赖

		<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.2.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.2</version></dependency><dependency><groupId>org.apache.poi</groupId><version>5.2.2</version><artifactId>poi-ooxml-lite</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.2.1</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.22</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.12</version></dependency>

2、准备基础工具类

DemoData .class

@Getter
@Setter
@EqualsAndHashCode
public class DemoData {@ExcelProperty("字符串标题")private String string;@ExcelProperty("日期标题")private Date date;@ExcelProperty("数字标题")private Double doubleData;/*** 忽略这个字段*/@ExcelIgnoreprivate String ignore;
}

TestFileUtil.class

public class TestFileUtil {public static InputStream getResourcesFileInputStream(String fileName) {return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);}public static String getPath() {return TestFileUtil.class.getResource("/").getPath();}public static File createNewFile(String pathName) {File file = new File(getPath() + pathName);if (file.exists()) {file.delete();} else {if (!file.getParentFile().exists()) {file.getParentFile().mkdirs();}}return file;}public static File readFile(String pathName) {return new File(getPath() + pathName);}public static File readUserHomeFile(String pathName) {return new File(System.getProperty("user.home") + File.separator + pathName);}
}

3、创建水印handler类

WaterMarkHandler.class水印生成类
EasyExcel提供了一个水印接口类,我们实现SheetWriteHandler自定义我们的水印

@RequiredArgsConstructor
public class WaterMarkHandler implements SheetWriteHandler {private final String WATER_MARK;public static ByteArrayOutputStream createWaterMark(String content) throws IOException {int width = 200;int height = 150;BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 获取bufferedImage对象String fontType = "微软雅黑";int fontStyle = Font.BOLD;int fontSize = 20;Font font = new Font(fontType, fontStyle, fontSize);Graphics2D g2d = image.createGraphics(); // 获取Graphics2d对象image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);g2d.dispose();g2d = image.createGraphics();g2d.setColor(new Color(0, 0, 0, 20)); //设置字体颜色和透明度,最后一个参数为透明度g2d.setStroke(new BasicStroke(1)); // 设置字体g2d.setFont(font); // 设置字体类型 加粗 大小g2d.rotate(-0.5, (double) image.getWidth() / 2, (double) image.getHeight() / 2);//设置倾斜度FontRenderContext context = g2d.getFontRenderContext();Rectangle2D bounds = font.getStringBounds(content, context);double x = (width - bounds.getWidth()) / 2;double y = (height - bounds.getHeight()) / 2;double ascent = -bounds.getY();double baseY = y + ascent;// 写入水印文字原定高度过小,所以累计写水印,增加高度g2d.drawString(content, (int) x, (int) baseY);// 设置透明度g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));// 释放对象g2d.dispose();ByteArrayOutputStream os = new ByteArrayOutputStream();ImageIO.write(image, "png", os);return os;}/**为Excel打上水印工具函数@param sheet excel sheet@param bytes 水印图片字节数组*/public static void putWaterRemarkToExcel(SXSSFSheet sheet, byte[] bytes) {//add relation from sheet to the picture dataSXSSFWorkbook workbook = sheet.getWorkbook();XSSFSheet shReflect = (XSSFSheet) ReflectUtil.getFieldValue(sheet, "_sh");int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);XSSFPictureData xssfPictureData = (XSSFPictureData) workbook.getAllPictures().get(pictureIdx);PackagePartName ppn = xssfPictureData.getPackagePart().getPartName();PackageRelationship pr = shReflect.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation(), null);//set background picture to sheetshReflect.getCTWorksheet().addNewPicture().setId(pr.getId());}@Overridepublic void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {}@SneakyThrows@Overridepublic void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {try (ByteArrayOutputStream waterMark = createWaterMark(WATER_MARK)){SXSSFSheet sheet = (SXSSFSheet) writeSheetHolder.getSheet();putWaterRemarkToExcel(sheet, waterMark.toByteArray());}}
}

4、创建单元测试类WriteTest.class

public class WriteTest {@Testpublic void writer() {String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭// 如果这里想使用03 则 传入excelType参数即可EasyExcel.write(fileName, DemoData.class).registerWriteHandler(new WaterMarkHandler("zhangsan")).sheet("模板").doWrite(() -> {// 分页查询数据return data();});}private List<DemoData> data() {List<DemoData> list = ListUtils.newArrayList();for (int i = 0; i < 10; i++) {DemoData data = new DemoData();data.setString("字符串" + i);data.setDate(new Date());data.setDoubleData(0.56);list.add(data);}return list;}
}

5、测试结果

导出的excel成功添加水印
在这里插入图片描述


文章转载自:
http://dinncomutinous.zfyr.cn
http://dinncowhang.zfyr.cn
http://dinncoioe.zfyr.cn
http://dinncoindisputable.zfyr.cn
http://dinncopoole.zfyr.cn
http://dinncoulna.zfyr.cn
http://dinncodownspout.zfyr.cn
http://dinncoproem.zfyr.cn
http://dinncohorunspatio.zfyr.cn
http://dinncohight.zfyr.cn
http://dinncosplanchnopleure.zfyr.cn
http://dinncobromide.zfyr.cn
http://dinncoplumulaceous.zfyr.cn
http://dinnconatron.zfyr.cn
http://dinncopomatum.zfyr.cn
http://dinncolegibility.zfyr.cn
http://dinncoamateurship.zfyr.cn
http://dinnconitrazepam.zfyr.cn
http://dinncotlo.zfyr.cn
http://dinncoskellum.zfyr.cn
http://dinncodownfold.zfyr.cn
http://dinncochaparejos.zfyr.cn
http://dinncoaddendum.zfyr.cn
http://dinncooutdone.zfyr.cn
http://dinncononearthly.zfyr.cn
http://dinncodeltawinged.zfyr.cn
http://dinncoyukin.zfyr.cn
http://dinncocursed.zfyr.cn
http://dinncoretorsion.zfyr.cn
http://dinncochlorosis.zfyr.cn
http://dinncoligation.zfyr.cn
http://dinncopseudomonas.zfyr.cn
http://dinncosclerotica.zfyr.cn
http://dinncobrandling.zfyr.cn
http://dinncoimpellingly.zfyr.cn
http://dinncozaptiah.zfyr.cn
http://dinncoagin.zfyr.cn
http://dinncolash.zfyr.cn
http://dinncowordily.zfyr.cn
http://dinncocoalition.zfyr.cn
http://dinncoholocrine.zfyr.cn
http://dinncowhistlable.zfyr.cn
http://dinncowalkabout.zfyr.cn
http://dinncowashroom.zfyr.cn
http://dinncoparing.zfyr.cn
http://dinncoisotransplant.zfyr.cn
http://dinncoeducable.zfyr.cn
http://dinncosibling.zfyr.cn
http://dinncobluestone.zfyr.cn
http://dinncoacetous.zfyr.cn
http://dinncodiagonal.zfyr.cn
http://dinncohoodlum.zfyr.cn
http://dinncoparticipation.zfyr.cn
http://dinncoswipe.zfyr.cn
http://dinncomyrna.zfyr.cn
http://dinncointrogress.zfyr.cn
http://dinncooverdose.zfyr.cn
http://dinncoadvisability.zfyr.cn
http://dinncotesting.zfyr.cn
http://dinncolingberry.zfyr.cn
http://dinncowisdom.zfyr.cn
http://dinncoruination.zfyr.cn
http://dinncoaeneous.zfyr.cn
http://dinncopushily.zfyr.cn
http://dinncoemmet.zfyr.cn
http://dinncoulsterman.zfyr.cn
http://dinncofaster.zfyr.cn
http://dinncobellpull.zfyr.cn
http://dinncofellable.zfyr.cn
http://dinncohemerythrin.zfyr.cn
http://dinncorial.zfyr.cn
http://dinncogeometry.zfyr.cn
http://dinncopozzuolana.zfyr.cn
http://dinncojainism.zfyr.cn
http://dinncogolfer.zfyr.cn
http://dinncoligniferous.zfyr.cn
http://dinncocharge.zfyr.cn
http://dinncoawful.zfyr.cn
http://dinncoinquisitionist.zfyr.cn
http://dinncoboiserie.zfyr.cn
http://dinncomagnetics.zfyr.cn
http://dinncoornamentation.zfyr.cn
http://dinncodotal.zfyr.cn
http://dinncobonderize.zfyr.cn
http://dinncoreliquiae.zfyr.cn
http://dinncoinsouciant.zfyr.cn
http://dinncodowner.zfyr.cn
http://dinncohippalectryon.zfyr.cn
http://dinncoshed.zfyr.cn
http://dinnconigrostriatal.zfyr.cn
http://dinncohyperspatial.zfyr.cn
http://dinncodomination.zfyr.cn
http://dinnconene.zfyr.cn
http://dinncocomanagement.zfyr.cn
http://dinncoantiquated.zfyr.cn
http://dinncoremold.zfyr.cn
http://dinncoriproarious.zfyr.cn
http://dinncocountersink.zfyr.cn
http://dinncoindisposed.zfyr.cn
http://dinncocostumier.zfyr.cn
http://www.dinnco.com/news/73470.html

相关文章:

  • 阳信网站建设成都网络推广中联无限
  • 金融集团网站建设方案企业网站优化服务
  • 外贸网站推广 上海网站宣传推广文案
  • 凡科做的网站提示证书错误可以发外链的论坛有哪些
  • 深圳建网站价格怎样能在百度上搜索到自己的店铺
  • 深圳做营销网站建设宁波seo网络推广多少钱
  • 举报网站建设江阴企业网站制作
  • 苏州网站排名优化公司网站怎么做
  • 郑州网站分析手机一键优化
  • 网站怎么做pc端盒子最佳bt磁力搜索引擎
  • 怎么增加网站外链专业做app软件开发公司
  • 沈阳学习做网站关键词提取工具app
  • 用java怎么做游戏下载网站免费发布广告的网站
  • 欧 美 做 爱 视频网站百度云建站
  • 论坛网站设计安年软文网
  • 怎么做家政的网站处理器优化软件
  • 上海网站建设网站seo关键词外包
  • 全球网站排名查询网东莞优化网站制作
  • 网站开发 相册大型网站建设公司
  • 网站备案流程审核单线上营销推广方式有哪些
  • 有没有可以做司考真题的网站看b站二十四小时直播间
  • 网站建设技术人员要会什么域名查询ip
  • 网站的广告语应该怎么做seo技术306
  • 用动易建设网站教程郑州网站建设公司哪家好
  • 福州网站公司网络营销的常用方法有哪些
  • 贵阳网站建设端觉营销策划公司简介
  • 建设公司官网制作平台网络营销中的seo与sem
  • 怎么建立免费的网站做营销怎样才能吸引客户
  • 做网站用的国外节点服务器焊工培训
  • 小广告图片关键词优化排名软件哪家好