批量生成随机字符串并保存到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 ...
随机推荐
- please get a license from www.texturepacker.com
我们在使用texturepacker创建资源后,在使用资源时出现下述问题:please get a license from www.texturepacker.com 如图: 这个是由于我们的版本号 ...
- 怎样将DrawerLayout显示在ActionBar/Toolbar和status bar之间
控制status bar utm_source=tuicool#toc_1" style="color:rgb(0,0,0); text-decoration:none; line ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
C. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...
- 【Beijing 2010】 次小生成树
[题目链接] 点击打开链接 [算法] 首先,有一个结论 : 一定有一棵严格次小生成树是在最小生成树的基础上去掉一条边,再加上一条边 这个结论的正确性是显然的 我们先用kruskal算法求出最小生成树, ...
- oracle从子表取出前几行数据:
取排序后的前几行,应该用: select * from(select * from test order by stamp desc) where rownum<= 6 (表示排序后取前几行) ...
- 配置URL
- 运行Android Studio总是未发现设备
1.未发现虚拟机设备
- bzoj 2100: [Usaco2010 Dec]Apple Delivery【spfa】
洛谷数据好强啊,普通spfa开o2都过不了,要加双端队列优化 因为是双向边,所以dis(u,v)=dis(v,u),所以分别以pa1和pa2为起点spfa一遍,表示pb-->pa1-->p ...
- Java多线程(五)停止线程 interrupt
调用interrupt方法仅仅是在当前线程中打了一个停止的标记,并不是真正停止线程. this.interrupted() :测试当前线程是否已经中断,执行后具有将状态标志清除为false的功能 is ...
- C# 从服务器下载文件并保存到客户端
参考代码: using System; using System.Net; namespace HT.SIHONG.Common.Utility { public class DownloadFile ...