如何复制在apache poi excel中的下拉列表?

我将包含一个下拉列表的单元格复制到另一个单元格,但不会复制下拉列表。 如果我在ctrl + c和ctrl + v的excel文件上执行它,它会在新单元格中复制下拉列表。

有没有办法用Apache Poi复制它?
我复制包含下拉列表的单元格,但结果只是值而不是下拉列表。

我有一张表,我有下拉列表,并希望复制到另一个单元格和数据(Libro.xls)。

在这里输入图像说明

我在Excel类中有这个方法。

package es.fips; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; public class Excel { private static HSSFWorkbook workbook = null; private static FileInputStream fis = null; private static HSSFSheet sheet = null; public static boolean openExcel(String pathExcel) { // Cargar la ruta del fichero Excel. try { fis = new FileInputStream(pathExcel); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } // Linkeamos el documento excel. try { workbook = new HSSFWorkbook(fis); loadSheet(0); return true; } catch (IOException e) { e.printStackTrace(); return false; } } private static boolean loadSheet(int numHoja){ try { // Obtenemos la hoja. int hojas = workbook.getNumberOfSheets(); if((hojas-1) < numHoja){ throw new Exception("El fichero excel solo contiene "+hojas+" hojas."); }else{ sheet = workbook.getSheetAt(numHoja); return true; } } catch (Exception e) { e.printStackTrace(); return false; } } public static boolean saveChanges(String dirTemp, String name){ FileOutputStream fos = null; // Crear fichero de salida para el nuevo excel. try { fos = new FileOutputStream(dirTemp+"/"+name); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } // Los cambios realizado en la plantilla los guardamos en el nuevo excel. try { workbook.write(fos); fos.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } } public static void closeExcel(){ try { if (workbook != null) { workbook.close(); } if (fis != null) { fis.close(); } } catch (IOException e) { e.printStackTrace(); } } public static void copyCell() { // Get the source / new row. Row newRow = sheet.getRow(2);// Row number 3. Row sourceRow = sheet.getRow(2);// Row number 3. // Grab a copy of the old/new cell Cell oldCell = sourceRow.getCell(3);// Column D. Cell newCell = newRow.createCell(5);// Column F. // Copy STYLE from old cell and apply to new cell. HSSFCellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); newCell.setCellStyle(newCellStyle); // If there is a cell comment, copy. if (newCell.getCellComment() != null) { newCell.setCellComment(oldCell.getCellComment()); } // If there is a cell hyperlink, copy. if (oldCell.getHyperlink() != null) { newCell.setHyperlink(oldCell.getHyperlink()); } // Set the cell data TYPE. newCell.setCellType(oldCell.getCellType()); // Set the cell data value. switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: newCell.setCellValue(oldCell.getStringCellValue()); break; case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getStringCellValue()); break; } } } 

而我的主class:

 package es.fips; public class Main { public static void main(String[] args) { Excel.openExcel("Path/Libro.xls"); Excel.copyCell(); Excel.saveChanges("Path", "New.xls"); Excel.closeExcel(); } } 

结果(New.xls):只复制单元格的值,而不是下拉列表。

在这里输入图像说明

我想复制下拉列表,谢谢将来的答案。