java生成表格图片(请假条)

package table;import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;public class TestTable {BufferedImage image;void createImage(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 void graphicsGeneration() {//实际数据行数+标题+备注int totalrow = 4;int totalcol = 6;int imageWidth = 2024;int imageHeight = totalrow * 40 + 20;int rowheight = 40;int startHeight = 10;int startWidth = 10;int colwidth = (int) ((imageWidth - 20) / totalcol);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, imageWidth - 5, startHeight + (j + 1) * rowheight);}//末行graphics.setColor(Color.black);graphics.drawLine(startWidth, imageHeight - 90, imageWidth - 5, imageHeight - 90);//画竖线for (int k = 0; k < totalcol; k++) {graphics.setColor(Color.black);graphics.drawLine(startWidth + k * colwidth, startHeight + rowheight, startWidth + k * colwidth, imageHeight - 50);}//末列graphics.setColor(Color.black);graphics.drawLine(imageWidth - 5, startHeight + rowheight, imageWidth - 5, imageHeight - 50);//设置字体Font font = new Font("华文楷体", Font.BOLD, 20);graphics.setFont(font);//写标题String title = "警员请假单";graphics.drawString(title, imageWidth / 3 + startWidth, startHeight + rowheight - 10);font = new Font("华文楷体", Font.BOLD, 18);graphics.setFont(font);//写入表头String[] headCells = {"账号", "姓名", "请假内容", "开始时间", "结束时间","审核意见"};for (int m = 0; m < headCells.length; m++) {graphics.drawString(headCells[m].toString(), startWidth + colwidth * m + 5, startHeight + rowheight * 2 - 10);}//设置字体font = new Font("华文楷体", Font.PLAIN, 16);graphics.setFont(font);String[][] cellsValue = {{"20182012", "陈雅丽", "2012-11-12", "2012-11-13", "头疼,前往中心医院检查,请假一天","同意!注意身体"}};//写入内容for (int n = 0; n < cellsValue.length; n++) {String[] arr = cellsValue[n];for (int l = 0; l < arr.length; l++) {graphics.drawString(cellsValue[n][l].toString(), startWidth + colwidth * l + 5, startHeight + rowheight * (n + 3) - 10);}}font = new Font("华文楷体", Font.BOLD, 18);graphics.setFont(font);graphics.setColor(Color.RED);//写备注String remark = "此图片可作为请假凭据,请保存至本地!";graphics.drawString(remark, startWidth, imageHeight - 30);createImage("d:\\test.jpg");}}

效果图:

ok了,至于如何应用到web项目中,应该大家都会了,如果有想了解的,可以评论,我会立刻出一个web请假系统生成请假单的例子。最后,别忘了点赞关注6666.

java生成表格图片(请假条为例)相关推荐

  1. java生成表格图片

    为什么80%的码农都做不了架构师?>>>    主要代码: /*** 生成图片* @param cellsValue 以二维数组形式存放 表格里面的值* @param path 文件 ...

  2. java生成表格图片_java生成表格图片

    主要代码: /** * 生成图片 * @param cellsValue 以二维数组形式存放 表格里面的值 * @param path 文件保存路径 */ public void myGraphics ...

  3. java生成表格图片,使用Graphics

    实现代码 package com.xjj.modules.test;import com.xjj.modules.redem.form.RedeemConfirmationModel; import ...

  4. Python数据展示 - 生成表格图片

    前言 本文来讲讲如何用Python生成表格图片. 选一个合适库 Python最大的优点就是第三方库丰富,基本你要什么功能,都能找到别人实现好的库,几行代码一调用就完事了. Pytable 最先找到的是 ...

  5. 致敬Gif之父,使用Java生成Gif图片

    点击关注强哥,查看更多精彩文章呀 哈喽,大家好,我是强哥. 据美国媒体报道,美国计算机科学家.GIF图像格式发明人斯蒂芬•威尔海特(Stephen Wilhite)于当地时间3月14日因新冠肺炎去世, ...

  6. JAVA通过Graphics2D生成表格图片

    目录 一.背景 二.效果图 三.主要类 四.环境要求 五.完整代码 一.背景 由于钉钉机器人目前不支持发送表格消息,所以想通过Graphics2D绘制表格生成图片文件后转Base64发送,在参考了其他 ...

  7. java生成小图片_JAVA生成缩略小图片类

    JAVA生成缩略小图片类 java.awt.image.BufferedImage是缓冲图片类主要将生成的图片对象缓冲起来:javax.imageio.ImageIO是图片IO控制类,可以将缓冲图片对 ...

  8. Java生成随机图片验证码工具类

    一.第一种生成随机图片验证码 public class VerifyCodeUtil {//生成随机数据的数据源 public static final String VERIFY_CODES = & ...

  9. java生成条码图片、打印二维码、图片合并、图片加文字

    通过java生成二维码图片,可以添加文字内容,非常方便实现打印. import java.awt.Color; import java.awt.Font; import java.awt.FontMe ...

最新文章

  1. NLP分词数据准备及模型训练实例
  2. RPA有哪些优点和缺点?
  3. Softmax回归——logistic回归模型在多分类问题上的推广
  4. CSS 盒子的边距塌陷
  5. SAP Spartacus My Company list focus事件触发后,控件border的默认效果
  6. 数据结构之图的存储结构二及其实现
  7. SSM整合项目实践——完成图书的CRUD
  8. NSUserDefaults 、对象归档
  9. 杂读 May 12,2008
  10. get buffer from CMSampleBufferRef
  11. set,env,export,set -x,set -e;
  12. Python递归的几个经典案例
  13. maven for Mac配置,idea 配置maven
  14. vba 宏获取文件夹中所有excel文件,对slk文件数据每3000个求平均值
  15. 典型ARM嵌入式Linux设备启动流程-S3C2440,S5PV210,AM3352x
  16. 第二人生的源码分析(三十九)关闭WinXP的错误报告功能
  17. MongoDB World 2016参会全记录
  18. Windows资源管理器已停止工作的两种解决方法
  19. 【网易笔试】小易最近在数学课上学习到了集合的概念
  20. 在windows中使用bat脚本获取linux服务器文件

热门文章

  1. COTS应用程序开发框架简介(三)
  2. 编程番外篇:Rider体验与常用功能分享
  3. Ghost的使用方法
  4. experience(1):一个博士的经历(小木虫精华帖)
  5. 【Web开发】良心教程视频推荐
  6. dedeCMS采集规则各大CMS采集规则通用
  7. Tensorflow针对CPU的编译优化加速-解决Not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
  8. GBase 8s HAC高可用方案
  9. 只是有一天freeeim
  10. 基于stm32的模拟楼道光控开关的实验