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");
}
}
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");
}
}
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");
}
}
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");
}
}
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;
}
Aggregations