excel文件怎么重命名
Article Update 13-March-2020: I removed the source code. The article that remains should act as a "design roadmap" for members who want to write the code in the programming language of your choice. If you are interested in discussing the program further, please contact me via the EE message system. 文章更新2020年3月13日:我删除了源代码。 对于希望用您选择的编程语言编写代码的成员,剩下的文章应作为“设计路线图”。 如果您有兴趣进一步讨论该程序,请通过EE消息系统与我联系。In a previous Experts Exchange article, How To Rename-Move a Batch of PDF Files Based on Contents of the Files, I presented a program that solved a question asked here at EE. In that article and program, the situation was that a large number of PDF files in a folder had to be renamed automatically (en masse) with a suffix contained somewhere in each of the PDF files.
在上一篇专家交流文章“ 如何基于文件内容重命名移动一批PDF文件”中 ,我介绍了一个程序,该程序解决了EE在此处提出的一个问题。 在该文章和程序中,情况是文件夹中的大量PDF文件必须自动(重命名)自动重命名,并且每个PDF文件中都包含一个后缀。
For example, a file might be named:
例如,一个文件可能被命名为:
D123456.pdf D123456.pdfAnd inside that file at a fixed location (specific page, specific line, specific column) might be:
在该文件的固定位置(特定页面,特定行,特定列)内可能是:
John Smith 约翰·史密斯In this example, the requirement is to rename the file as:
在此示例中,要求将文件重命名为:
D123456 John Smith.pdf D123456约翰·史密斯.pdfA more recent question here at EE has a similar requirement, except that the suffix is contained in a specific cell of a corresponding Excel spreadsheet. In this newer question, there's an automated process that creates hundreds of PDF documents from Excel spreadsheets. The problem is that the PDF documents need to be renamed after they are created. The renaming should add a suffix to the current PDF file name, as in the previous question, but the suffix is in a fixed cell location of the Excel spreadsheet from which the PDF was created.
EE上一个较新的问题具有类似的要求,除了后缀包含在相应的Excel电子表格的特定单元格中。 在这个新问题中,有一个自动过程,可以从Excel电子表格创建数百个PDF文档。 问题在于PDF文档创建后需要重命名。 与上一个问题一样,重命名应在当前PDF文件名中添加一个后缀,但是后缀位于从中创建PDF的Excel电子表格的固定单元格位置。
For example, a file might be named:
例如,一个文件可能被命名为:
Order Number 12345.xls 订单号码12345.xlsIn which case, the automated PDF creation process would create:
在这种情况下,自动PDF创建过程将创建:
Order Number 12345.pdf 订单号码12345.pdfNow, suppose that cell V16 in each spreadsheet contains the invoice number for each order and that this should be the suffix for the PDF filename. In other words, if cell V16 in file Order Number 12345.xls contains:
现在,假设每个电子表格中的单元格V16都包含每个订单的发票编号,并且这应该是PDF文件名的后缀。 换句话说,如果文件序号12345.xls中的单元格V16包含:
K56789 K56789Then the PDF file should be renamed to:
然后将PDF文件重命名为:
Order Number 12345K56789.pdf 订单号码12345K56789.pdfOr perhaps the more visually pleasing:
也许在视觉上更令人愉悦:
Order Number 12345 K56789.pdf 订单号12345 K56789.pdfOr maybe even:
甚至:
Order Number 12345_Invoice K56789.pdf 订单号12345_发票K56789.pdfIn thinking about this new requirement, it occurred to me that I could leverage the bulk of the code created for the previous article. As with that previous program, the new program presented here is written in AutoHotkey, an excellent (free!) programming/scripting language. The quick explanation for installing AutoHotkey is to visit its website. A more comprehensive explanation is to read my EE article, AutoHotkey - Getting Started. After installation, AutoHotkey will own the AHK file type, supporting the solution discussed in the remainder of this article. Also, the setup utility will install a compiler that turns an AutoHotkey source code script into a stand-alone/no-install executable (an EXE file).
在考虑这一新要求时,我想到可以利用为上一篇文章创建的大量代码。 与以前的程序一样,此处介绍的新程序是使用AutoHotkey (一种出色的(免费!)编程/脚本语言)编写的。 安装AutoHotkey的快速说明是访问其网站 。 更全面的解释是阅读我的EE文章AutoHotkey-Getting Started 。 安装后,AutoHotkey将拥有AHK文件类型,支持本文其余部分讨论的解决方案。 另外,安装实用程序将安装一个编译器 ,该编译器将AutoHotkey源代码脚本转换为独立/无需安装的可执行文件(EXE文件)。
The source code is attached to this article in the file MassRenamePX.ahk, which is a plain text file ( PX in the file name stands for PDF files based on E Xcel cell contents). As mentioned above, AutoHotkey will own the file type AHK, so double-clicking on MassRenamePX.ahk in Windows/File Explorer (or whatever file manager you use) will invoke AutoHotkey to run the program. Alternatively, you may run the AutoHotkey compiler to create a stand-alone executable called MassRenamePX.exe (or whatever you'd like to call it).
源代码附在本文的MassRenamePX.ahk文件中,该文件是纯文本文件(文件名中的PX代表基于E X cel单元格内容的P DF文件)。 如上所述,AutoHotkey将拥有文件类型AHK,因此在Windows / File Explorer(或您使用的任何文件管理器)中双击MassRenamePX.ahk将调用AutoHotkey来运行该程序。 或者,您可以运行AutoHotkey编译器来创建一个名为MassRenamePX.exe的独立可执行文件(或任何您想调用的可执行文件)。
For those folks who do not want to install AutoHotkey, I compiled it into MassRenamePX.exe and uploaded it to EE-Stuff. The regular EE site does not allow uploading EXE files, but EE-Stuff does. You log into EE-Stuff with the same username and password as EE. Then click on the Expert Area tab, then the "Find files for an article" link, and enter this article's ID (12872) in the box. When you download the file, the file name will be MassRenamePX.renamed-from-exe-for-your-safety. Rename it to MassRenamePX.exe (or whatever you want to call it, but make sure the file type is EXE).
对于那些不想安装AutoHotkey的人,我将其编译为MassRenamePX.exe并将其上传到EE-Stuff 。 常规EE站点不允许上传EXE文件,但是EE-Stuff允许。 您使用与EE相同的用户名和密码登录EE-Stuff。 然后,单击“专家区域”选项卡,然后单击“查找文章的文件”链接,然后在框中输入该文章的ID(12872)。 下载文件时,文件名将为MassRenamePX.renamed-from-exe-for-your-safety 。 将其重命名为MassRenamePX.exe (或任何您想调用的名称,但请确保文件类型为EXE)。
When running the program, it goes through the following process:
运行该程序时,它将经历以下过程:
(1) Warns that existing files in the destination folder will be overwritten with no warning and asks if you want to continue:
(1)警告目标文件夹中的现有文件将被覆盖而不会发出警告,并询问您是否要继续:
![](https://i-blog.csdnimg.cn/blog_migrate/1c51a8f4d4d6685f0bc480995f2affb9.png)
(2) Asks for the Excel cell (such as A1 or C5 or V16) containing the suffix:
(2)询问包含后缀的Excel单元格 (例如A1或C5或V16):
![](https://filedb.experts-exchange.com/incoming/2020/03_w11/1446854/2Enter-Excel-cell.jpg)
And then performs error checking on the cell address, as follows:
然后对单元地址执行错误检查,如下所示:
(a) The cell address must be entered:
(a)必须输入单元地址:
![](https://i-blog.csdnimg.cn/blog_migrate/e8f28da13b28406543818236b9301ecf.png)
(b) The first character of the cell address must be alphabetic:
(b)单元地址的第一个字符必须为字母:
![](https://i-blog.csdnimg.cn/blog_migrate/e7653251b8d4338e96d1e7c8d3e43bf9.png)
(c) The cell address must be entirely alphanumeric:
(c)单元地址必须完全是字母数字:
![](https://i-blog.csdnimg.cn/blog_migrate/f11b079cdcc6a5c432019ca5445685cf.png)
(d) The cell address must contain at least one number that is not zero – in other words, cells such as A0 or B00 are not valid:
(d)单元地址必须至少包含一个不为零的数字-换句话说,诸如A0或B00的单元无效:
![](https://i-blog.csdnimg.cn/blog_migrate/c4eba46a53283ac5729f1e22293c91e6.png)
(3) Asks for a separator to put between the current file name and the suffix, such as a space or hyphen or underscore (or no separator):
(3)要求在当前文件名和后缀之间放置一个分隔符 ,例如空格,连字符或下划线(或不包含分隔符):
![](https://i-blog.csdnimg.cn/blog_migrate/30d9e582cb91857b86353552858f1ecd.png)
This may be any number of characters but, of course, must contain only the characters that are valid in a file name. If you enter any invalid characters (see list below in item #8), it shows this:
它可以是任意数量的字符,但是,当然,必须仅包含文件名中有效的字符。 如果输入任何无效字符(请参阅下面的项目#8中的列表),则会显示以下内容:
![](https://i-blog.csdnimg.cn/blog_migrate/9b04072c4a8d1890252cc4fa1e579cd6.png)
(4) Asks for the source folder:
(4)询问源文件夹 :
![](https://i-blog.csdnimg.cn/blog_migrate/56cd3f41149a1d6fe4b6e36c495358c5.png)
This is the folder where the PDF files and Excel spreadsheets are located (the latter may have file types of XLS or XLSX). You may enter it by browsing to it or typing the name into the box or copying/pasting into the box. The source folder must exist, otherwise it displays this:
这是PDF文件和Excel电子表格所在的文件夹(后者可能具有XLS或XLSX文件类型)。 您可以通过浏览到它或在框中输入名称或复制/粘贴到框中来输入它。 源文件夹必须存在,否则将显示以下内容:
![](https://i-blog.csdnimg.cn/blog_migrate/e5156e7ebbe3baa972004bc9d83a7416.png)
(5) Asks for the destination folder:
(5)询问目标文件夹 :
![](https://i-blog.csdnimg.cn/blog_migrate/e05372c9c871b838d28e6331c74983a1.png)
This is the folder where the renamed PDF files will be stored. If the source and destination folders are the same, the program does just a Rename. If the source and destination folders are not the same, the program does a Rename and a Move. As with the source folder, you may enter the destination folder by browsing to it or typing the name into the box or copying/pasting into the box. But this dialog has one more option not available for the source folder, namely, Make New Folder, providing the ability to create the destination folder if it doesn't exist.
这是将存储重命名的PDF文件的文件夹。 如果源文件夹和目标文件夹相同,则程序仅执行重命名 。 如果源文件夹和目标文件夹不同,则程序将执行重命名和移动 。 与源文件夹一样,您可以通过浏览到目标文件夹或在框中输入名称或复制/粘贴到框中来输入目标文件夹。 但是此对话框还有一个对源文件夹不可用的选项,即Make New Folder ,提供了创建目标文件夹(如果不存在)的功能。
(6) Asks for confirmation that the parameters are correct, since at this point it has all of the information needed:
(6)要求确认参数正确,因为此时它具有所需的所有信息:
![](https://i-blog.csdnimg.cn/blog_migrate/d95e09a07d9e1f943b49aa6cfff91fd3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b872201cc9b2d9c1467316edbdc8e585.png)
As you can see in the two examples above, the program shows if the source and destination folders are the same or different, and what that means the result will be, namely, either a rename/in-place or a rename/move.
正如您在上面的两个示例中看到的那样,该程序显示源文件夹和目标文件夹是相同还是不同,这意味着结果将是重命名/就地或重命名/移动。
(7) Loops through all of the files in the source folder looking for PDF files that have an XLS or XLSX file with a matching name. When it finds such a pair, it reads the suffix cell in the Excel file and performs the rename/move on the PDF file. During this process, it displays a green progress bar moving to the right so you know that processing is taking place. The progress bar dialog also contains the name of the file that it is currently working on:
(7)循环浏览源文件夹中的所有文件,以查找具有匹配名称的XLS或XLSX文件的PDF文件。 当找到这样的对时,它将读取Excel文件中的后缀单元格并在PDF文件上执行重命名/移动。 在此过程中,它显示向右移动的绿色进度条,因此您知道正在进行处理。 进度栏对话框还包含当前正在处理的文件的名称:
![](https://i-blog.csdnimg.cn/blog_migrate/0ce6840ad9eb52946f8cf290577bd822.png)
(8) Detects if the suffix contains a character that is not valid for a file name. Specifically, it checks every character in the suffix against this list:
(8)检测后缀是否包含对于文件名无效的字符。 具体来说,它将对照此列表检查后缀中的每个字符:
< (less than)
<(小于)
> (greater than)
>(大于)
: (colon)
:(冒号)
" (double quote)
”(双引号)
/ (forward slash)
/(正斜杠)
| (vertical bar or pipe)
| (垂直杆或管)
\ (backslash)
\(反斜杠)
? (question mark)
? (问号)
* (asterisk)
*(星号)
All of these are invalid characters for a Windows file name, and if the program finds one in a suffix, it will not attempt to perform the rename/move.
对于Windows文件名,所有这些字符都是无效字符,如果程序在后缀中找到一个字符,它将不会尝试执行重命名/移动。
(9) Captures the following statistics during a run:
(9)在运行期间捕获以下统计信息:
where YYYY-MM-DD and hh.mm.ss are the date and time when the run began. The file looks like this:
其中YYYY-MM-DD和hh.mm.ss是运行开始的日期和时间。 该文件如下所示:
Operational Statistics from Batch-Mass-Rename-Move-PDF-Files-Excel
批处理-批量-重命名-移动-PDF-文件-Excel的运营统计
Beginning date and time: 2014-01-17_16.02.04
起始日期和时间:2014-01-17_16.02.04
Source folder: D:\0tempD\TestPDFrename-in\
源文件夹:D:\ 0tempD \ TestPDFrename-in \
Destination folder: D:\0tempD\TestPDFrename-out\
目标文件夹:D:\ 0tempD \ TestPDFrename-out \
Excel cell containing the suffix: a2
包含后缀的Excel单元格:a2
Separator between file name and suffix: _
文件名和后缀之间的分隔符:_
Number of PDF files processed: 173
处理的PDF文件数量:173
Number of PDF files without a matching Excel file: 8
没有匹配的Excel文件的PDF文件数量:8
Number of Excel files with invalid character in suffix: 3
带后缀无效字符的Excel文件数:3
Number of times attempted rename/move returned error: 0
尝试重命名/移动返回错误的次数:0
Ending date and time: 2014-01-17_16.05.22
结束日期和时间:2014-01-17_16.05.22
Elapsed time (minutes:seconds): 3:18
经过时间(分钟:秒):3:18
If the attempt to write the Operational Statistics file fails (returns an error code), the program displays this dialog:
如果尝试写入Operational Statistics文件的尝试失败(返回错误代码),则程序将显示以下对话框:
![](https://i-blog.csdnimg.cn/blog_migrate/b50aec751cabcaad08c8a0ac3d1f341f.png)
As with the previous program, I did some generalization, but I realize that the solution is still rather specific to the requirements in the posted question. However, by providing the source code, I hope that other members with similar requirements will be able to modify the program to suit their purposes.
与以前的程序一样,我做了一些概括,但是我意识到解决方案仍然非常特定于发布的问题中的要求。 但是,通过提供源代码,我希望具有类似要求的其他成员能够修改该程序以适合他们的目的。
If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe
如果您发现本文有帮助,请单击下面的大拇指图标。 这使我知道什么对EE成员有价值,并为以后的文章提供了指导。 非常感谢! 问候乔
excel文件怎么重命名