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
java 代码生成表格图片
最新推荐文章于 2024-07-12 21:40:46 发布
本文介绍如何使用Java编程生成包含表格数据的图片。通过特定的库,可以将CSV或Excel数据转换为图像,便于在网页、报告中快速查看表格信息。
摘要由CSDN通过智能技术生成