合并连续单元格在Excel中具有相同值的列

我有一些数据要写入Excel工作表。 我已经完成了这一部分。 现在我想第一列的连续单元格具有相同的值来合并。 我不知道如何通过编码来合并单元格。 我使用apache-poi

以下是我的代码。

HSSFWorkbook wb = new HSSFWorkbook(); String fromAddress,toAddress; HSSFSheet sheet = wb.createSheet("Report 1"); SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); short dateFormat = wb.createDataFormat().getFormat("dd-MM-yyyy HH:mm:ss"); SimpleDateFormat dateFormatter1 = new SimpleDateFormat("dd/MM/yyyy-HH:mm:ss"); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(0); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Proposal No.")); cell = row.createCell(1); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Equipment Name")); cell = row.createCell(2); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Quantity Ordered")); cell = row.createCell(3); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Invoice")); cell = row.createCell(4); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Total Invoice Value")); cell = row.createCell(5); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Quantity Dispatched")); cell = row.createCell(6); cell.setCellStyle(headerCellStyle); cell.setCellValue(new HSSFRichTextString("Balance Quantity")); DispatchReports dispatchSummery=new DispatchReports(); if (dispatchSummery != null) { dispatchList = dispatchSummery.dispatchSummery(); } DispatchReports dispatchSummeryExtend=new DispatchReports(); if (dispatchSummeryExtend != null) { dispatchListExtended = dispatchSummeryExtend.dispatchSummeryExtended(); } int tempCount = 1; 

//数据填充从这里开始

  for (int key = 0; key < dispatchList.size(); key++) { try { CmaDispatchEquipmentDetails ws = new CmaDispatchEquipmentDetails(); int cellnum = 0; HSSFRow row1 = sheet.createRow(tempCount++); ws = (CmaDispatchEquipmentDetails) dispatchList.get(key); HSSFCell cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getCmaId().getCmaNo())); cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getEquipmentname())); cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getQtyordered())); cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getInvoice())); cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getTotalinvoicevalue())); cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getQtydispatched())); cell1 = row1.createCell(cellnum++); cell1.setCellValue(new HSSFRichTextString("" + ws.getBalancedispatched())); } catch (Exception e) { e.printStackTrace(); tempCount--; continue; } } 

请帮我合并“提案号”的连续单元格 列具有相同的值。