批量生成随机字符串并保存到excel
需要导入jxl.jar,commons-lang-2.6.jar
链接:https://pan.baidu.com/s/1NPPh24XWxkka68x2JQYlYA
提取码:jvj3
链接:https://pan.baidu.com/s/1d68GzCbXFIx41uPiWZpAkg
提取码:z2az
package exceldemo; import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random; import org.apache.commons.lang.RandomStringUtils;
import org.junit.Test; import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException; /**
*
* @author csh
* 批量创建随机字符串并保存到excel
*/ public class JxlWriteDemo { public static void main(String[] args) throws IOException, WriteException {
Random r = new Random();
Date date = new Date();
// String curdate = date.toString();
DateFormat df6 = new SimpleDateFormat("yyMMddhhmmss");
String formatdate = df6.format(date);
File fileDir=new File("D:\\exceldata");
if(!fileDir.exists()){
fileDir.mkdir();
}
File xlsFile = new File("D:\\exceldata\\jxl" + formatdate + ".xls"); // 创建一个工作簿
WritableWorkbook workbook = Workbook.createWorkbook(xlsFile);
// 创建一个工作表
WritableSheet sheet = workbook.createSheet("sheet1", 0);
// 设置titles
String[] titles = { "卡号" };
// 设置单元格
Label label = null;
// 给第一行设置列名
for (int i = 0; i < titles.length; i++) {
// x,y,第一行的列名
Label lable = new Label(i, 0, titles[i]);
// 添加单元格
sheet.addCell(lable); } for (int row = 1; row < 3000; row++) {
for (int col = 0; col < 1; col++) {
// //获取当前时间的时间戳
// long currentTimeMillis = System.currentTimeMillis();
// 生成三位随机整数
int rundomInt = r.nextInt(999);
// 如果不足三位前面补0
String vipCode = String.format("%03d", rundomInt); // 随机生成字符串
String filename = RandomStringUtils.randomAlphanumeric(10);
// 随机字符串+日期,生成激活码
String code = filename + formatdate;
// 向工作表中添加数据
sheet.addCell(new Label(col, row, "VIP" + filename + vipCode));
}
}
workbook.write();
workbook.close(); }
}
批量生成随机字符串并保存到excel的更多相关文章
- 将数字n转换为字符串并保存到s中
将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各 ...
- Sql数据保存到Excel文件中
public string ExportExcel( DataSet ds,string saveFileName) { try { if (ds == null) return "数据库为 ...
- 调用获取学生信息的接口,保存到excel里面
# 2.http: // doc.nnzhp.cn / index.php?s = / 6 & page_id = 14# 调用获取学生信息的接口,保存到excel里面 import requ ...
- 调用获取学生信息的接口,保存到excel里面的小程序
# 2.http: // doc.nnzhp.cn / index.php?s = / 6 & page_id = 14# 调用获取学生信息的接口,保存到excel里面 import requ ...
- 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间
生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...
- 用python实现批量获取Linux主机简要信息并保存到Excel中 unstable 1.1
#!/usr/bin/env python3 # -*- coding: utf-8 -*- #filename get_linux_info.py #获取Linux主机的信息 # titles=[' ...
- Java中生成随机字符的方法总结
package learnExercise; public class RandomCharacter { public static char getRandomCharacter(char ch1 ...
- 利用Masscan批量生成随机ip地址表
简介 Masscan是Kali下集成的高效扫描器,和nmap命令有很多相似之处 命令生成随机ip masscan -sL 10.0.0.0/24 > c段.txt masscan -sL 10. ...
- python 批量修改预定字符串并将修改后的字符串插入文件指定位置
下面的例子是在文件的指定位置增加指定字符串的例子 修改配置文件: def add_str(pre_str): lines = [] flag = True f = open("z.txt&q ...
随机推荐
- UVA10056 - What is the Probability ?(概率)
UVA10056 - What is the Probability ? (概率) 题目链接 题目大意:有n个人玩游戏,一直到一个人胜出之后游戏就能够结束,要不然就一直从第1个到第n个循环进行,没人一 ...
- Bootstrap button源码分析
/* ======================================================================== * Bootstrap: button.js v ...
- linux进程间通信——netlink【转】
本文转载自:http://blog.csdn.net/wangyuling1234567890/article/details/21561457 今天在看用户态与内核态通信相关东西时,发现了关于net ...
- 控件CListCtr详解
1.CListCtrl控件 CListCtrl控件在数据库编程中是用得比较多的控件之一,也是Window控件中较难掌握的一个控件.他可以有四显示方式,Report.List.Icon.SmallIco ...
- Windows路径
绝对路径 是从盘符开始的路径,形如 C:\windows\system32\cmd.exe 相对路径 是从当前目录开始的路径,假如当前目录为C:\windows 要描述上述路径,只需输入 system ...
- bzoj2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 构建分层图. 代码如下: 写法1(空间略大)(时间很慢): #include<i ...
- gitlab https
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https https:// ...
- 0629-TP整理四(create(),success(),error(),U())
create()-前提:表单中name的值要与数据库中的字段一一匹配 可直接获取表单数据进行操作: 作用:将数据库中没有的字段在数组中去除. PHP中添加的语法如下: success()和error( ...
- bzoj 4424: Cf19E Fairy && codeforces 19E. Fairy【树形dp】
参考:https://blog.csdn.net/heheda_is_an_oier/article/details/51131641 这个找奇偶环的dp1真是巧妙,感觉像tarjan一样 首先分情况 ...
- bzoj 1627: [Usaco2007 Dec]穿越泥地【bfs】
在洛谷上被卡了一个点开了O2才过= = bfs即可,为方便存储,把所有坐标+500 #include<iostream> #include<cstdio> #include&l ...