poi实现EXCEL添加水印图片

dangerousDJ 2015-11-15 10:59:12
JAVA的POI方法对EXCEL添加图片可以实现,但是属于插入图片类型。想要做一个水印类型的样式,有做过的前辈吗?尝试了很多种方式都没有实现,有能指导一下的吗?
现在的成果:
图片会挡住原来的文字部分。
想要的效果是:
图片是透明的,不影响与那里的文字部分。
目标的效果是用EXCEL的插入页眉页脚的方法做出来的。
JAVA的POI技术能够仿照EXCEL的方法实现的吧?
还是大家有什么别的办法?类似JXL之类的方法?
坐等前辈们的回复。。。。。。。。。
...全文
4587 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinat_34581948 2017-10-23
  • 打赏
  • 举报
回复
楼主你好,你的这个问题解决了吗
qq_38216473 2017-10-08
  • 打赏
  • 举报
回复
怎么做的啊??qq1052757233,望指导啊,求帮助啊
yangSmallBear 2017-09-21
  • 打赏
  • 举报
回复
我想问一下,那个java poi怎么实现出类似于你那个excel的效果的,再做,找不到解决办法,求助一下!谢谢
Achieving阿六 2016-12-16
  • 打赏
  • 举报
回复
您好,请问具体实现是怎样的?
bcsflilong 2016-10-31
  • 打赏
  • 举报
回复
我做过 但是是调用了第三方的东西 Aspose 你百度一下
lisajxy 2016-10-31
  • 打赏
  • 举报
回复
引用 3 楼 dangerousDJ 的回复:
word,pdf都比较好实现,就是excel最麻烦啊。
~请问WORD如何实现呢~~最近在搞这个希望能指教~991211946@qq.com
xiao_1010 2015-12-17
  • 打赏
  • 举报
回复
你好,我想请问一下,我现在也在做你说的效果,请问一下,实现了吗,可以分享一下吗
yhfzmm 2015-11-30
  • 打赏
  • 举报
回复
你好,我在帖子上看到你有关于poi word 添加水印的程序 能给我参考参考吗 yhfzmm@163.com
yhfzmm 2015-11-27
  • 打赏
  • 举报
回复
引用 3 楼 dangerousDJ 的回复:
word,pdf都比较好实现,就是excel最麻烦啊。
亲 你有word的生成水印的例子吗
dangerousDJ 2015-11-16
  • 打赏
  • 举报
回复
引用 楼主 dangerousDJ 的回复:
JAVA的POI方法对EXCEL添加图片可以实现,但是属于插入图片类型。想要做一个水印类型的样式,有做过的前辈吗?尝试了很多种方式都没有实现,有能指导一下的吗? 现在的成果: 图片会挡住原来的文字部分。 想要的效果是: 图片是透明的,不影响与那里的文字部分。 目标的效果是用EXCEL的插入页眉页脚的方法做出来的。 JAVA的POI技术能够仿照EXCEL的方法实现的吧? 还是大家有什么别的办法?类似JXL之类的方法? 坐等前辈们的回复。。。。。。。。。
word,pdf都很方便实现,就是excel还没有实现啊。。。
dangerousDJ 2015-11-16
  • 打赏
  • 举报
回复
word,pdf都比较好实现,就是excel最麻烦啊。
  • 打赏
  • 举报
回复

    //*************************给PDF添加水印******************************************************************************************************************
		         String	zkzPdf1=user_name+"-"+UUID.randomUUID().toString()+".pdf";
		         String outputFile1 = zkzpath+zkzPdf1; 
		         try {
		        	 PdfReader reader = new PdfReader(outputFile, "PDF".getBytes());//获取要加水印的原pdf文件路径 
		            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outputFile1)); //加了水印后要输出的路径 
		            String markImagePath =ImageSYPaht + "view/front/20141210/images/shuiyin_1.png"; 
		            Image shuiyinImg = Image.getInstance(markImagePath);//水印图片路径      
		            shuiyinImg.setAbsolutePosition(110, 200); 
		             int pageSize = reader.getNumberOfPages();
		             for(int i = 1; i <= pageSize; i++) {  
		            	PdfContentByte under = stamp.getUnderContent(i);  
		              	under.addImage(shuiyinImg);  
		             }
						stamp.close();
						reader.close();
					} catch (DocumentException e) {
						e.printStackTrace();
					}// 关闭    
		            File tempfile = new File(outputFile); 
		            if(tempfile.exists()) {  
		              tempfile.delete();  
		            }  
	//**************************添加水印完成******************************************************************************************************************		         
		         int i=   webImpl.saveZkzPDF(decID, zkzPdf1);
		         if(i>0){
		        	 json.put("success", true);
		        	 json.put("zkzPdf", zkzPdf1);
		        	 
		         }else{
		        	 json.put("success", false);
		        	 json.put("msg", "生成模板失败,请重新生成!");
		        	 
		         }
		        response.getWriter().write(json.toString());
				response.getWriter().close();

tony4geek 2015-11-16
  • 打赏
  • 举报
回复
参考
private static void insertWatermarkText(Document doc, String watermarkText) throws Exception
{
    // Create a watermark shape. This will be a WordArt shape.
    // You are free to try other shape types as watermarks.
    Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);

    // Set up the text of the watermark.
    watermark.getTextPath().setText(watermarkText);
    watermark.getTextPath().setFontFamily("Arial");
    watermark.setWidth(500);
    watermark.setHeight(100);
    // Text will be directed from the bottom-left to the top-right corner.
    watermark.setRotation(-40);
    // Remove the following two lines if you need a solid black text.
    watermark.getFill().setColor(Color.GRAY); // Try LightGray to get more Word-style watermark
    watermark.setStrokeColor(Color.GRAY); // Try LightGray to get more Word-style watermark

    // Place the watermark in the page center.
    watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
    watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
    watermark.setWrapType(WrapType.NONE);
    watermark.setVerticalAlignment(VerticalAlignment.CENTER);
    watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);

    // Create a new paragraph and append the watermark to this paragraph.
    Paragraph watermarkPara = new Paragraph(doc);
    watermarkPara.appendChild(watermark);

    // Insert the watermark into all headers of each document section.
    for (Section sect : doc.getSections())
    {
        // There could be up to three different headers in each section, since we want
        // the watermark to appear on all pages, insert into all headers.
        insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
//            insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
//            insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
    }
}

private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType) throws Exception
{
    HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);

    if (header == null)
    {
        // There is no header of the specified type in the current section, create it.
        header = new HeaderFooter(sect.getDocument(), headerType);
        sect.getHeadersFooters().add(header);
    }

    // Insert a clone of the watermark into the header.
    header.appendChild(watermarkPara.deepClone(true));
}

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧