Commit 909368ba authored by sherlock's avatar sherlock

显示公式的问题,导入手工数据源设置

parent 69c9343c
......@@ -3,6 +3,12 @@ package pwc.taxtech.atms.controller;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -27,13 +33,7 @@ import pwc.taxtech.atms.service.impl.HttpFileService;
import pwc.taxtech.atms.service.impl.TemplateServiceImpl;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
......@@ -64,6 +64,44 @@ public class TemplateController extends BaseController {
return Collections.emptyList();
}
private InputStream handleFomularView(InputStream is){
Workbook workbook = null;
try {
workbook = new XSSFWorkbook(is);
} catch (IOException e ) {
logger.error("failed to read workbook!", e);
throw new ApplicationException("failed to read workbook!");
}
for(int i = 0; i < workbook.getNumberOfSheets(); i++){
Sheet sheet = workbook.getSheetAt(i);
for(int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++){
Row row = sheet.getRow(r);
for (int c = row.getFirstCellNum(); c <= row.getLastCellNum(); c++) {
Cell cell = row.getCell(c);
if(cell != null && !cell.getCellStyle().getLocked()){
cell.setCellValue(StringUtils.EMPTY);
}
}
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
try{
workbook.write(baos);
byte[] content = baos.toByteArray();
return new ByteArrayInputStream(content);
} catch (Exception e){
logger.error("failed write workbook!", e);
throw new ApplicationException("failed write workbook!");
} finally {
try {
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequestMapping(value = "getTemplateJson", method = RequestMethod.POST, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public @ResponseBody
void getTemplateBlob(@RequestParam(name = "templateID") Long templateId, HttpServletResponse response) throws URISyntaxException {
......@@ -95,8 +133,9 @@ public class TemplateController extends BaseController {
// while ((len = inputStream.read(buffer)) > 0) {
// out.write(buffer, 0, len);
// }
out = response.getOutputStream();
IOUtils.copy(inputStream, out);
IOUtils.copy(handleFomularView(inputStream), out);
out.flush();
} catch (FileNotFoundException e) {
......
......@@ -266,12 +266,13 @@ public class TemplateGroupServiceImpl extends AbstractService {
cellTemplate.setIsReadOnly(cell.getCellStyle().getLocked());
cellTemplateList.add(cellTemplate);
//todo: 这里没有Config数据只有在上传模板以后,在界面里面可以配置公式
if (!cell.getCellStyle().getLocked() && hasKeyIn(cell) && allowManual) {
if (!cell.getCellStyle().getLocked() && hasKeyIn(cell)) {
cell.setCellValue(StringUtils.EMPTY);
addManualConfig(cellTemplate, template, cell, now, cellTemplateConfigList);
if(allowManual){
addManualConfig(cellTemplate, template, cell, now, cellTemplateConfigList);
}
}
if(!cell.getCellStyle().getLocked() && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))
&& "${KeyIn}".equalsIgnoreCase(POIUtil.getCellFormulaString(cell))) {
if(!cell.getCellStyle().getLocked() && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))) {
CellTemplateConfig config = new CellTemplateConfig();
config.setId(distributedIdService.nextId());
config.setCellTemplateId(cellTemplate.getId());
......@@ -402,12 +403,13 @@ public class TemplateGroupServiceImpl extends AbstractService {
cellTemplate.setIsReadOnly(cell.getCellStyle().getLocked() ? true : false);
cellTemplateList.add(cellTemplate);
//todo: 这里没有Config数据只有在上传模板以后,在界面里面可以配置公式
if (!cell.getCellStyle().getLocked() && hasKeyIn(cell) && allowManual) {
if (!cell.getCellStyle().getLocked() && hasKeyIn(cell)) {
cell.setCellValue(StringUtils.EMPTY);
addManualConfig(cellTemplate, template, cell, now, cellTemplateConfigList);
if(allowManual){
addManualConfig(cellTemplate, template, cell, now, cellTemplateConfigList);
}
}
if(!cell.getCellStyle().getLocked() && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))
&& "${KeyIn}".equalsIgnoreCase(POIUtil.getCellFormulaString(cell))) {
if(!cell.getCellStyle().getLocked() && StringUtils.isNotBlank(POIUtil.getCellFormulaString(cell))) {
CellTemplateConfig config = new CellTemplateConfig();
config.setId(distributedIdService.nextId());
config.setCellTemplateId(cellTemplate.getId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment