亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

主要代碼:

/** * 生成圖片 * @param cellsValue 以二維數(shù)組形式存放 表格里面的值 * @param path 文件保存路徑 */public void myGraphicsGeneration(String cellsValue[][], String path) {// 字體大小int fontTitileSize = 15;// 橫線的行數(shù)int totalrow = cellsValue.length+1;// 豎線的行數(shù)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);}//設(shè)置字體Font font = new Font('微軟雅黑',Font.BOLD,fontTitileSize);graphics.setFont(font);//寫標題String title = '【指標完成進度】';graphics.drawString(title, startWidth, startHeight+rowheight-10);//寫入內(nèi)容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日','累計用戶數(shù)','目標值','完成進度','時間進度', '進度差異'}, {'掌廳客戶端(戶)','469281','1500000','31.2%','33.6%', '-2.4%'}};String[][] tableData2 = {{'8月31日(戶)','新增用戶數(shù)','日訪問量','累計用戶數(shù)','環(huán)比上月'},{'合肥和巢湖','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生成表格圖片的實例代碼的詳細內(nèi)容,更多關(guān)于Java生成表格圖片的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標簽: Java
相關(guān)文章:
主站蜘蛛池模板: 久久精品草 | 麻豆传媒免费网站 | 自拍亚洲色图 | 污在线观看 | 欧美中文字幕一区二区三区 | 日本一卡2卡三卡4卡 免费网站仙踪 | 欧美一级久久久久久久久大 | 一级做a爰片性色毛片黄书 一级做a爰片性色毛片新版的 | 久久综合久久综合久久 | 色综合色综合色综合网址 | 538prom精品视频在放免费 | 欧美黑人巨大肥婆性视频 | 日韩亚洲综合精品国产 | 免费国产成人高清视频网站 | 国产精品品福利视频 | 欧美黄色网页 | ccmm123在线播放 | 欧美精品v国产精品v日韩精品 | 久久青草18免费观看网站 | 国产97在线 | 亚洲 | 国产综合精品在线 | 日韩中出 | 日日噜噜夜夜狠狠视频无 | 欧美性三三影院 | 亚洲免费影视 | 日韩欧美一区二区精品久久 | 狠狠插入视频 | 一级特黄录像视频免费 | 日本一级毛片高清免费观看视频 | 日韩视频 中文字幕 | 日韩高清在线免费看 | 成人国产欧美精品一区二区 | 亚洲欧美日韩国产综合高清 | 精品视频免费在线观看 | 色婷婷亚洲十月十月色天 | 国产欧美另类久久精品91 | 欧美人七十二式性视频教程一 | 国产精品久久久久aaaa | 大尺度做爰床戏呻吟免费观 | 午夜一级视频 | 永久免费不卡在线观看黄网站 |