Excel Java组件Spire.XLS教程:在Java中的Excel中插入和删除形状

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,立即购买!想要获取更多福利的朋友可以咨询在线客服哦~


将形状添加到Excel工作表:

import com.spire.xls.*;import com.spire.xls.core.*;import javax.imageio.ImageIO;import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;public class addShapestoExcel {    public static void main(String[] args) throws Exception {        String output = "output/AddShapesToExcelSheet.xlsx";        //create a workbook.        Workbook workbook = new Workbook();        //get the first worksheet.        Worksheet sheet = workbook.getWorksheets().get(0);        //add a triangle shape.        IPrstGeomShape triangle = sheet.getPrstGeomShapes().addPrstGeomShape(2, 2, 100, 100, PrstGeomShapeType.Triangle);        //fill the triangle with solid color.        triangle.getFill().setForeColor( Color.YELLOW);        triangle.getFill().setFillType( ShapeFillType.SolidColor);        //add a heart shape.        IPrstGeomShape heart = sheet.getPrstGeomShapes().addPrstGeomShape(2, 5, 100, 100, PrstGeomShapeType.Heart);        //fill the heart with gradient color.        heart.getFill().setForeColor(Color.RED);        heart.getFill().setFillType(ShapeFillType.Gradient);        //add an arrow shape with default color.        IPrstGeomShape arrow = sheet.getPrstGeomShapes().addPrstGeomShape(10, 2, 100, 100, PrstGeomShapeType.CurvedRightArrow);        //add a cloud shape.        IPrstGeomShape cloud = sheet.getPrstGeomShapes().addPrstGeomShape(10, 5, 100, 100, PrstGeomShapeType.Cloud);        //fill the cloud with custom picture        BufferedImage image = ImageIO.read(new File("SpireXls.png"));        cloud.getFill().customPicture(image, "SpireXls.png");        cloud.getFill().setFillType( ShapeFillType.Picture);        //save to file.        workbook.saveToFile(output, ExcelVersion.Version2013);        }}

输出如下:

Excel Java组件Spire.XLS教程:在Java中的Excel中插入和删除形状

从Excel工作表中删除特定形状或所有形状:

import com.spire.xls.*;public class removeShape {    public static void main(String[] args) throws Exception {                 //Load the sample file                Workbook workbook = new Workbook();                workbook.loadFromFile("output/AddShapesToExcelSheet.xlsx");                //get the first worksheet.                Worksheet sheet = workbook.getWorksheets().get(0);                //delete the second shape in the worksheet                sheet.getPrstGeomShapes().get(1).remove();              /* //delete all shapes in the worksheet                for (int i = sheet.getPrstGeomShapes().getCount()-1; i >= 0; i--)                 {                   sheet.getPrstGeomShapes().get(i).remove();                 }*/                //save to file.                workbook.saveToFile("output/RemoveParticularShape.xlsx", ExcelVersion.Version2013);            }        }

从Excel工作表中删除第二个形状后的有效屏幕截图:

Excel Java组件Spire.XLS教程:在Java中的Excel中插入和删除形状

是E-iceblue官方友好合作伙伴,如果您对spire.xls可以联系在线客服了解具体授权价格和使用机制
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年3月9日
下一篇 2021年3月9日

相关推荐

发表回复

登录后才能评论