コード例 #1
0
  @Test
  public void testJExcelWithTemplateAndLanguage() throws Exception {
    request.setAttribute(
        DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, newDummyLocaleResolver("de", ""));

    AbstractJExcelView excelView =
        new UnixSafeAbstractJExcelView() {
          @Override
          protected void buildExcelDocument(
              Map<String, Object> model,
              WritableWorkbook wb,
              HttpServletRequest request,
              HttpServletResponse response)
              throws Exception {
            WritableSheet sheet = wb.getSheet("Sheet1");
            // test all possible permutation of row or column not existing
            sheet.addCell(new Label(2, 4, "Test Value"));
            sheet.addCell(new Label(2, 3, "Test Value"));
            sheet.addCell(new Label(3, 4, "Test Value"));
            sheet.addCell(new Label(2, 4, "Test Value"));
          }
        };

    excelView.setApplicationContext(webAppCtx);
    excelView.setUrl("template");
    excelView.render(new HashMap<String, Object>(), request, response);

    Workbook wb = Workbook.getWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
    Sheet sheet = wb.getSheet("Sheet1");
    Cell cell = sheet.getCell(0, 0);
    assertEquals("Test Template auf Deutsch", cell.getContents());
  }
コード例 #2
0
  @Test
  public void testJExcel() throws Exception {
    AbstractJExcelView excelView =
        new UnixSafeAbstractJExcelView() {
          @Override
          protected void buildExcelDocument(
              Map<String, Object> model,
              WritableWorkbook wb,
              HttpServletRequest request,
              HttpServletResponse response)
              throws Exception {
            WritableSheet sheet = wb.createSheet("Test Sheet", 0);
            // test all possible permutation of row or column not existing
            sheet.addCell(new Label(2, 4, "Test Value"));
            sheet.addCell(new Label(2, 3, "Test Value"));
            sheet.addCell(new Label(3, 4, "Test Value"));
            sheet.addCell(new Label(2, 4, "Test Value"));
          }
        };

    excelView.render(new HashMap<String, Object>(), request, response);

    Workbook wb = Workbook.getWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
    assertEquals("Test Sheet", wb.getSheet(0).getName());
    Sheet sheet = wb.getSheet("Test Sheet");
    Cell cell = sheet.getCell(2, 4);
    assertEquals("Test Value", cell.getContents());
  }