Excel批量导入图像构成人员信息表

在开发中,我遇到需要构建下列5000个数据项的任务,每一项有证件照、姓名、身份证号、身份证有效期、出生年月日等等。如果一个一个手动构建完全不可能,因此在学习每个步骤的方法后,成功构建含有5000项的excel表格,下面我将对构建过程进行讲解和记录,方便他人参考。

第一步:创建一个excel文件

第二步:可用方方格子excel工具插件生成5000个随机姓名、5000个随机身份证,然后按照上述项使用各种方法填完对应的5000个格子。

第三步:在一个txt文本中构建出5000个以下类似文本内容,5000个代表着下面下述字符串中就最后的*.jpg不一样

<table><img src="C:\Users\13676\Desktop\5000\ (4512).jpg"width="176"height="220">

说明:(1)C:\Users\13676\Desktop\5000\ (4512).jpg:文件名和路径

            (2)"width="176"height="220":导入后的图像宽高

为了生成5000个不同的上述字符串,这里有两个办法可以操作:

第(1):使用代码进行生成

该方法是最简单的,首先将所有图像文件同一命名,让其按一定序列命名;然后,编写代码,将字符串写入txt文件,方便我们直接复制到excel表格中。

以下为简单demo。

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <malloc.h>

int main()
{
	int ncnt = 0;

	FILE *pfp =NULL;
	pfp = fopen("Name.txt","w");
	if(NULL == pfp)
	{
		printf("====> file open error\n!");
		return -1;
	}

	for(ncnt =1;ncnt<4882;ncnt++)
	{	
		fprintf(pfp,"<table><img src=\"C:\\Users\\13676\\Desktop\\5000\\ (%d).jpg\"width=\"176\"height=\"220\">\n",ncnt);
	}

    return 0;
}

 下面是生成的批量导入图像命令

<table><img src="C:\Users\13676\Desktop\5000\ (2456).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2457).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2458).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2459).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2460).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2461).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2462).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2463).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2464).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2465).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2466).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2467).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2468).jpg"width="176"height="220">
<table><img src="C:\Users\13676\Desktop\5000\ (2469).jpg"width="176"height="220">

第(2):使用Linux命令进行各种操作

首先,使用ls命令将图像文件名导入一个txt文件中。

ls > ../picName.txt

然后,使用vim对picName.txt编辑

#进入vim命令模式
%s/^/<table><img src="your_path/   #给每一行首加入上述字符串
%s/$/"width="176"height="220">/    #给每一行尾加入上述字符串

第四步:将生成的字符串复制到excel表格,黏贴时右键,选择粘贴性粘贴,此时excel会主动将图片导入excel

第四部:如果要生成随机合法身份证,那么需在网上下载excel插件方方格子,并按照,安装完之后excel上方会出现下图所示选项,有一系列的工具。

提取身份证出生年月日命令:

=MID(A2,7,4)&"年"&MID(A2,11,2)&"月"&MID(A2,13,2)&"日"

生成身份证有效期,这里直接+20年:

=MID(A2,7,4)+20&"年"&MID(A2,11,2)&"月"&MID(A2,13,2)&"日"

第五步:如果要生成随机电话号码,则需要单元格输入公式,回车,然后下拉。

=13&RANDBETWEEN(100000000,999999999)

最后,加上其它操作可生成如下效果示意图。

 

结束。

猜你喜欢

转载自blog.csdn.net/Chasing_Chasing/article/details/81268086