excel存储到指定盘下

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段<Context path=”Welcome” docBase=”c:\hello\hello” reloadable=”true” />,该代码片段中每个属性的含义与用途是什么?


contex指上下文,实际上就是一个web项目;
path是虚拟目录,访问的时候用127.0.0.1:8080/welcom/*.jsp访问网页,welcome前面要加/;
docBase是网页实际存放位置的根目录,映射为path虚拟目录;
reloadable="true"表示你修改了jsp文件后不需要重启就可以实现显示的同步。
 
/**
	 * http://localhost:8080/CQMarketSupervise/exportEntity.do?fCheckType=&fStatus=
	 */
	@RequestMapping(value = "exportEntity", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData exportEntity(@RequestParam String fCheckType,
			@RequestParam String fStatus,HttpServletRequest request) {
		ReturnData redata = new ReturnData();
		//服务器保存路径
		String path1 = request.getSession().getServletContext().getRealPath("");
		//服务ip地址和端口
		String ip="http://"+request.getLocalAddr()+":"+request.getLocalPort();
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			
			if (fCheckType != null && !fCheckType.isEmpty()) {
				params.put("fCheckType", fCheckType );
			}
			if (fStatus != null && !fStatus.isEmpty()) {
				params.put("fStatus", fStatus);
			}
			String path=checkTaskservice.exportEntity(params,path1,ip);
			
			redata.setData(path);


		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return redata;
	}
 
 
 
/**
	 * http://localhost:8080/CQMarketSupervise/exportEntity.do?fCheckType=&fStatus=
	 */
	@RequestMapping(value = "exportEntity", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ReturnData exportEntity(@RequestParam String fCheckType,
			@RequestParam String fStatus,HttpServletRequest request) {
		ReturnData redata = new ReturnData();
		//服务器保存路径
		String path1 = request.getSession().getServletContext().getRealPath("");
		//服务ip地址和端口
		String ip="http://"+request.getLocalAddr()+":"+request.getLocalPort();
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			
			if (fCheckType != null && !fCheckType.isEmpty()) {
				params.put("fCheckType", fCheckType );
			}
			if (fStatus != null && !fStatus.isEmpty()) {
				params.put("fStatus", fStatus);
			}
			String path=checkTaskservice.exportEntity(params,path1,ip);
			
			redata.setData(path);


		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return redata;
	}
 
 
@Override
	public String exportEntity(Map<String, Object> params,String path,String ip) {
		ExcelUtil excelUtil=new ExcelUtil();
		System.out.println("list:"+checkTaskMapper.exportEntity(params).size());
		return excelUtil.exportExcel(checkTaskMapper.exportEntity(params),path,ip);
	}
 
 
 
/**
	 * 写入数据到excel
	 */
	public String exportExcel(List<Map<String,Object>> list,String path,String ip){
		try{
		WritableWorkbook wwb = null;


        // 创建可写入的Excel工作簿
        //String filePath = FileData.class.getResource("").getPath();
        //String filePath = "/CQMarketSupervise/WEB-INF/classes/com/CQMarketSupervise/data/";
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        Random random=new Random();
        String fileN="CheckTask_"+random.nextInt(1000)+"_"+dateFormat.format(new Date())+".xls";
        String fileName1="\\"+fileN;
        String fileName="D:\\oracle_c\\DATE"+fileName1;
        File file=new File(fileName);
        if (!file.exists()) {
            file.createNewFile();
        }
        //以fileName为文件名来创建一个Workbook
        wwb = Workbook.createWorkbook(file);


        // 创建工作表
        WritableSheet ws = wwb.createSheet("Test Shee 1", 0);
        
        //要插入到的Excel表格的行号,默认从0开始
        Label fEntityName= new Label(0, 0, "主体名称");//表示第
        Label fBizlicNum= new Label(1, 0, "注册号");
        Label fAddress= new Label(2, 0, "地址");
        Label fFilishUser= new Label(3, 0, "核查人");
        Label fFilishDate= new Label(4, 0, "核查时间");
        Label fResult= new Label(5, 0, "核查结果");
        
        ws.addCell(fEntityName);
        ws.addCell(fBizlicNum);
        ws.addCell(fAddress);
        ws.addCell(fFilishUser);
        ws.addCell(fFilishDate);
        ws.addCell(fResult);
        for (int i = 0; i < list.size(); i++) {
            
            Label fEntityName_i= new Label(0, i+1, list.get(i).get("fEntityName")+"");
            Label fBizlicNum_i= new Label(1, i+1, list.get(i).get("fBizlicNum")+"");
            Label fAddress_i= new Label(2, i+1, list.get(i).get("fAddress")+"");
            Label fFilishUser_i= new Label(3, i+1, list.get(i).get("fFilishUser")+"");
            Label fFilishDate_i= new Label(4, i+1, list.get(i).get("fFilishDate")+"");
            Label fResult_i= new Label(5, i+1, list.get(i).get("fResult")+"");
            ws.addCell(fEntityName_i);
            ws.addCell(fBizlicNum_i);
            ws.addCell(fAddress_i);
            ws.addCell(fFilishUser_i);
            ws.addCell(fFilishDate_i);
            ws.addCell(fResult_i);
        }
      
       //写进文档
        wwb.write();
       // 关闭Excel工作簿对象
        wwb.close();
		      return ip+"/GSfile/"+fileN;
		
		 } catch (Exception e) {
		     // TODO Auto-generated catch block
		     e.printStackTrace();
		 }
		return null;
	}
 
 <Context docBase="D:\oracle_c\DATE" path="/GSfile" reloadable="true"/><Context docBase="CQMarketSupervise" path="/CQMarketSupervise" reloadable="true" source="org.eclipse.jst.jee.server:CQMarketSupervise"/></Host>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Excel是一款功能强大的电子表格软件,能够帮助用户进行数据处理和分析。在使用Excel时,有时我们需要将数据写入公共网络盘,以便多人协作和共享数据。 要实现Excel自动写入公共网络盘,可以采取以下步骤: 1. 首先,确保你有权限访问公共网络盘。如果没有权限,需要向网络管理员申请。 2. 在Excel中,打开你要写入公共网络盘的工作簿。选择要写入的工作表。 3. 在工作表中选择或创建一个空的单元格,用于存储文件路径和名称。这个单元格将用于指定要写入的文件位置。 4. 在Excel菜单栏中选择“文件”选项,然后选择“另存为”。在弹出的对话框中,选择你的公共网络盘作为保存位置,并在文件名中指定要保存的文件名。 5. 在保存对话框中,点击“保存”按钮。Excel将自动将工作表保存到你指定的公共网络盘位置。 6. 如果你想要自动写入数据,可以使用Excel的宏功能。首先,打开开发者选项。在Excel中,点击菜单栏中的“文件”,选择“选项”,然后选择“自定义功能区”。勾选“开发者”选项卡,点击“确认”按钮。现在你可以在菜单栏中看到“开发者”选项。 7. 点击“开发者”选项卡,选择“Visual Basic”按钮。在弹出的Visual Basic编辑器中,编写一个宏来自动保存你的工作表到公共网络盘的指定位置。你可以使用VBA代码来实现这个功能。 8. 编写完宏后,保存并关闭Visual Basic编辑器。现在你可以在Excel中运行宏来自动将工作表保存到公共网络盘。 通过以上步骤,你就可以实现Excel自动写入公共网络盘的功能了。这样,你就可以方便地将数据保存到公共网络盘,以便实现多人协作和共享。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值