| | |
| | | import org.apache.poi.hssf.usermodel.HSSFSheet; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.util.HSSFColor; |
| | | import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.CellStyle; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.CellValue; |
| | | import org.apache.poi.ss.usermodel.DataValidation; |
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint; |
| | | import org.apache.poi.ss.usermodel.DateUtil; |
| | | import org.apache.poi.ss.usermodel.Font; |
| | | import org.apache.poi.ss.usermodel.FormulaEvaluator; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.Name; |
| | | import org.apache.poi.ss.usermodel.RichTextString; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.VerticalAlignment; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | |
| | | Sheet sheet = getSheetByWorkbook(finalWb, sheetName); |
| | | |
| | | try { |
| | | writeDataToCell(sheet, excelDataList); |
| | | writeDataToCell(sheet, excelDataList,workbook); |
| | | } catch (VciBaseException var6) { |
| | | IOUtils.closeQuietly(os); |
| | | throw var6; |
| | |
| | | return cell; |
| | | } |
| | | |
| | | private static void writeDataToCell(Sheet sheet, List<WriteExcelData> excelDataList) throws VciBaseException { |
| | | private static void writeDataToCell(Sheet sheet, List<WriteExcelData> excelDataList,Workbook workbook) throws VciBaseException { |
| | | if (sheet != null && !CollectionUtils.isEmpty(excelDataList)) { |
| | | List<WriteExcelData> mergedDataList = new ArrayList(); |
| | | excelDataList.stream().forEach((ed) -> { |
| | |
| | | Cell cell = getCellByRow(row, ed.getCol()); |
| | | if (ed.isMerged() && (ed.getRowTo() > ed.getRow() || ed.getColTo() > ed.getCol())) { |
| | | mergedDataList.add(ed); |
| | | } |
| | | // TODO: 修改编号列为文本 |
| | | if("id".equalsIgnoreCase(ed.getObjCode())){ |
| | | //CellStyle textStyle = workbook.createCellStyle(); |
| | | HSSFDataFormat format = (HSSFDataFormat)sheet.getWorkbook().createDataFormat(); |
| | | Row copyStyleRow = sheet.getRow(ed.getRow()); |
| | | cell = copyStyleRow.getCell(ed.getCol()); |
| | | cell.getCellStyle().setDataFormat(format.getFormat("@")); |
| | | } |
| | | |
| | | copyStyle(sheet, cell, ed); |
| | |
| | | |
| | | Map<Integer, String> rowDataMap = new HashMap(); |
| | | |
| | | for(int columnIndex = 0; columnIndex < rowDataSet.getLastCellNum(); ++columnIndex) { |
| | | for(int columnIndex = 0; columnIndex < sheetDataSet.getColName().size(); ++columnIndex) { |
| | | Cell cell = rowDataSet.getCell(columnIndex); |
| | | Object value = getCellValue(cell, evaluator); |
| | | String title = colsNameIndexMap.containsKey(columnIndex) ? (String)colsNameIndexMap.get(columnIndex) : ""; |
| | |
| | | } else { |
| | | rowDataMap.put(columnIndex, VciBaseUtil.getStringValueFromObject(value)); |
| | | } |
| | | } else if (!isDataSet && thisField != null && excelColumn != null) { |
| | | if (!excelColumn.nullable()) { |
| | | throw new VciBaseException("cellValueCanNotNull", new String[]{title, rowIndex + 1 + ""}); |
| | | } |
| | | } else { |
| | | if (!isDataSet && thisField != null && excelColumn != null) { |
| | | if (!excelColumn.nullable()) { |
| | | throw new VciBaseException("cellValueCanNotNull", new String[]{title, rowIndex + 1 + ""}); |
| | | } |
| | | |
| | | if (StringUtil.isNotBlank(excelColumn.regExg())) { |
| | | throw new VciBaseException("cellValueCanNotNullForReg", new String[]{title, rowIndex + 1 + ""}); |
| | | if (StringUtil.isNotBlank(excelColumn.regExg())) { |
| | | throw new VciBaseException("cellValueCanNotNullForReg", new String[]{title, rowIndex + 1 + ""}); |
| | | } |
| | | } |
| | | rowDataMap.put(columnIndex, VciBaseUtil.getStringValueFromObject(value)); |
| | | } |
| | | } |
| | | |