当前位置:网站首页>Enterprise level development and use POI stepping on pit inventory
Enterprise level development and use POI stepping on pit inventory
2022-06-21 07:19:00 【SteveCode.】
Active address : Graduation season · The technique of attack er
- Just two years after graduation ,2020.06-2022.06 Haha, I just graduated from the epidemic area . To tell you the truth, it was really difficult to find a job when I graduated . Many small businesses have closed down because of the epidemic ! Forget about the past
The code is confidential I won't write it all for you Different business scenarios . Use the method for reference !
Today is mainly about POI In this framework
First excel It is equivalent to the table data that cannot be found in our database . Field attributes corresponding to the header . The following data corresponds to each record in the database .
I won't say the basic usage ! Let's talk about the enterprise level development process , We will encounter all kinds of situation . Summary questions :
poi Three ways to set adaptive column widths
sheet.autoSizeColumn(i); ( The version cannot be too old )
sheet.autoSizeColumn(i, true);( Merged cells use )
sheet.setColumnWidth(i, “ Name ”.getBytes().length*2*256);( Chinese applicable )
POi Report errors 2:For input string: “null”
This problem usually results in an error , How to solve ?
- Export process : Check the data in the database before exporting 、 In writing data into each cell .
if (CommUtil.notEquals("null", entry.getValue().toString())) {
cell.setCellValue(Double.valueOf(entry.getValue().toString()));
} else {
cell.setCellValue(0);
}
And so on . Just judge ···· It's rough
POi frame When importing, the cells are : Scientific counting (4.8e9)
String content;
{
// value type :
// Fix scientific counting problem
NumberFormat numberFormat = NumberFormat.getInstance();
content = numberFormat.format(cell.getNumericCellValue());
if (content.indexOf(",") >= 0) {
content = content.replace(",", "");
}
log.debug("handleRow: cell.getNumericCellValue(){}:{}",i,content);
}
Center cell contents text type
/** * The cell content is centered Text type * @param wb * @return */
private XSSFCellStyle setStyle(XSSFWorkbook wb) {
XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFDataFormat dataFormat = wb.createDataFormat();
// Text type
cellStyle.setDataFormat(dataFormat.getFormat("@"));
// Centered around
cellStyle.setAlignment(HorizontalAlignment.CENTER);
return cellStyle;
}
Set the unit to : value type ( When making statements : More important )
/** * value type * @param wb * @return */
private XSSFCellStyle setStyle(XSSFWorkbook wb) {
XSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
return cellStyle;
}
Tell you a secret
- Format the cells first - Setting the cell type ! If it's the opposite , He won't take effect Ha ha ha ** Pay attention **
// Change to numerical type
cell.setCellStyle(hssfCellStyleDouble);
// Insert the formula into the total column
cell.setCellFormula(sumString);
How to write in a cell excel Function of
Here's an example Sum the total
String colString;// The length is converted to ABC The last column
String sumString;// Summation formula
// total
int totalColumn = 0;
// Get the total number of columns
int cells = sheet.getRow(0).getPhysicalNumberOfCells();
// Get the total number
int rowNum=sheet.getLastRowNum();
// Get the total line
XSSFRow xssfRow = sheet.createRow(1);
XSSFCell cell = xssfRow.createCell(0);
cell.setCellValue(" total :");
// Traverse each column
for (int i = totalColumn, size = cells; i < size; i++) {
cell = xssfRow.createCell(i);
// The length is converted to ABC Column
colString = CellReference.convertNumToColString(i);
if (rowNum == 2) {
sumString = "SUM(" + colString + "3"+")";
} else {
// Summation formula seek 2 to Total number of lines Sum of cells
sumString = "SUM(" + colString + "3:" + colString + rowNum+1 + ")";
}
// Change to numerical type
cell.setCellStyle(hssfCellStyleDouble);
// Insert the formula into the total column
cell.setCellFormula(sumString);
totalColumn++;
}
Cell settings drop-down
/** * Set the drop-down box * @param sheet Appoint sheet page * @param values The value of the drop-down box * @param firstRow Start line number * @param lastRow Terminate line number * @param firstCol Starting column number * @param lastCol Terminate column number */
public static void setDropDownBox(XSSFSheet sheet, String[] values, Integer firstRow, Integer lastRow,
Integer firstCol, Integer lastCol) {
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(
values);
CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);
DataValidation validation = dvHelper.createValidation(dvConstraint, addressList);
// These two rows set that the cells can only be the contents of the list , Otherwise, the report will be wrong
validation.setSuppressDropDownArrow(true);
validation.setShowErrorBox(true);
sheet.addValidationData(validation);
}
Import / export interface Try to use void Ha
Later I met bug I will continue to add and Tell us the solution
You can actually import and export data through reflection annotation solution . I will give you time later Publish a version
Active address : Graduation season · The technique of attack er
边栏推荐
- MySQL MHA
- [QT] article summarizes the MSVC compilation suite in qtcreator
- 2022 运维故障案例经验
- 操作成功的提示信息动态添加
- 2022年6月13日面试被问到面试题目
- IDM mobile terminal function upgrade description
- Black technology, real-time voice simulation
- 数学是用于解决问题的工具
- C language program design - Sanzi chess (semester homework)
- Pinia advanced: elegant setup (functional) writing + encapsulation into your enterprise project
猜你喜欢

Bol Bohr's original dual currency driving model leads the new hotspot of dfi+nft+web3.0

Weather forecast applet source code / weather wechat applet source code

Postman发布API文档

Postman publishing API documentation

【FPGA小波变换】基于FPGA的图像9/7整数小波变换verilog实现

Kubernetes pod的生命周期

Easyexcel exclude display field-02

微信小程序_3,WXML模板语法

Life cycle of kubernetes pod

Google Earth Engine(GEE)——美国本土岩性数据集
随机推荐
[QT] article summarizes the MSVC compilation suite in qtcreator
C skill tree evaluation
布隆过滤器
什么是Eureka?Eureka能干什么?Eureka怎么用?
Google Earth Engine(GEE)——美国本土岩性数据集
[OSG] OSG development (03) -- build the osgqt Library of MSVC version
(programming exercises of various regular numbers) the prime number in the output range, the factorization prime factor of an integer, the maximum common divisor and minimum common multiple of two num
Yield Guild Games 与 Walken 达成合作
matplotlib子图美化操作
缺失数据填补数据集介绍(2)——多种数据集介绍及数据集预处理(mushroom、news、spam、wine-red和yeast)
数据库与缓存数据一致性问题
Four necessary steps for building a digital factory
win10上vs2017配置Eigen3开发环境
數據分析之:不同行業的常見指標
What is Eureka? What can Eureka do? How does Eureka work?
Vite + whistle: a development environment proxy solution once and for all
Wechat applet_ 5. Global configuration
@nonnull annotation of Lombok
产品经理精通Axure工具篇
模拟手机设备长按事件