I used gxt2.5, java1.7, oracle 11g, MyBatis. I want upload and update into a database using jxsl.
excel.xsl or excel.xlsx https://i.sstatic.net/Bk5As.jpg
mapping.xml
<?xml version="1.0" encoding="UTF-8"?>
<workbook>
<worksheet name="Sheet1">
<loop startRow="3" endRow="3" items="listFile" var="listFile"
varType="com.app.test.server.vo.listVO"
<section startRow="3" endRow="3">
<mapping row="3"col="0">listFile.a</mapping>
<mapping row="3" col="1">listFile.b</mapping>
<mapping row="3" col="2">listFile.c</mapping>
<mapping row="3" col="3">listFile.d</mapping>
<mapping row="3" col="4">listFile.e</mapping>
<mapping row="3" col="5">listFile.f</mapping>
<mapping row="3" col="6">listFile.g</mapping>
</section>
<loopbreakcondition>
<rowcheck offset="0">
<cellcheck offset="0">listFile.b</cellcheck>
</rowcheck>
</loopbreakcondition>
</loop>
</worksheet>
I don't know loopbreakcondition. I want break when listFile.b is null. Because, listFile.b is PK.
controller.java
private ClassPathResource uploadFileTemplate = new ClassPathResource("mapping.xml", getClass());
@RequestMapping(value = "/imp/XlsListImport.do")
public String handleFormUpload(@RequestParam("file") MultipartFile file,
@ModelAttribute("listVO") listVO listVo,
Model model, final HttpServletRequest request) throws InvalidFormatException, IOException,
SAXException {
listVo = new listVO();
model.addAttribute(listVo);
if (listExcelService == null) {
WebApplicationContext wac = WebApplicationContextUtils.
getRequiredWebApplicationContext(request.getSession().getServletContext());
listExcelService = (ListExcelService) wac.getBean("ListExcelService" );
}
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
InputStream fis = null;
String sResult = "";
Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator();
while (itr.hasNext()) {
Entry<String, MultipartFile> entry = itr.next();
file = entry.getValue();
if (!"".equals(file.getOriginalFilename())) {
if (file.getOriginalFilename().endsWith(".xls")
|| file.getOriginalFilename().endsWith(".XLS") ) {
try {
fis = file.getInputStream();
excelService.updateXls(fis);
sResult = "success";
} catch(Exception e) {
e.printStackTrace();
sResult = "error";
} finally {
if (fis != null)
fis.close();
}
} else if ( file.getOriginalFilename().endsWith(".xlsx")
|| file.getOriginalFilename().endsWith(".XLSX")) {
try {
fis = file.getInputStream();
excelService.updateXls(fis);
sResult = "success";
} catch(Exception e) {
e.printStackTrace();
sResult = "error";
} finally {
if (fis != null)
fis.close();
}
}else{
logger.info(" Only xls, xlsx... check file extension");
sResult = "success";
}
}
}
listExcelRead.read(uploadFileTemplate, file, model);
System.out.println(listVo);
System.out.println(listVo.getListVo());
return sResult;
}
listExcelRead.java
public XLSReadStatus read(Resource templateFile, MultipartFile file,
Model model) throws InvalidFormatException, IOException, SAXException {
return read(templateFile, file, model.asMap());
}
public XLSReadStatus read(Resource templateFile, MultipartFile file,
Map<?, ?> model) throws InvalidFormatException, IOException, SAXException {
InputStream inputXML = null;
InputStream inputXLS = null;
try {
inputXML = new BufferedInputStream(templateFile.getInputStream());
XLSReader mainReader = ReaderBuilder.buildFromXML(inputXML);
inputXLS = new BufferedInputStream(file.getInputStream());
return mainReader.read(inputXLS, model);
} finally {
IOUtils.closeQuietly(inputXML);
IOUtils.closeQuietly(inputXLS);
}
}
Try with the following loop break condition
<loopbreakcondition>
<rowcheck offset="0">
<cellcheck offset="1"/>
</rowcheck>
</loopbreakcondition>
So you instructing to check the cell in column B (offset=1) where your listFile.b field is and break the loop when the value in this cell is empty.