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)文章
mybatis?plus新增(insert)數(shù)據(jù)獲取主鍵id的問題
這篇文章主要介紹了mybatis?plus新增(insert)數(shù)據(jù)獲取主鍵id的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03Java中常見的日期操作(取值、轉(zhuǎn)換、加減、比較)
本文給大家介紹java中常見的日期操作,日期取值、日期轉(zhuǎn)換、日期加減、日期比較,對java日期操作相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-12-12Java中使用DOM4J生成xml文件并解析xml文件的操作
這篇文章主要介紹了Java中使用DOM4J來生成xml文件和解析xml文件的操作,今天通過代碼給大家展示了解析xml文件和生成xml文件的方法,需要的朋友可以參考下2021-09-09