需要导入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的更多相关文章

  1. 将数字n转换为字符串并保存到s中

    将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各 ...

  2. Sql数据保存到Excel文件中

    public string ExportExcel( DataSet ds,string saveFileName) { try { if (ds == null) return "数据库为 ...

  3. 调用获取学生信息的接口,保存到excel里面

    # 2.http: // doc.nnzhp.cn / index.php?s = / 6 & page_id = 14# 调用获取学生信息的接口,保存到excel里面 import requ ...

  4. 调用获取学生信息的接口,保存到excel里面的小程序

    # 2.http: // doc.nnzhp.cn / index.php?s = / 6 & page_id = 14# 调用获取学生信息的接口,保存到excel里面 import requ ...

  5. 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间

    生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...

  6. 用python实现批量获取Linux主机简要信息并保存到Excel中 unstable 1.1

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- #filename get_linux_info.py #获取Linux主机的信息 # titles=[' ...

  7. Java中生成随机字符的方法总结

    package learnExercise; public class RandomCharacter { public static char getRandomCharacter(char ch1 ...

  8. 利用Masscan批量生成随机ip地址表

    简介 Masscan是Kali下集成的高效扫描器,和nmap命令有很多相似之处 命令生成随机ip masscan -sL 10.0.0.0/24 > c段.txt masscan -sL 10. ...

  9. python 批量修改预定字符串并将修改后的字符串插入文件指定位置

    下面的例子是在文件的指定位置增加指定字符串的例子 修改配置文件: def add_str(pre_str): lines = [] flag = True f = open("z.txt&q ...

随机推荐

  1. Android 代码设置Activity 背景透明

    当指定Activity 样式 Them.Dialog 时候 又不同意用XML 设置 Activity 的背景颜色的时候 用代码 this.getWindow().getDecorView().setB ...

  2. JS重名解决方案

    一个页面如果引用多个JS,或者像ASP.NET MVC,一个视图包含多个子视图,每个子视图有自己的JS,那么变量.函数的重名冲突机会将会大增. 如何解决? 这里有一个方案: 1.用类来封装子页的JS代 ...

  3. ZOJ3659 Conquer a New Region 并查集

    Conquer a New Region Time Limit: 5 Seconds      Memory Limit: 32768 KB The wheel of the history roll ...

  4. Codeforces Round #319 (Div. 2)B. Modulo Sum DP

                                                             B. Modulo Sum                               ...

  5. 【bzoj2464】中山市选[2009]小明的游戏

    直接转换成最短路 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstr ...

  6. docker 基本指令

    sudo docker info 查看docker状态. jiqing@ThinkPad:~$ sudo docker info [sudo] password for jiqing: Contain ...

  7. 【POJ 3233】Matrix Power Series

    [题目链接] 点击打开链接 [算法] 要求 A^1 + A^2 + A^3 + ... + A^k 考虑通过二分来计算这个式子 : 令f(k) = A^1 + A^2 + A ^ 3 + ... + ...

  8. 【POJ 2983】 Is the information reliable?

    [题目链接] 点击打开链接 [算法] 差分约束系统,SPFA判负环 [代码] #include <algorithm> #include <bitset> #include & ...

  9. 洛谷 P2312 & bzoj 3751 解方程 —— 取模

    题目:https://www.luogu.org/problemnew/show/P2312 https://www.lydsy.com/JudgeOnline/problem.php?id=3751 ...

  10. is not mapped [from错误

    我出现的错误是:org.hibernate.hql.ast.QuerySyntaxException: loginuser is not mapped [from loginuser] 配置文件如下: ...