We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Excel导入的时候怎么获取sheet内单元格的样式,比如水平居中、垂直居中这种
The text was updated successfully, but these errors were encountered:
目前读的时候没法获取单元格样式, 可以配合POI进行读取,但不保证性能, 参考Demo如下:
... FileInputStream fis = new FileInputStream(fileName); Workbook workbook = new XSSFWorkbook(fis); Sheet sheet = workbook.getSheetAt(0); EasyExcel.read(fileName, DemoData.class, new ReadListener<DemoData>() { @Override public void invoke(DemoData data, AnalysisContext context) { // 获取行号 int rowIndex = context.readRowHolder().getRowIndex(); System.out.println("读取到数据: " + data); // 通过 POI 获取对应行和列的样式 XSSFRow row = (XSSFRow) sheet.getRow(rowIndex); if (row != null) { int cellNumCount = row.getPhysicalNumberOfCells(); int cellIndex = 0; XSSFCell cell = row.getCell(cellIndex); if (cell != null) { CellStyle cellStyle = cell.getCellStyle(); HorizontalAlignment horizontalAlignment = cellStyle.getAlignment(); VerticalAlignment verticalAlignment = cellStyle.getVerticalAlignment(); // 输出样式信息 System.out.println("共有 " + cellNumCount + " 列"); System.out.println("第 " + (rowIndex + 1) + " 行第" + (cellIndex + 1) + "列的水平对齐方式: " + horizontalAlignment); System.out.println("第 " + (rowIndex + 1) + " 行第" + (cellIndex + 1) + "列的垂直对齐方式: " + verticalAlignment); } } } /** * if have something to do after all analysis * * @param context */ @Override public void doAfterAllAnalysed(AnalysisContext context) { } }).sheet().doRead(); workbook.close(); fis.close(); ...
Sorry, something went wrong.
jieyangxchen
No branches or pull requests
Excel导入的时候怎么获取sheet内单元格的样式,比如水平居中、垂直居中这种
The text was updated successfully, but these errors were encountered: