ext 가져오기 excel 내보내기 excel
8551 단어 ext
@SuppressWarnings("deprecation")
@GET
@POST
@Path("/importServicesCompSegMapping")
@Produces(MediaType.APPLICATION_JSON)
public void importPartKitCompSegMapping(
@Context HttpServletRequest request,
@Context HttpServletResponse response,
@Context ServletContext servletContext) {
DiskFileUpload uploadFile = new DiskFileUpload();
uploadFile.setHeaderEncoding("utf8");
List<ServicesSegMappingVo> servicesSegmMappingList = new ArrayList<ServicesSegMappingVo>();
InputStream fileInputSteam = null;
try {
List<?> items = uploadFile.parseRequest(request);
ListIterator<?> listIterator = items.listIterator();
while (listIterator.hasNext()) {
FileItem item = (FileItem) listIterator.next();
String name = item.getName();
if (RCHelper.isExcelFile(name)) {
fileInputSteam = item.getInputStream();
Workbook workBook = Workbook.getWorkbook(fileInputSteam);
Sheet sheet = workBook.getSheet(0);
int rowCount = sheet.getRows();
// int colCount = sheet.getColumns();
Cell cell = null;
ServicesSegMappingVo servicesSegMappingVo = null;
for (int row = 1; row < rowCount; row++) {
servicesSegMappingVo = new ServicesSegMappingVo();
cell = sheet.getCell(0, row);
if (cell.getContents() != null) {
servicesSegMappingVo.setWorkItemId(cell.getContents());
}
cell = sheet.getCell(1, row);
if (cell.getContents() != null) {
servicesSegMappingVo.setWorkItemName(cell.getContents());
}
cell = sheet.getCell(2, row);
if (cell.getContents() != null) {
servicesSegMappingVo.setSegmentLevel(cell.getContents());
}
cell = sheet.getCell(3, row);
if (cell.getContents() != null) {
servicesSegMappingVo.setAllocationPeriod(cell.getContents());
}
cell = sheet.getCell(4, row);
if (cell.getContents() != null) {
servicesSegMappingVo.setEquipmentTechnology(cell.getContents());
}
cell = sheet.getCell(5, row);
if (cell.getContents() != null) {
if (!"".equals(StringUtils.nvl(cell.getContents()))) {
String[] segm = cell.getContents().split("#");
servicesSegMappingVo.setCompSegmName(segm[0]);
servicesSegMappingVo.setCompSegmId(segm[1]);
}
}
servicesSegmMappingList.add(servicesSegMappingVo);
}
// partkitSegmMappingList.size();
} else {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
SerializationConfig.Feature.WRITE_NULL_PROPERTIES,
false);
mapper.getSerializationConfig().setSerializationInclusion(
Inclusion.ALWAYS);
String errmsg = "Please upload file with extention '.XLS' or '.XLX'";
String jsonData = "{total:0,success:false,errorMessage:\""
+ errmsg + "\"}";
logger.debug(jsonData);
PrintWriter pw = response.getWriter();
pw.write(jsonData);
pw.flush();
pw.close();
}
}
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
SerializationConfig.Feature.WRITE_NULL_PROPERTIES,
false);
mapper.getSerializationConfig().setSerializationInclusion(
Inclusion.ALWAYS);
PrintWriter pw = response.getWriter();
String json = new Gson().toJson(servicesSegmMappingList);
String str = "{success:true,servicesSegmMappingList : "+json+"}";
pw.write(str);
pw.flush();
pw.close();
} catch (FileUploadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}finally {
logger.info("finally");
if (fileInputSteam != null) {
try {
fileInputSteam.close();
} catch (IOException ex) {
;
}
}
}
//return "partkitSegmMappingList";
}
js
var jsonData = Ext.JSON.decode(action.response.responseText);
//alert(jsonData.partkitSegmMappingList);
grid.store.removeAll();
grid.store.loadData(jsonData.servicesSegmMappingList);
downViewServices
fileName = "ViewServices.xls";
templatePath = "/resources/template/ViewServices.xls";// ,
try {
InputStream is = this.getClass().getResourceAsStream(
templatePath);
ViewServicesList viewServicesList;
viewServicesList = this.findServices(request, response);
List<ViewServicesVo> records = viewServicesList.getViewServicesList();
wwb = XLSUtil.getRateXlsFile(records, outputStream, is, 11);
} catch (Exception e) {
e.printStackTrace();
}
@SuppressWarnings({ "deprecation", "rawtypes", "unchecked" })
public static WritableWorkbook getRateXlsFile(List recordsList, OutputStream os, InputStream is, int reportType) throws BiffException, IOException, WriteException {
Workbook template = Workbook.getWorkbook(is);
WritableWorkbook wwb = Workbook.createWorkbook(os, template);
WritableSheet sheet = wwb.getSheet(0);
sheet.setProtected(true);
WritableCellFormat lockCF = getLockCellFormat();
WritableCellFormat unlockCF = getUnlockCellFormat();
if (reportType == RCATConstants.REPORT_LOH_SHOP_RATE) { // LOH shop rate
getRateRecord(recordsList, lockCF, unlockCF, sheet);
} else if (reportType == RCATConstants.REPORT_LOH_COMP_RATE) {
getCompRateRecord(recordsList, lockCF, unlockCF, sheet);
} else if (reportType == 3) {
// exportFinalCatalog(recordsList, lockCF, sheet);
} else if (reportType == 4) {
getViewTechnologiesRecord(recordsList, lockCF, sheet);
} else if (reportType == 5) {
getPartKitsRecord(recordsList, lockCF, sheet);
} else if (reportType == 6) {
getShopCClRecord(recordsList, lockCF, sheet);
} else if (reportType == 8) {
getRateRecord(recordsList, lockCF, unlockCF, sheet);
}else if (reportType == 10) {
getServiceCatalog(recordsList, lockCF, unlockCF, sheet);
}else if (reportType == 11) {
getServices(recordsList, lockCF, unlockCF, sheet);
}
return wwb;
}
private static void getServices(List recordsList,
WritableCellFormat lockCF, WritableCellFormat unlockCF,
WritableSheet sheet) throws BiffException, IOException, WriteException{
if (!recordsList.isEmpty()) {
Iterator<ViewServicesVo> itr = recordsList.iterator();
ViewServicesVo viewServicesVo = null;
int startRowNumber = 1;
Label cell;
while (itr.hasNext()) {
viewServicesVo = (ViewServicesVo) itr.next();
cell = new Label(0, startRowNumber, viewServicesVo.getAtaNumber(), lockCF);
sheet.addCell(cell);
cell = new Label(1, startRowNumber, viewServicesVo.getEquipTech(), lockCF);
sheet.addCell(cell);
cell = new Label(2, startRowNumber, viewServicesVo.getWorkItemId(), lockCF);
sheet.addCell(cell);
cell =new Label(3, startRowNumber, viewServicesVo.getWorkItemName(), lockCF);
sheet.addCell(cell);
cell = new Label(4, startRowNumber, viewServicesVo.getSeglevel(), lockCF);
sheet.addCell(cell);
cell = new Label(5, startRowNumber, viewServicesVo.getAllocationPeriod(), lockCF);
sheet.addCell(cell);
cell = new Label(6, startRowNumber, viewServicesVo.getCompSegName(), lockCF);
sheet.addCell(cell);
startRowNumber++;
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
ExtJS 3.2 학습 노트(3) 사용자 정의 이벤트Extjs에서 모든 상속은 Ext.util에서 합니다.Observable 클래스의 컨트롤은 이벤트를 지원할 수 있습니다. 클래스에 대해 이벤트를 사용자 정의하려면 다음 절차를 따르십시오. 1, 먼저 클래스를 정의합니...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.