excel文件导出并上传到服务器上

本文介绍了一种将数据导出到Excel文件的方法,并通过代码示例展示了如何将这些文件上传到服务器的过程。主要内容包括设置Excel文件的基本属性如标题、文件名及sheet名称,以及使用Java进行文件操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(个人业务,将需要导出的数据,写到excel文件中并上传到相对应的服务器上)


```java
  //excel标题
            String[] title = {"用户名(非必填)", "手机号", "验证状态"};

            //excel文件名
            String fileName =  System.currentTimeMillis() + ".xls";

            //sheet名
            String sheetName = "用户导入";

            String[][] content = new String[normalList.size()][];
            for (int i = 0; i < normalList.size(); i++) {
                content[i] = new String[title.length];
                UserInfoImportVo userInfoImportVo = normalList.get(i);
                content[i][0] = userInfoImportVo.getUserName();
                content[i][1] = userInfoImportVo.getPhone();
                content[i][2] = userInfoImportVo.getMessage();
            }

            //创建HSSFWordkBook
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbookColor(sheetName, title, content, null);

           
                //创建字节输出流
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                //写入内容
                wb.write(os);
                InputStream byteArrayInputStream = new ByteArrayInputStream(os.toByteArray());
                os.close();
                //将输入流上传到服务器上就可以了(用自己公司的上传工具)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值