批量生成随机字符串并保存到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 ...
随机推荐
- [办公自动化]如何让excel图表标签中显示最新值数据
同事做了一张excel图表,希望最新的数据显示数据标签,其他都不显示.并且当单元格的数据新增加时,这个标签要能自动更新. 这里需要用到公式,获取到这个最新值.在b2输入公式=lookup(9e+307 ...
- servlet container:tomcat jetty and undertow
1 spring boot内嵌容器支持tomcat.jetty和undertow 但是undertow性能最好,详见: https://examples.javacodegeeks.com/enter ...
- b-is-in- (1267, "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='") SELECT id FROM qqzoneshuoshuo WHERE words=
db-is-in- (1267, "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci, ...
- GeHost powershell
PS C:\Users\clu\Desktop> [System.Net.Dns] | Get-Member -Static | Format-Table -AutoSize TypeName: ...
- POJ 3650:The Seven Percent Solution
The Seven Percent Solution Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7684 Accep ...
- BaezaYates 交集python和golang代码
def bsearch(find, arr, low, high): while low <= high: mid = (low + high) >> 1 if arr[mid] = ...
- [疑问] C# 多线程程序,如果在并行程序块中开空间会远远慢于将空间开在并行块之外
// int[,] label = new int[m, n]; Parallel.For(, thread_num, (n) => { ]; i++) { int[] tmp = new in ...
- 第十二周 Leetcode 354. Russian Doll Envelopes(HARD) LIS问题
Leetcode354 暴力的方法是显而易见的 O(n^2)构造一个DAG找最长链即可. 也有办法优化到O(nlogn) 注意 信封的方向是不能转换的. 对第一维从小到大排序,第一维相同第二维从大到小 ...
- Python 私有化类的属性
class MandgerSec: def __init__(self,name,gender,level): self.type=("fire",None) self.name= ...
- bzoj 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列【hash】
我%&&--&()&%????? 双模hashWA,unsigned long longAC,而且必须判断hash出来的数不能为0???? 我可能学了假的hash 这个 ...