亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

Java生成表格圖片的實例代碼

瀏覽:71日期:2022-08-25 11:46:42

主要代碼:

/** * 生成圖片 * @param cellsValue 以二維數組形式存放 表格里面的值 * @param path 文件保存路徑 */public void myGraphicsGeneration(String cellsValue[][], String path) {// 字體大小int fontTitileSize = 15;// 橫線的行數int totalrow = cellsValue.length+1;// 豎線的行數int totalcol = 0;if (cellsValue[0] != null) {totalcol = cellsValue[0].length;}// 圖片寬度int imageWidth = 1024;// 行高int rowheight = 40;// 圖片高度int imageHeight = totalrow*rowheight+50;// 起始高度int startHeight = 10;// 起始寬度int startWidth = 10;// 單元格寬度int colwidth = (int)((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);graphics.setColor(new Color(220,240,240));//畫橫線for(int j=0;j<totalrow; j++){graphics.setColor(Color.black);graphics.drawLine(startWidth, startHeight+(j+1)*rowheight, startWidth+colwidth*totalcol, startHeight+(j+1)*rowheight);}//畫豎線for(int k=0;k<totalcol+1;k++){graphics.setColor(Color.black);graphics.drawLine(startWidth+k*colwidth, startHeight+rowheight, startWidth+k*colwidth, startHeight+rowheight*totalrow);}//設置字體Font font = new Font('微軟雅黑',Font.BOLD,fontTitileSize);graphics.setFont(font);//寫標題String title = '【指標完成進度】';graphics.drawString(title, startWidth, startHeight+rowheight-10);//寫入內容for(int n=0;n<cellsValue.length;n++){for(int l=0;l<cellsValue[n].length;l++){if (n == 0) {font = new Font('微軟雅黑',Font.BOLD,fontTitileSize);graphics.setFont(font);}else if (n > 0 && l >0) {font = new Font('微軟雅黑',Font.PLAIN,fontTitileSize);graphics.setFont(font);graphics.setColor(Color.RED);} else {font = new Font('微軟雅黑',Font.PLAIN,fontTitileSize);graphics.setFont(font);graphics.setColor(Color.BLACK);}graphics.drawString(cellsValue[n][l].toString(), startWidth+colwidth*l+5, startHeight+rowheight*(n+2)-10);}}// 保存圖片createImage(image, path);} /** * 將圖片保存到指定位置 * @param image 緩沖文件類 * @param fileLocation 文件位置 */public void createImage(BufferedImage image, String fileLocation) {try {FileOutputStream fos = new FileOutputStream(fileLocation);BufferedOutputStream bos = new BufferedOutputStream(fos);JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);encoder.encode(image);bos.close();} catch (Exception e) {e.printStackTrace();}}

測試代碼:

public static void main(String[] args) {DrawTableImg cg = new DrawTableImg();try {String tableData1[][] = {{'8月31日','累計用戶數','目標值','完成進度','時間進度', '進度差異'}, {'掌廳客戶端(戶)','469281','1500000','31.2%','33.6%', '-2.4%'}};String[][] tableData2 = {{'8月31日(戶)','新增用戶數','日訪問量','累計用戶數','環比上月'},{'合肥和巢湖','469281','1500000','31.2%','33.6%'},{'蕪湖','469281','1500000','31.2%','33.6%'},{'蚌埠','469281','1500000','31.2%','33.6%'},{'淮南','469281','1500000','31.2%','33.6%'},{'馬鞍山','469281','1500000','31.2%','33.6%'},{'淮北','469281','1500000','31.2%','33.6%'}};cg.myGraphicsGeneration(tableData2, 'c:myPic.jpg');} catch (Exception e) {e.printStackTrace();}}

效果圖

Java生成表格圖片的實例代碼

以上就是Java生成表格圖片的實例代碼的詳細內容,更多關于Java生成表格圖片的資料請關注好吧啦網其它相關文章!

標簽: Java
相關文章:
主站蜘蛛池模板: 一级特黄a免费大片 | 香蕉成人国产精品免费看网站 | 久久久亚洲欧美综合 | 日韩在线观看视频免费 | 欧美一级毛片日本 | 成人欧美网站免费 | 亚洲人成亚洲精品 | 国产日韩欧美一区二区三区在线 | 精品国产综合区久久久久99 | 亚洲三级a | 国产激情一区二区三区 | 国产欧美日韩一区二区三区 | 92午夜国产福利视频1000 | 国产成人精品高清不卡在线 | 欧美日韩高清在线观看一区二区 | 亚洲三级在线视频 | 亚洲一区二区三区精品国产 | 日韩免费专区 | 久久久久久亚洲精品不卡 | 看看免费a一片欧 | 免费看一区二区三区 | 欧美成人性色xxxx视频 | 久久er精品热线免费 | 久艹视频在线免费观看 | 朝鲜美女免费一级毛片 | 香蕉视频黄在线观看 | 中文字幕日韩精品在线 | 国产成人综合久久精品亚洲 | 久久在线视频免费观看 | 亚洲一区二区三区四区五区六区 | 欧美高清亚洲欧美一区h | 久久久999国产精品 久久久99精品免费观看 | 日本在线亚洲 | 欧美成人精品欧美一级乱黄 | 男人一进一出桶女人视频 | 久久久久久久久免费视频 | 久久精品视频一区 | 国产成人女人在线视频观看 | a级做爰片毛片视频 | 欧美高清在线精品一区 | 国产高清晰在线播放 |