给图片加上边框.(仿胶卷)

本文深入探讨了CSS样式的实现方法,包括边框和轮廓的不同应用技巧。通过具体实例讲解如何在不同浏览器环境下实现一致的显示效果,特别是针对Internet Explorer的特殊处理方式。
http://www.corange.cn//uploadfiles/2a18c100d779b219738b65c1_17907.jpg
http://www.corange.cn//uploadfiles/e417c539b2da45fb3b87cec3_40970.jpg


body{
margin:1em 12em;
background:#fff;
font:normal 1em/1.6em "lucida grande", "trebuchet ms", verdana, sans-serif;
}
h1{
text-indent:2em;
color:#dfdfdf;
background:#555;
padding:5px 0; margin:.4em 0;
border-top:4px solid #000;
font:normal 2em/1.1em "lucida grande", "trebuchet ms", verdana, sans-serif;
}
h2{
font-size:1.3em;
margin:1em 0;
}
a:link, a:visited, a:hover{ color:salmon; }
img{
float:left;
margin:0 30px 0 0; padding:4px;
}
.border-wrap, .outline-wrap{
width:96%;
padding:0 2% 20px 2%;
overflow:hidden;
}
.border{
border:5px dotted #fff; margin-right:23px;
/* border:3px dotted #fff;*/ /* this works better for Opera */
background:#ccc;
}
.outline-wrap{
background:#555;
color:#dfdfdf;
}
.outline{
outline:5px dotted #fff; /* dotted works better for Opera then dashed */
background:#fff;
}
.xray{
border-color:red;
outline-color:red;
background:yellow;
margin:20px auto;
float:none;
display:block;
}
#footer{
background:#555;
border-top:4px solid #000;
color:#efefef;
padding:.5em 1em 3em 1em;
text-align:center;
font-size:.8em; line-height:1.3em;
}
pre{
overflow:auto;
border:2px solid #ccc;
padding:4px;
float:right;
}
/* OK listen up, dont use the star html hack, I am using it here because I am too lazy to write a separate stylesheet for IE and use conditional comments */
* html .border{ border:5px dashed #ccc; } /* tweak for IE */
* html .xray{ border-color:red; }
* html .outline-wrap .border{ border-color:#fff; background:#fff; }
CSS Stamps v1.1
The border method
The outline method
Border method only for IE on a dark background

POI本身并没有直接给插入的Excel图片添加边框的方法,但可以通过一些变通的方式来实现类似效果,以下是一个示例代码: ```java import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.*; import org.springframework.core.io.ClassPathResource; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; public class AddBorderToImageInExcel { public static void main(String[] args) throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); // 先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); BufferedImage bufferImg = null; try { // 读取图片 ClassPathResource resource = new ClassPathResource("static/acc_sta_logo.png"); bufferImg = ImageIO.read(resource.getInputStream()); // 将图片写入流中 ImageIO.write(bufferImg, "png", byteArrayOut); // 利用HSSFPatriarch将图片写入EXCEL HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); // 图片导出到单元格B2中 HSSFClientAnchor anchor = new HSSFClientAnchor(350, 100, 150, 0, (short) 0, 0, (short) 1, 2); // 插入图片 patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); // 创建一个有边框的单元格样式 CellStyle borderStyle = wb.createCellStyle(); borderStyle.setBorderTop(BorderStyle.THIN); borderStyle.setBorderBottom(BorderStyle.THIN); borderStyle.setBorderLeft(BorderStyle.THIN); borderStyle.setBorderRight(BorderStyle.THIN); // 获取图片所在单元格范围并设置边框样式 Row row1 = sheet.getRow(anchor.getRow1()); if (row1 == null) { row1 = sheet.createRow(anchor.getRow1()); } Cell cell1 = row1.getCell(anchor.getCol1()); if (cell1 == null) { cell1 = row1.createCell(anchor.getCol1()); } cell1.setCellStyle(borderStyle); Row row2 = sheet.getRow(anchor.getRow2()); if (row2 == null) { row2 = sheet.createRow(anchor.getRow2()); } Cell cell2 = row2.getCell(anchor.getCol2()); if (cell2 == null) { cell2 = row2.createCell(anchor.getCol2()); } cell2.setCellStyle(borderStyle); } catch (IOException e) { e.printStackTrace(); } // 保存文件 FileOutputStream fileOut = new FileOutputStream("workbook.xls"); wb.write(fileOut); fileOut.close(); wb.close(); } } ``` 上述代码通过创建一个带有边框样式的单元格,将图片所在的单元格设置为该样式,从而实现给图片添加边框的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值