POI XSSFSheet shiftRows bug問題解決
問題
業(yè)務(wù)中需要往給定格式的excel中寫入數(shù)據(jù)。
使用shiftRows函數(shù)往excel中插入新行時,xls文件沒問題,xlsx文件問題多多
- 執(zhí)行如下代碼,xls格式插入了3行,xlsx格式卻只插入了2行
- xlsx執(zhí)行shiftRows操作之后,合并單元格丟失
- xlsx執(zhí)行shiftRows操作之后,用excel打開提示格式有問題,用wps打開正常
InputStream inp = new FileInputStream("/Users/shao/Downloads/模板.xlsx");
Workbook templateWorkbook = WorkbookFactory.create(inp);
Sheet sheet = templateWorkBook.getSheetAt(0);
sheet.shiftRows(5, sheet.getLastRowNum(), 1);
sheet.shiftRows(5, sheet.getLastRowNum(), 1);
sheet.shiftRows(5, sheet.getLastRowNum(), 1);
OutputStream outputStream = new FileOutputStream("/Users/shao/Downloads/模板輸出.xlsx");
templateWorkbook.write(outputStream);解決
poi 4.1.1版本修復(fù)了該bug,升級到最新的4.1.2,問題解決
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>原因
poi bug
參考
https://stackoverflow.com/questions/55980407/apache-poi-shiftrows-corrupts-file-and-deletes-content
http://poi.apache.org/changes.html

以上就是POI XSSFSheet shiftRows bug問題解決的詳細內(nèi)容,更多關(guān)于POI XSSFSheet shiftRows bug的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于java Springboot實現(xiàn)教務(wù)管理系統(tǒng)詳解
這篇文章主要介紹了Java 實現(xiàn)簡易教務(wù)管理系統(tǒng)的代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-08-08
SpringBoot2.7?WebSecurityConfigurerAdapter類過期配置
這篇文章主要為大家介紹了SpringBoot2.7中WebSecurityConfigurerAdapter類過期應(yīng)該如何配置,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06
springboot項目中controller層與前端的參數(shù)傳遞方式
這篇文章主要介紹了springboot項目中controller層與前端的參數(shù)傳遞方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
Java調(diào)用ChatGPT API并實現(xiàn)流式接收方式(Server-Sent Events,SSE)
文章介紹如何在Java中通過OkHttp和SSE技術(shù)實現(xiàn)流式獲取ChatGPT響應(yīng),解決傳統(tǒng)HTTP阻塞問題,提升用戶體驗,需配置stream參數(shù),利用SseEmitter封裝后端推送,前端使用EventSourcePolyfill插件處理Token,同時注意資源管理和避免換行符干擾2025-08-08

