暂降模块代码合并
终端运行管理接口调整
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.njcn.event.utils;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年08月23日 19:33
|
||||
*/
|
||||
public class EchartsUtil {
|
||||
private static final String SUCCESS_CODE = "1";
|
||||
|
||||
public static String generateEchartsBase64(String option, String port) throws IOException {
|
||||
String url;
|
||||
if (port.equals("8911")) {
|
||||
url = "http://192.168.1.13:8911";
|
||||
} else {
|
||||
url = "http://192.168.1.13:8910";
|
||||
}
|
||||
|
||||
String base64 = "";
|
||||
if (option == null) {
|
||||
return base64;
|
||||
}
|
||||
|
||||
option = option.replaceAll("\\s+", "").replaceAll("\"", "'");
|
||||
|
||||
// 将option字符串作为参数发送给echartsConvert服务器
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("opt", option);
|
||||
String response = HttpUtil.post(url, params, "utf-8");
|
||||
|
||||
// 解析echartsConvert响应
|
||||
JSONObject responseJson = JSONObject.fromObject(response);
|
||||
String code = responseJson.getString("code");
|
||||
|
||||
// 如果echartsConvert正常返回
|
||||
if (SUCCESS_CODE.equals(code)) {
|
||||
base64 = responseJson.getString("data");
|
||||
}
|
||||
// 未正常返回
|
||||
else {
|
||||
String string = responseJson.getString("msg");
|
||||
throw new RuntimeException(string);
|
||||
}
|
||||
return base64;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.event.utils;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年08月23日 19:32
|
||||
*/
|
||||
public class FreemarkerUtil {
|
||||
private static String path = FreemarkerUtil.class.getClassLoader().getResource("").getPath();
|
||||
|
||||
public static String generateString(String templateFileName, String templateDirectory, Map<String, Object> datas)
|
||||
throws IOException, TemplateException {
|
||||
Configuration configuration = new Configuration(Configuration.VERSION_2_3_0);
|
||||
|
||||
// 设置默认编码
|
||||
configuration.setDefaultEncoding("UTF-8");
|
||||
|
||||
// 设置模板所在文件夹
|
||||
path = java.net.URLDecoder.decode(path,"utf-8");
|
||||
configuration.setDirectoryForTemplateLoading(new File(path + templateDirectory));
|
||||
|
||||
// 生成模板对象
|
||||
Template template = configuration.getTemplate(templateFileName);
|
||||
|
||||
// 将datas写入模板并返回
|
||||
try (StringWriter stringWriter = new StringWriter()) {
|
||||
template.process(datas, stringWriter);
|
||||
stringWriter.flush();
|
||||
return stringWriter.getBuffer().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.event.utils;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年08月23日 19:33
|
||||
*/
|
||||
public class HttpUtil {
|
||||
|
||||
public static String post(String url, Map<String, String> params, String charset)
|
||||
throws ClientProtocolException, IOException {
|
||||
String responseEntity = "";
|
||||
|
||||
// 创建CloseableHttpClient对象
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
|
||||
// 创建post方式请求对象
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
// 生成请求参数
|
||||
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
||||
if (params != null) {
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
// 将参数添加到post请求中
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, charset));
|
||||
|
||||
// 发送请求,获取结果(同步阻塞)
|
||||
CloseableHttpResponse response = client.execute(httpPost);
|
||||
|
||||
// 获取响应实体
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
// 按指定编码转换结果实体为String类型
|
||||
responseEntity = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
EntityUtils.consume(entity);
|
||||
response.close();
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.event.utils;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import freemarker.template.TemplateException;
|
||||
import net.sf.json.JSONArray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年08月25日 08:59
|
||||
*/
|
||||
public class TestTemplate {
|
||||
public static void main(String[] args) throws IOException, TemplateException {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("subtext","区域统计");
|
||||
map.put("xname","(区域)");
|
||||
List<String> x = Stream.of("江苏省", "浙江省", "福建省").collect(Collectors.toList());
|
||||
map.put("area",JSONArray.fromObject(x).toString());
|
||||
List<Integer> on = Stream.of(149, 15, 9).collect(Collectors.toList());
|
||||
List<Integer> off = Stream.of(24, 2, 1).collect(Collectors.toList());
|
||||
map.put("onlineData",JSONArray.fromObject(on).toString());
|
||||
map.put("offlineData",JSONArray.fromObject(off).toString());
|
||||
|
||||
List<List<Double>> floatData = new ArrayList<>();
|
||||
for (int i = 0; i < 1500; i++) {
|
||||
List<Double> sub = new ArrayList<>();
|
||||
sub.add( RandomUtil.randomDouble(100.0,3, RoundingMode.UP));
|
||||
sub.add( RandomUtil.randomDouble(200.0,3, RoundingMode.UP));
|
||||
floatData.add(sub);
|
||||
}
|
||||
map.put("point",JSONArray.fromObject(floatData).toString());
|
||||
|
||||
String s = FreemarkerUtil.generateString("bar.ftl", "com/njcn/event/template", map);
|
||||
System.out.println(EchartsUtil.generateEchartsBase64(s,"8910"));
|
||||
|
||||
|
||||
|
||||
|
||||
// HashMap<String, Object> datas = new HashMap<>();
|
||||
// List<List<Double>> floatData = new ArrayList<>();
|
||||
// for (int i = 0; i < 1500; i++) {
|
||||
// List<Double> sub = new ArrayList<>();
|
||||
// sub.add( RandomUtil.randomDouble(100.0,3, RoundingMode.UP));
|
||||
// sub.add( RandomUtil.randomDouble(200.0,3, RoundingMode.UP));
|
||||
// floatData.add(sub);
|
||||
// }
|
||||
// datas.put("bdata", JSONArray.fromObject(floatData).toString());
|
||||
// String option = FreemarkerUtil.generateString("test.ftl", "com/njcn/event/template", datas);
|
||||
// System.out.println(EchartsUtil.generateEchartsBase64(option, "8910"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
package com.njcn.event.utils;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
|
||||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.TextAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFStyle;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFStyles;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
|
||||
|
||||
public class WordUtils {
|
||||
|
||||
|
||||
public static void main(String[] args)throws Exception {
|
||||
|
||||
// 空白文档
|
||||
XWPFDocument document= new XWPFDocument();
|
||||
//把文档写进本地系统
|
||||
FileOutputStream out = new FileOutputStream(new File("create_table.docx"));
|
||||
//设定标题格式
|
||||
setHeadingStyle(document);
|
||||
//添加标题
|
||||
XWPFParagraph titleParagraph = document.createParagraph();
|
||||
setParagraphStyle(titleParagraph);
|
||||
addLine(titleParagraph,11);
|
||||
//设置段落居中
|
||||
titleParagraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
XWPFRun titleParagraphRun = titleParagraph.createRun();
|
||||
addParagraph(titleParagraphRun,"宋体",15,"000000","四川省供电公司",true);
|
||||
|
||||
addLine(titleParagraph,3);
|
||||
XWPFRun titleParagraphBigRun = titleParagraph.createRun();
|
||||
addParagraph(titleParagraphBigRun,"宋体",36,"000000","电压暂降事件分析报告",true);
|
||||
addLine(titleParagraph,19);
|
||||
|
||||
XWPFRun titleParagraphDateRun = titleParagraph.createRun();
|
||||
addParagraph(titleParagraphDateRun,"宋体",14,"000000","日期: 2018年1月3号",true);
|
||||
titleParagraph.setPageBreak(true);
|
||||
|
||||
|
||||
//段落
|
||||
XWPFParagraph statisticsParagraph = document.createParagraph();
|
||||
setParagraphStyle(statisticsParagraph);
|
||||
//段前分页
|
||||
statisticsParagraph.setPageBreak(true);
|
||||
statisticsParagraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
XWPFRun statisticsRun = statisticsParagraph.createRun();
|
||||
addParagraph(statisticsRun,"宋体",24,"000000","电压暂降事件分析报告",false);
|
||||
|
||||
|
||||
|
||||
XWPFParagraph introductionParagraph= document.createParagraph();
|
||||
setParagraphStyle(introductionParagraph);
|
||||
introductionParagraph.setStyle("标题 1");
|
||||
introductionParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
XWPFRun introductionRun = introductionParagraph.createRun();
|
||||
addParagraph(introductionRun,"宋体",15,"000000","1. 引言",true);
|
||||
|
||||
XWPFParagraph introductionContentParagraph = document.createParagraph();
|
||||
// 首行缩进---段落
|
||||
setParagraphStyle(introductionContentParagraph);
|
||||
introductionContentParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
introductionContentParagraph.setIndentationFirstLine(200);
|
||||
XWPFRun introductionContentRun=introductionContentParagraph.createRun();
|
||||
addParagraph(introductionContentRun,"宋体",11,"000000","对所选中区间内电压暂降事件进行分析,能够直观清晰查看相应的暂降事件信息。",false);
|
||||
|
||||
XWPFParagraph objectParagraph=document.createParagraph();
|
||||
setParagraphStyle(objectParagraph);
|
||||
objectParagraph.setStyle("标题 1");
|
||||
objectParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
XWPFRun objectRun= objectParagraph.createRun();
|
||||
addParagraph(objectRun,"宋体",15,"000000","2. 报告分析对象:",true);
|
||||
|
||||
XWPFParagraph objectContentParagraph = document.createParagraph();
|
||||
setParagraphStyle(objectContentParagraph);
|
||||
objectContentParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
objectContentParagraph.setIndentationFirstLine(200);
|
||||
XWPFRun objectContentRun = objectContentParagraph.createRun();
|
||||
addParagraph(objectContentRun,"宋体",11,"000000","成都供电公司—>锦江区变电站—>锦江2号。",false);
|
||||
|
||||
XWPFParagraph timeParagraph = document.createParagraph();
|
||||
timeParagraph.setStyle("标题 1");
|
||||
timeParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
setParagraphStyle(timeParagraph);
|
||||
XWPFRun timeRun = timeParagraph.createRun();
|
||||
addParagraph(timeRun,"宋体",15,"000000","3. 报告分析时间:",true);
|
||||
|
||||
XWPFParagraph timeContentParagraph = document.createParagraph();
|
||||
setParagraphStyle(timeContentParagraph);
|
||||
timeContentParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
timeContentParagraph.setIndentationFirstLine(200);
|
||||
XWPFRun timeContentRun = timeContentParagraph.createRun();
|
||||
addParagraph(timeContentRun,"宋体",11,"000000","2017年12月21日至2017年12月30日。",false);
|
||||
|
||||
|
||||
XWPFParagraph summaeParagraph = document.createParagraph();
|
||||
setParagraphStyle(summaeParagraph);
|
||||
summaeParagraph.setStyle("标题 1");
|
||||
summaeParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
XWPFRun summaeRun = summaeParagraph.createRun();
|
||||
addParagraph(summaeRun,"宋体",15,"000000","4. 汇总信息:",true);
|
||||
|
||||
|
||||
XWPFParagraph summaeTableParagraph = document.createParagraph();
|
||||
setParagraphStyle(summaeTableParagraph);
|
||||
summaeTableParagraph.setStyle("标题 2");
|
||||
summaeTableParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
summaeTableParagraph.setIndentationFirstLine(200);
|
||||
XWPFRun summaeTableRun = summaeTableParagraph.createRun();
|
||||
addParagraph(summaeTableRun,"宋体",11,"000000","4.1 表格",false);
|
||||
|
||||
|
||||
//工作经历表格
|
||||
XWPFTable summaTable = document.createTable();
|
||||
|
||||
//列宽自动分割
|
||||
CTTblWidth summaTableWidth = summaTable.getCTTbl().addNewTblPr().addNewTblW();
|
||||
summaTableWidth.setType(STTblWidth.DXA);
|
||||
summaTableWidth.setW(BigInteger.valueOf(9072));
|
||||
|
||||
//表格第一行
|
||||
XWPFTableRow summaTableRowOne = summaTable.getRow(0);
|
||||
XWPFParagraph excelParagraph= document.createParagraph();
|
||||
setParagraphStyle(excelParagraph);
|
||||
excelParagraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
excelParagraph.setVerticalAlignment(TextAlignment.CENTER);
|
||||
setExcelHeadContent(excelParagraph,summaTableRowOne,"序号","暂降发生时刻","暂降幅值(%)","持续时间(ms)","暂降类型","暂降原因","严重度");
|
||||
|
||||
//表格第二行
|
||||
XWPFTableRow summaTableRowTwo = summaTable.createRow();
|
||||
setExcelContent(excelParagraph,summaTableRowTwo,"1","2017-11-24 14:26:56.490","9","20","未识别","未明","0.91");
|
||||
|
||||
//表格第三行
|
||||
XWPFTableRow summaTableRowThree = summaTable.createRow();
|
||||
setExcelContent(excelParagraph,summaTableRowThree,"2","2017-11-24 14:25:46.472","15","19","未识别","未明","0.85");
|
||||
|
||||
XWPFParagraph summaePicParagraph = document.createParagraph();
|
||||
summaePicParagraph.setStyle("标题 2");
|
||||
summaePicParagraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
summaePicParagraph.setIndentationFirstLine(200);
|
||||
XWPFRun summaePicRun = summaePicParagraph.createRun();
|
||||
addParagraph(summaePicRun,"宋体",11,"000000","4.2 ITIC曲线",false);
|
||||
|
||||
|
||||
CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
|
||||
XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
|
||||
|
||||
//添加页眉
|
||||
CTP ctpHeader = CTP.Factory.newInstance();
|
||||
CTR ctrHeader = ctpHeader.addNewR();
|
||||
CTText ctHeader = ctrHeader.addNewT();
|
||||
String headerText = "Java POI create MS word file.";
|
||||
ctHeader.setStringValue(headerText);
|
||||
XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, document);
|
||||
//设置为右对齐
|
||||
headerParagraph.setAlignment(ParagraphAlignment.RIGHT);
|
||||
XWPFParagraph[] parsHeader = new XWPFParagraph[1];
|
||||
parsHeader[0] = headerParagraph;
|
||||
policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);
|
||||
|
||||
|
||||
//添加页脚
|
||||
CTP ctpFooter = CTP.Factory.newInstance();
|
||||
CTR ctrFooter = ctpFooter.addNewR();
|
||||
CTText ctFooter = ctrFooter.addNewT();
|
||||
String footerText = "http://blog.csdn.net/zhouseawater";
|
||||
ctFooter.setStringValue(footerText);
|
||||
XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, document);
|
||||
headerParagraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
XWPFParagraph[] parsFooter = new XWPFParagraph[1];
|
||||
parsFooter[0] = footerParagraph;
|
||||
policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
|
||||
|
||||
document.write(out);
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
public static void setParagraphStyle(XWPFParagraph paragraph){
|
||||
paragraph.setSpacingBefore(100);
|
||||
paragraph.setSpacingAfter(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回指定格式的段落 居中型
|
||||
* @param document 文档对象
|
||||
*/
|
||||
public static XWPFParagraph getCenterParagraph(XWPFDocument document){
|
||||
XWPFParagraph paragraph = document.createParagraph();
|
||||
setParagraphStyle(paragraph);
|
||||
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||
paragraph.setVerticalAlignment(TextAlignment.CENTER);
|
||||
return paragraph;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回指定格式的段落 居左型
|
||||
* @param document 文档对象
|
||||
*/
|
||||
public static XWPFParagraph getLeftParagraph(XWPFDocument document){
|
||||
XWPFParagraph paragraph = document.createParagraph();
|
||||
setParagraphStyle(paragraph);
|
||||
paragraph.setAlignment(ParagraphAlignment.LEFT);
|
||||
return paragraph;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加换行符
|
||||
* @param paragraph 指定段落
|
||||
* @param amount 行数
|
||||
* */
|
||||
public static void addLine(XWPFParagraph paragraph,Integer amount){
|
||||
XWPFRun run = paragraph.createRun();
|
||||
run.setFontSize(11);
|
||||
for(int i=0;i<amount;i++){
|
||||
run.addCarriageReturn();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加段落文本
|
||||
* @param run 文本执行对象
|
||||
* @param fontFamily 字体类型
|
||||
* @param fontSize 字体大小
|
||||
* @param backgroundColor 字体颜色
|
||||
* @param bold 是否加粗
|
||||
*/
|
||||
public static void addParagraph(XWPFRun run,String fontFamily,Integer fontSize,String backgroundColor,String message,boolean bold){
|
||||
run.setText(message);
|
||||
run.setColor(backgroundColor);
|
||||
run.setFontSize(fontSize);
|
||||
run.setFontFamily(fontFamily);
|
||||
run.setBold(bold);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加自定义标题样式。这里用的是stackoverflow的源码
|
||||
*
|
||||
* @param docxDocument 目标文档
|
||||
* @param strStyleId 样式名称
|
||||
* @param headingLevel 样式级别
|
||||
*/
|
||||
public static void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {
|
||||
|
||||
CTStyle ctStyle = CTStyle.Factory.newInstance();
|
||||
ctStyle.setStyleId(strStyleId);
|
||||
|
||||
CTString styleName = CTString.Factory.newInstance();
|
||||
styleName.setVal(strStyleId);
|
||||
ctStyle.setName(styleName);
|
||||
|
||||
CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
|
||||
indentNumber.setVal(BigInteger.valueOf(headingLevel));
|
||||
|
||||
// lower number > style is more prominent in the formats bar
|
||||
ctStyle.setUiPriority(indentNumber);
|
||||
|
||||
CTOnOff onoffnull = CTOnOff.Factory.newInstance();
|
||||
ctStyle.setUnhideWhenUsed(onoffnull);
|
||||
|
||||
// style shows up in the formats bar
|
||||
ctStyle.setQFormat(onoffnull);
|
||||
|
||||
// style defines a heading of the given level
|
||||
CTPPr ppr = CTPPr.Factory.newInstance();
|
||||
ppr.setOutlineLvl(indentNumber);
|
||||
ctStyle.setPPr(ppr);
|
||||
|
||||
XWPFStyle style = new XWPFStyle(ctStyle);
|
||||
|
||||
// is a null op if already defined
|
||||
XWPFStyles styles = docxDocument.createStyles();
|
||||
|
||||
style.setType(STStyleType.PARAGRAPH);
|
||||
styles.addStyle(style);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文档中标题格式
|
||||
* */
|
||||
public static void setHeadingStyle(XWPFDocument document){
|
||||
addCustomHeadingStyle(document, "标题 1", 1);
|
||||
addCustomHeadingStyle(document, "标题 2", 2);
|
||||
addCustomHeadingStyle(document, "标题 3", 3);
|
||||
addCustomHeadingStyle(document, "标题 4", 4);
|
||||
addCustomHeadingStyle(document, "标题 5", 5);
|
||||
addCustomHeadingStyle(document, "标题 6", 6);
|
||||
addCustomHeadingStyle(document, "标题 7", 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给表格添加一行数据
|
||||
* @param paragraph 段落对象
|
||||
* @param row 行对象
|
||||
* @param data 不定长度的数据
|
||||
*/
|
||||
public static void setExcelContent(XWPFParagraph paragraph, XWPFTableRow row,String... data){
|
||||
for (int i=0;i<data.length;i++){
|
||||
XWPFRun run =paragraph.createRun();
|
||||
run.setFontFamily("宋体");
|
||||
run.setText(data[i]);
|
||||
row.getCell(i).setParagraph(paragraph);
|
||||
paragraph.removeRun(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加表头标题一行数据
|
||||
* @param paragraph 段落对象
|
||||
* @param row 行对象
|
||||
* @param data 不定长度的数据
|
||||
*/
|
||||
public static void setExcelHeadContent(XWPFParagraph paragraph, XWPFTableRow row,String... data){
|
||||
XWPFRun run= paragraph.createRun();
|
||||
run.setFontFamily("宋体");
|
||||
run.setBold(true);
|
||||
run.setText(data[0]);
|
||||
row.getCell(0).setParagraph(paragraph);
|
||||
paragraph.removeRun(0);
|
||||
for(int i=1;i<data.length;i++){
|
||||
XWPFRun run1 =paragraph.createRun();
|
||||
run1.setFontFamily("宋体");
|
||||
run1.setBold(true);
|
||||
run1.setText(data[i]);
|
||||
row.addNewTableCell().setParagraph(paragraph);
|
||||
paragraph.removeRun(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的日期
|
||||
* @return
|
||||
*/
|
||||
public static String getRightNow(){
|
||||
Calendar rightNow = Calendar.getInstance();
|
||||
Integer year = rightNow.get(Calendar.YEAR);
|
||||
Integer month = rightNow.get(Calendar.MONTH)+1;
|
||||
Integer day = rightNow.get(rightNow.DAY_OF_MONTH);
|
||||
return year+"年"+month+"月"+day+"日";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user