ext 导入excel 导出 excel

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

			}
		}

	
		
	
		
	}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值