mh
2 days ago
23 changed files with 352 additions and 85 deletions
@ -0,0 +1,41 @@
|
||||
package com.mh.user.dto; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||
import com.alibaba.excel.annotation.write.style.ContentStyle; |
||||
import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 数据结果集基本类 |
||||
* @date 2024-07-10 16:49:24 |
||||
*/ |
||||
@Data |
||||
@HeadRowHeight(value = 20) |
||||
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)//内容样式
|
||||
public class ExportBaseResultDTO { |
||||
|
||||
@ColumnWidth(value = 18) |
||||
@ExcelProperty(value = "时间", index = 1) |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
||||
private String curDate; |
||||
|
||||
@ColumnWidth(value = 18) |
||||
@ExcelProperty(value = "瞬时流量", index = 2) |
||||
private String curValue; |
||||
|
||||
@ColumnWidth(value = 18) |
||||
@ExcelProperty(value = "项目名称", index = 0) |
||||
private String projectName; |
||||
|
||||
public ExportBaseResultDTO(String projectName, String curDate, String curValue) { |
||||
this.projectName = projectName; |
||||
this.curDate = curDate; |
||||
this.curValue = curValue; |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.mh.user.utils; |
||||
|
||||
import com.alibaba.excel.metadata.Head; |
||||
import com.alibaba.excel.write.handler.CellWriteHandler; |
||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
||||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; |
||||
import org.apache.poi.ss.usermodel.*; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 表格居中设置 |
||||
* @date 2024-11-13 15:51:21 |
||||
*/ |
||||
public class CenterCellStyleWriteHandler implements CellWriteHandler { |
||||
|
||||
@Override |
||||
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { |
||||
Workbook workbook = cell.getSheet().getWorkbook(); |
||||
CellStyle cellStyle = workbook.createCellStyle(); |
||||
|
||||
// 设置边框样式
|
||||
cellStyle.setBorderTop(BorderStyle.THIN); |
||||
cellStyle.setBorderBottom(BorderStyle.THIN); |
||||
cellStyle.setBorderLeft(BorderStyle.THIN); |
||||
cellStyle.setBorderRight(BorderStyle.THIN); |
||||
|
||||
// 设置水平居中对齐
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER); |
||||
|
||||
// 设置垂直居中对齐
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
||||
|
||||
cell.setCellStyle(cellStyle); |
||||
|
||||
System.out.println("进入到格式化表格"); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue