java 代码生成表格图片

本文介绍如何使用Java编程生成包含表格数据的图片。通过特定的库,可以将CSV或Excel数据转换为图像,便于在网页、报告中快速查看表格信息。
摘要由CSDN通过智能技术生成
public class GraphicsGeneration {
    public static BufferedImage graphicsGeneration(List<List<List<String>>> allValue,List<String> titles,List<String[]> headers ,String receiver,int totalcol,int isTableKuang) throws Exception {

        int rows = 0;
        for (List<List<String>> typeV : allValue) {
            if (typeV != null && typeV.size() > 0) {
                rows += (2+typeV.size());
            }
        }
        int imageWidth = 0;
        if(isTableKuang>0){
            // 实际数据行数+标题+备注
            imageWidth = 1601;
        }else {
            // 实际数据行数+标题+备注
             imageWidth = 500;
        }
        int totalrow = 1+rows;
        int imageHeight = totalrow * 30 + 20;
        int rowheight = 30;
        int startHeight = 10;
        int startWidth = 10;
        int colwidth = ((imageWidth - 20) / totalcol);


        BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
        Graphics graphics = image.getGraphics();

        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, imageWidth, imageHeight);
        int startH = 1;

        int rightLine = 0 ;
        int i = 0;
        Font font = null;
        //是否画边框
        if(isTableKuang>0) {
            //画背景
            graphics.setColor(new Color(198, 213, 214));

            for (List<List<String>> typeV : allValue) {
                if (typeV != null && typeV.size() > 0) {
                    graphics.fillRect(startWidth + 1, startHeight + startH * rowheight + 1 + 30, imageWidth - startWidth - 5 - 1, rowheight - 1);
                    startH += 2 + typeV.size();
                }
            }

            graphics.setColor(new Color(220, 240, 240));
            startH = 1;

            // 画横线
            for (int j = 0; j < totalrow - 1; j++) {
                graphics.setColor(Color.black);
                graphics.drawLine(startWidth, startHeight + (j + 1) * rowheight + 30, imageWidt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值