午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

Java生成表格圖片的實(shí)例代碼

瀏覽:125日期: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);//寫標(biāo)題String title = '【指標(biāo)完成進(jìn)度】';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日','累計(jì)用戶數(shù)','目標(biāo)值','完成進(jìn)度','時(shí)間進(jìn)度', '進(jìn)度差異'}, {'掌廳客戶端(戶)','469281','1500000','31.2%','33.6%', '-2.4%'}};String[][] tableData2 = {{'8月31日(戶)','新增用戶數(shù)','日訪問量','累計(jì)用戶數(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生成表格圖片的實(shí)例代碼

以上就是Java生成表格圖片的實(shí)例代碼的詳細(xì)內(nèi)容,更多關(guān)于Java生成表格圖片的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 欧美黄色录像视频 | 你懂的在线视频 | 亚洲黄色一级 | 亚洲无限看 | 午夜剧场在线 | 在线看v| 免费欧美一级 | 伊人久久大香线蕉成人综合网 | 一区二区三区四区视频 | 伊人久久精品 | 日韩欧美视频在线 | 欧美做受高潮中文字幕 | 亚洲一区第一页 | 国产午夜大片 | 天堂网中文在线观看 | 一级黄色片网站 | 成人h视频在线观看 | 亚洲国产精品激情在线观看 | 色网免费 | 成人观看视频 | 亚洲婷婷免费 | 四虎成人永久免费视频 | 亚洲日本色| 91免费福利视频 | jizz性欧美23| 美国做爰xxxⅹ性视频 | 欧美一级片免费观看 | 欲色| 啪啪影音 | 一级免费黄色录像 | 哪个网站可以看毛片 | 91狠狠综合久久久久久 | 亚洲a网 | 欧美小视频在线 | 国内久久精品 | 中文字幕视频网站 | 成人欧美激情 | www亚洲国产 | 涩涩网站在线观看 | 成人p站在线观看 | 亚洲成年人网站在线观看 |