Java 使用jxl库将combobox添加到excel中

Java 使用jxl库将combobox添加到excel中,java,servlets,jxl,Java,Servlets,Jxl,我正在从事动态web项目。 根据要求,我想准备一个包含组合框的excel文件。 我熟悉jxl库。 我正在研究servlet和jsp 我正在用servlet编写代码。我的代码如下: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getS

我正在从事动态web项目。 根据要求,我想准备一个包含组合框的excel文件。 我熟悉jxl库。 我正在研究servlet和jsp

我正在用servlet编写代码。我的代码如下:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String floderPath = getServletContext().getRealPath("");
        String lFilePath = "test1.xls";
        String filePathString = floderPath + File.separator + lFilePath;
        File lfile = new File(floderPath + File.separator + lFilePath);

      WorkbookSettings lbookSettings = new WorkbookSettings();
      WritableWorkbook lworkbook = Workbook.createWorkbook(lfile, lbookSettings);

      WritableSheet lwriSheet = lworkbook.createSheet("Documents", 0);

      //Create lable
      Label lLblName = new Label(1, 2, "chintan");

      //create list
      ArrayList<String> arrList = new ArrayList<String>();
      arrList.add("DropDown1");
      arrList.add("DropDown2");
      arrList.add("DropDown3");

      //Create cobobox
      ComboBox cb = new ComboBox();

      //create WritableCellFeatures for the combo option.
      WritableCellFeatures cellFeatures = new WritableCellFeatures();

      //bind list with WritableCellFeatures
      cellFeatures.setDataValidationList(arrList);

      //Now bind cobobox with WritableCellFeatures
      cellFeatures.setComboBox(cb);
      try {
        //Add lable in to excel  
        lwriSheet.addCell(lLblName);

        //Try to add code for add combobox into excel 
        /**
        Unable to found code for add combo into excel.
        */
    } catch (RowsExceededException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (WriteException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
      lworkbook.write();
      try {
        lworkbook.close();
    } catch (WriteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException{
HttpSession session=request.getSession();
字符串floderPath=getServletContext().getRealPath(“”);
字符串lFilePath=“test1.xls”;
String filePathString=floderPath+File.separator+lFilePath;
File lfile=新文件(floderPath+File.separator+lFilePath);
WorkbookSettings lbookSettings=新WorkbookSettings();
WritableWorkbook lworkbook=Workbook.createWorkbook(lfile,lbookSettings);
WritableSheet lwriSheet=lworkbook.createSheet(“文档”,0);
//创建标签
标签lLblName=新标签(1,2,“chintan”);
//创建列表
ArrayList arrList=新的ArrayList();
arrList.add(“下拉列表1”);
arrList.add(“DropDown2”);
arrList.add(“DropDown3”);
//创建COBOX
ComboBox cb=新ComboBox();
//为组合选项创建WritableCellFeatures。
WritableCellFeatures cellFeatures=新的WritableCellFeatures();
//使用WritableCellFeatures绑定列表
cellFeatures.setDataValidationList(arrList);
//现在使用WritableCellFeatures绑定Cobox
cellFeatures.setComboBox(cb);
试一试{
//将标签添加到excel中
lwriSheet.addCell(lLblName);
//尝试将“添加组合框”的代码添加到excel中
/**
找不到将组合添加到excel的代码。
*/
}catch(rowseceedexception e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}捕获(写入异常e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
lworkbook.write();
试一试{
lworkbook.close();
}捕获(写入异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}

如果有人知道,请指导我。

什么是chobobox?是一盒巧克力包裹的流浪汉吗?你为什么要在电子表格中这样做???@Boristeider:修复了。此外,Trololol…组合框意味着下拉列表现在我可以使用智能excel lirary在excel中添加组合框