不是吧,不是吧,你还在手写表结构信息吗
之前公司正在做到word文档生成信息这块,然后就顺手写了把数据库表结构的信息。目前只写了Oracle的版本,当然了Mysql或者其他的也差不多的事情。
目前也只是 生成如下这四个字段。
“字段”, “类型”, “数据长度”, “是否为空”, “注释”
只需要配置对应的数据库信息
server:
port: 8777
servlet:
context-path: /dbase
spring:
datasource:
name: mainDataSource
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:@***.***.***.***:1521:orcl
username: *****
password: 123456
mybatis:
mapper-locations: classpath*:com/yic/oracle_dbase/oracle/mapper/*.xml
type-aliases-package: com.yic.oracle_dbase.oracle.entity
configuration:
jdbc-type-for-null: NULL
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
部分代码
读入本地word文件,写入查询信息
String source = "static/oracle_dbase.docx";
String fileName = "OracleDbase.docx";
org.springframework.core.io.Resource fileResource = new ClassPathResource(source);
InputStream in = fileResource.getInputStream();
List<TableInfo> tableInfos = oracleMapper.queryTableInfo(userName);
tableInfos.forEach(t -> {
ColumnInfo columnInfo = new ColumnInfo("字段", "类型", "数据长度", "是否为空", "注释");
List<ColumnInfo> columnInfoList = new ArrayList<>();
columnInfoList.add(columnInfo);
List<ColumnInfo> columnInfos = oracleMapper.queryColumnInfo(t.getTableName());
columnInfoList.addAll(columnInfos);
t.setColumnInfos(columnInfoList);
});
WordUtils wordUtils = new WordUtils();
wordUtils.getWord(in, tableInfos, response, fileName);
部分查询信息代码
//创建列
CTTc ctTc = cell.getCTTc();
CTP ctP = (ctTc.sizeOfPArray() == 0) ? ctTc.addNewP() : ctTc.getPArray(0);
//设置宽度
CTTcPr ctTcPr = ctTc.addNewTcPr();
CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
ctTblWidth.setType(STTblWidth.DXA);
ctTblWidth.setW(BigInteger.valueOf(360 * 5));
//获取段落
XWPFParagraph par = cell.getParagraph(ctP);
//设置水平居中
par.setAlignment(ParagraphAlignment.CENTER);
//设置垂直居中
par.setVerticalAlignment(TextAlignment.CENTER);
XWPFRun run = par.createRun();
run.setText(oTs(value));
run.setFontFamily("新宋体");
if (i == 0) {
run.setBold(true);
run.setFontFamily("宋体");
}
效果
有想法的和我沟通! (QQ:422146969)