|
|
|
@ -10,6 +10,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.DefaultIndexedColorMap;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFColor;
|
|
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -48,28 +49,22 @@ public class TestExportExcel {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static List<Record> getTableDataByJobId(int job_id, String table_name) {
|
|
|
|
|
String sql = "select * from " + table_name + " where job_id=?";
|
|
|
|
|
String sql = "select * from " + table_name + " where job_id = ?";
|
|
|
|
|
return Db.find(sql, job_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
//读取库
|
|
|
|
|
HikariCpPlugin hp = new HikariCpPlugin("jdbc:postgresql://10.10.14.71:5432/szjz_db", "postgres",
|
|
|
|
|
"DsideaL147258369", "org.postgresql.Driver");
|
|
|
|
|
hp.start();
|
|
|
|
|
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
|
|
|
|
arp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
arp.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:生成简单的数据汇集EXCEL
|
|
|
|
|
*
|
|
|
|
|
* @param job_id
|
|
|
|
|
* @param filePath
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public static void getSummaryExcel(int job_id, String filePath) throws IOException { //给定任务编号,获取它有哪些表
|
|
|
|
|
// 创建工作簿和工作表
|
|
|
|
|
SXSSFWorkbook workbook = new SXSSFWorkbook();//默认100行,超100行将写入临时文件
|
|
|
|
|
workbook.setCompressTempFiles(false); //是否压缩临时文件,否则写入速度更快,但更占磁盘,但程序最后是会将临时文件删掉的
|
|
|
|
|
|
|
|
|
|
//给定任务编号,获取它有哪些表
|
|
|
|
|
int job_id = 8;
|
|
|
|
|
|
|
|
|
|
//开始生成EXCEL
|
|
|
|
|
List<Record> allSheet = getAllSheetByJobId(job_id);
|
|
|
|
|
for (Record rSheet : allSheet) {
|
|
|
|
@ -87,7 +82,7 @@ public class TestExportExcel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取数据
|
|
|
|
|
List<Record> data = getTableDataByJobId(job_id,table_name);
|
|
|
|
|
List<Record> data = getTableDataByJobId(job_id, table_name);
|
|
|
|
|
Sheet sheet = workbook.createSheet(sheet_name);
|
|
|
|
|
// 创建单元格样式对象
|
|
|
|
|
CellStyle headerStyle = workbook.createCellStyle();
|
|
|
|
@ -171,7 +166,20 @@ public class TestExportExcel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存Excel文件
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream("c:/example.xlsx");
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(filePath);
|
|
|
|
|
workbook.write(outputStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
//读取库
|
|
|
|
|
HikariCpPlugin hp = new HikariCpPlugin("jdbc:postgresql://10.10.14.71:5432/szjz_db", "postgres",
|
|
|
|
|
"DsideaL147258369", "org.postgresql.Driver");
|
|
|
|
|
hp.start();
|
|
|
|
|
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
|
|
|
|
arp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
arp.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|