In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to do if POI copy EXCEL cell style fails. Many people may not know much about it. In order to let you know more, Xiaobian summarizes the following contents for you. I hope you can gain something according to this article.
XSSFCell Two ways to copy cell styles
1. Load the original cell style directly into the new cell
XSSFRow newRow = sheet.createRow(row + 5);for (int cell = 0; cell < maxCellNum; cell++) { XSSFCell newCell = newRow.createCell(cell); newCell.setCellStyle(sheet.getRow(5).getCell(cell).getCellStyle());}
Copy a new style using CellStyle's cloneStryleFrom method
XSSFRow newRow = sheet.createRow(row + 5);for (int cell = 0; cell < maxCellNum; cell++) { XSSFCell newCell = newRow.createCell(cell); CellStyle cStyle = workbook.createCellStyle(); cStyle.cloneStyleFrom(newCell.getCellStyle()); newCell.setCellStyle(cStyle);}
The second method is recommended in general, and method one may cause cell styles to be overwritten.
Problem background: through excel template, specific data will be filled into the corresponding cells to generate a list of goods file. The template is as follows (for intuitive purposes, the last two columns of background colors are set to orange and red for easy comparison)
The final excel file is as follows
The problem encountered this time is that cells cannot be styled properly using either of the above methods.
After investigation, it was found that the style was not assigned to the last cell in each row, so the style would not take effect. The last cell in each row must be assigned a style to display the style normally.
excelRow.getCell(10).setCellValue("");
The modified export file is as follows
After reading the above, do you have any further understanding of how to do if POI fails to copy EXCEL cell style? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.