java creator 下载_ExcelWorkBookCreator.java

package com.xdj.iot.util.excelUtils;

import com.xdj.iot.util.excelUtils.processor.ExcelProcessor;

import org.apache.poi.hssf.usermodel.*;

import org.apache.poi.ss.usermodel.Font;

import javax.servlet.http.HttpServletResponse;

import java.io.*;

import java.lang.reflect.Field;

import java.net.URLEncoder;

import java.util.ArrayList;

import java.util.List;

/**

* created by chongyahhh

* 2020/2/21

*/

public class ExcelWorkBookCreator {

private String excelFileName;

private List sheets;

private HSSFWorkbook hssfWorkbook;

private final String EXCEL_SHEET_PASSWORD = "123321";

public ExcelWorkBookCreator(String excelFileName) {

this.excelFileName = excelFileName;

hssfWorkbook = new HSSFWorkbook();

sheets = new ArrayList<>();

}

public void addOneSheet(String sheetName, List> data, Class targetClass){

sheets.add(new ExcelAssistBean(hssfWorkbook,sheetName,data,targetClass));

}

public void addOneSheet(String sheetName, List> data, Class targetClass, boolean customMode){

sheets.add(new ExcelAssistBean(hssfWorkbook,sheetName,data,targetClass,customMode));

}

public void addOneSheet(String sheetName, List> data, Class targetClass, ExcelProcessor excelProcessor){

sheets.add(new ExcelAssistBean(hssfWorkbook,sheetName,data,targetClass,excelProcessor));

}

public void addOneSheet(String sheetName, List> data, Class targetClass, ExcelProcessor excelProcessor, boolean customMode){

sheets.add(new ExcelAssistBean(hssfWorkbook,sheetName,data,targetClass,excelProcessor,customMode));

}

/**

* 导出 excel

* @param response

* @return

* @throws Exception

*/

public void excelExport(HttpServletResponse response) throws Exception{

//设置文件名

response.setContentType("multipart/form-data");

response.setHeader("Content-Disposition", "attachment;fileName="+ URLEncoder.encode((excelFileName + ".xls"),"UTF-8"));

OutputStream os = response.getOutputStream();

//开始注入数据

for(int sheetIndex = 0;sheetIndex < sheets.size();sheetIndex++) {

ExcelAssistBean currentSheetMsg = sheets.get(sheetIndex);

HSSFSheet currentSheet = hssfWorkbook.createSheet(currentSheetMsg.getSheetName());

currentSheet.protectSheet(EXCEL_SHEET_PASSWORD);

ExcelProcessor excelProcessor = currentSheetMsg.getExcelProcessor();

int firstRowNum = excelProcessor.customOperationBeforeInvokeData(currentSheetMsg,currentSheet);

if(currentSheetMsg.isCustomMode()){

invokeDataUnderCustomModel(currentSheetMsg,currentSheet,firstRowNum);

} else {

invokeData(currentSheetMsg,currentSheet,firstRowNum);

}

excelProcessor.customOperationAfterInvokeData(currentSheetMsg,currentSheet,firstRowNum);

}

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

hssfWorkbook.write(outputStream);

outputStream.flush();

hssfWorkbook.close();

outputStream.close();

InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

int b = 0;

byte[] buffer = new byte[512];

while (b != -1){

b = inputStream.read(buffer);

if(b != -1){

os.write(buffer,0,b);

}

}

if(inputStream != null){

inputStream.close();

}

if(os!=null){

os.close();

os.flush();

}

}

/**

* 不开启自定义文本模式下注入正文

* @param currentSheet

* @param hssfSheet

* @param firstRowNum

* @throws Exception

*/

private void invokeData(ExcelAssistBean currentSheet,HSSFSheet hssfSheet,int firstRowNum) throws Exception{

//设置表头

HSSFRow firstRow = hssfSheet.createRow(firstRowNum);

HSSFCellStyle cellStyle = hssfWorkbook.createCellStyle();

Font titleFont = hssfWorkbook.createFont();

//加粗标题字体

titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

cellStyle.setFont(titleFont);

cellStyle.setLocked(true);

HSSFCell titleCell;

for(int titleIndex = 0;titleIndex < currentSheet.getOrderedTitles().size();titleIndex++){

titleCell = firstRow.createCell(titleIndex);

titleCell.setCellValue(currentSheet.getOrderedTitles().get(titleIndex));

titleCell.setCellStyle(cellStyle);

}

//注入数据

List> currentData = currentSheet.getData();

List fields = currentSheet.getOrderedFields();

cellStyle = hssfWorkbook.createCellStyle();

cellStyle.setLocked(true);

HSSFRow currentRow;

for(int rowIndex = 0;rowIndex < currentData.size();rowIndex++){

currentRow = hssfSheet.createRow(rowIndex + firstRowNum + 1);

HSSFCell currentCell;

Object obj = currentData.get(rowIndex);

for(int cellIndex = 0;cellIndex < fields.size();cellIndex++){

currentCell = currentRow.createCell(cellIndex);

currentCell.setCellStyle(cellStyle);

if(!fields.get(cellIndex).isAccessible()){

fields.get(cellIndex).setAccessible(true);

if(fields.get(cellIndex).get(obj) != null){

currentCell.setCellValue(fields.get(cellIndex).get(obj).toString());

}

fields.get(cellIndex).setAccessible(false);

} else {

if(fields.get(cellIndex).get(obj) != null){

currentCell.setCellValue(fields.get(cellIndex).get(obj).toString());

}

}

}

}

}

/**

* 开启自定义文本模式下注入正文

* @param currentSheet

* @param hssfSheet

* @param firstRowNum

* @throws Exception

*/

private void invokeDataUnderCustomModel(ExcelAssistBean currentSheet,HSSFSheet hssfSheet,int firstRowNum) throws Exception{

//设置表头

HSSFRow firstRow = hssfSheet.createRow(firstRowNum);

currentSheet.titleCellStyleInvoke(firstRow);

//注入数据

currentSheet.contentCellStyleInvoke(hssfSheet,firstRowNum);

}

public String getExcelFileName() {

return excelFileName;

}

public void setExcelFileName(String excelFileName) {

this.excelFileName = excelFileName;

}

public List getSheets() {

return sheets;

}

public void setSheets(List sheets) {

this.sheets = sheets;

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

root@in_dev_docker:/apollo# bash scripts/msf_create_lossless_map.sh /apollo/hdmap/pcd_apollo/ 50 /apollo/hdmap/ /apollo/bazel-bin WARNING: Logging before InitGoogleLogging() is written to STDERR E0715 22:08:35.399576 6436 lossless_map_creator.cc:162] num_trials = 1 Pcd folders are as follows: /apollo/hdmap/pcd_apollo/ Resolution: 0.125 Dataset: /apollo/hdmap/pcd_apollo Dataset: /apollo/hdmap/pcd_apollo/ Loaded the map configuration from: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. Saved the map configuration to: /apollo/hdmap//lossless_map/config.xml. E0715 22:08:35.767315 6436 lossless_map_creator.cc:264] ieout_poses = 1706 Failed to find match for field 'intensity'. Failed to find match for field 'timestamp'. E0715 22:08:35.769896 6436 velodyne_utility.cc:46] Un-organized-point-cloud E0715 22:08:35.781770 6436 lossless_map_creator.cc:275] Loaded 245443D Points at Trial: 0 Frame: 0. F0715 22:08:35.781791 6436 base_map_node_index.cc:101] Check failed: false *** Check failure stack trace: *** scripts/msf_create_lossless_map.sh: line 11: 6436 Aborted (core dumped) $APOLLO_BIN_PREFIX/modules/localization/msf/local_tool/map_creation/lossless_map_creator --use_plane_inliers_only true --pcd_folders $1 --pose_files $2 --map_folder $IN_FOLDER --zone_id $ZONE_ID --coordinate_type UTM --map_resolution_type single root@in_dev_docker:/apollo# bash scripts/msf_create_lossless_map.sh /apollo/hdmap/pcd_apollo/ 50 /apollo/hdmap/
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值