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++;

			}
		}

	
		
	
		
	}

좋은 웹페이지 즐겨찾기