Search in sources :

Example 1 with ExcelException

use of io.metersphere.exception.ExcelException in project metersphere by metersphere.

the class EasyExcelExporter method exportByCustomWriteHandler.

public void exportByCustomWriteHandler(HttpServletResponse response, List<List<String>> headList, List<List<Object>> data, String fileName, String sheetName, WriteHandler writeHandler) {
    if (CollectionUtils.isEmpty(headList)) {
        headList = new ArrayList<>();
    }
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("utf-8");
    try {
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
        EasyExcel.write(response.getOutputStream()).head(headList).registerWriteHandler(writeHandler).sheet(sheetName).doWrite(data);
    } catch (UnsupportedEncodingException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("Utf-8 encoding is not supported");
    } catch (IOException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("IO exception");
    }
}
Also used : ExcelException(io.metersphere.exception.ExcelException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 2 with ExcelException

use of io.metersphere.exception.ExcelException in project metersphere by metersphere.

the class EasyExcelExporter method exportByCustomWriteHandler.

public void exportByCustomWriteHandler(HttpServletResponse response, List<List<String>> headList, List<List<Object>> data, String fileName, String sheetName) {
    if (CollectionUtils.isEmpty(headList)) {
        headList = new ArrayList<>();
    }
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("utf-8");
    try {
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
        EasyExcel.write(response.getOutputStream()).head(headList).sheet(sheetName).doWrite(data);
    } catch (UnsupportedEncodingException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("Utf-8 encoding is not supported");
    } catch (IOException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("IO exception");
    }
}
Also used : ExcelException(io.metersphere.exception.ExcelException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 3 with ExcelException

use of io.metersphere.exception.ExcelException in project metersphere by metersphere.

the class XmindExportUtil method exportXmind.

public void exportXmind(HttpServletResponse response, TestCaseXmindData rootXmind) {
    IWorkbook workBook = this.createXmindByTestCase(rootXmind);
    response.setContentType("application/octet-stream");
    response.setCharacterEncoding("utf-8");
    try {
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("TestCaseExport", "UTF-8") + ".xmind");
        workBook.save(response.getOutputStream());
    // EasyExcel.write(response.getOutputStream(), this.clazz).registerWriteHandler(horizontalCellStyleStrategy).sheet(sheetName).doWrite(data);
    } catch (UnsupportedEncodingException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("Utf-8 encoding is not supported");
    } catch (Exception e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("IO exception");
    }
}
Also used : ExcelException(io.metersphere.exception.ExcelException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExcelException(io.metersphere.exception.ExcelException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with ExcelException

use of io.metersphere.exception.ExcelException in project metersphere by metersphere.

the class EasyExcelExporter method export.

public void export(HttpServletResponse response, List data, String fileName, String sheetName) {
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("utf-8");
    WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
    contentWriteCellStyle.setWrapped(true);
    try {
        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(null, contentWriteCellStyle);
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
        EasyExcel.write(response.getOutputStream(), this.clazz).registerWriteHandler(horizontalCellStyleStrategy).sheet(sheetName).doWrite(data);
    } catch (UnsupportedEncodingException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("Utf-8 encoding is not supported");
    } catch (IOException e) {
        LogUtil.error(e.getMessage(), e);
        throw new ExcelException("IO exception");
    }
}
Also used : WriteCellStyle(com.alibaba.excel.write.metadata.style.WriteCellStyle) ExcelException(io.metersphere.exception.ExcelException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) HorizontalCellStyleStrategy(com.alibaba.excel.write.style.HorizontalCellStyleStrategy)

Example 5 with ExcelException

use of io.metersphere.exception.ExcelException in project metersphere by metersphere.

the class TestCaseNodeService method createNodes.

public Map<String, String> createNodes(List<String> nodePaths, String projectId) {
    List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
    Map<String, String> pathMap = new HashMap<>();
    for (String item : nodePaths) {
        if (item == null) {
            throw new ExcelException(Translator.get("test_case_module_not_null"));
        }
        List<String> nodeNameList = new ArrayList<>(Arrays.asList(item.split("/")));
        Iterator<String> itemIterator = nodeNameList.iterator();
        Boolean hasNode = false;
        String rootNodeName = null;
        if (nodeNameList.size() <= 1) {
            throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + item);
        } else {
            itemIterator.next();
            itemIterator.remove();
            rootNodeName = itemIterator.next().trim();
            // 原来没有,新建的树nodeTrees也不包含
            for (TestCaseNodeDTO nodeTree : nodeTrees) {
                if (StringUtils.equals(rootNodeName, nodeTree.getName())) {
                    hasNode = true;
                    createNodeByPathIterator(itemIterator, "/" + rootNodeName, nodeTree, pathMap, projectId, 2);
                }
                ;
            }
        }
        if (!hasNode) {
            createNodeByPath(itemIterator, rootNodeName, null, projectId, 1, "", pathMap);
        }
    }
    return pathMap;
}
Also used : ExcelException(io.metersphere.exception.ExcelException) TestCaseNodeDTO(io.metersphere.track.dto.TestCaseNodeDTO)

Aggregations

ExcelException (io.metersphere.exception.ExcelException)5 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 WriteCellStyle (com.alibaba.excel.write.metadata.style.WriteCellStyle)1 HorizontalCellStyleStrategy (com.alibaba.excel.write.style.HorizontalCellStyleStrategy)1 TestCaseNodeDTO (io.metersphere.track.dto.TestCaseNodeDTO)1