使用jxl库将组合框添加到excel中

时间:2015-04-11 12:32:45

标签: java servlets jxl

我正在研究动态网络项目。 根据要求,我想准备一个包含组合框的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();
    }

}

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

0 个答案:

没有答案