使用poi來生成excel,遇到的了一個坑。
sheet頁的名字最后面加上了業務id,肯定是不一樣的。但是在創第二個sheet時就是報sheet name已存在。
原因是我創建的sheet name的固定前綴太長了,最長不能超過32位,超過了會被自動截取為32位。
public boolean doesContainsSheetName(String name, int excludeSheetIdx) { String aName = name; if(name.length() > 31) { aName = name.substring(0, 31); } for(int i = 0; i < this.boundsheets.size(); ++i) { BoundSheetRecord boundSheetRecord = this.getBoundSheetRec(i); if(excludeSheetIdx != i) { String bName = boundSheetRecord.getSheetname(); if(bName.length() > 31) { bName = bName.substring(0, 31); } if(aName.equalsIgnoreCase(bName)) { return true; } } } return false; }