Excel 的 Applescript:如何将范围格式化为日期和 1900 日期系统
Applescript for Excel: How to format range as date and 1900 date system
我编写了一个脚本,该脚本大部分成功实现了从 CSV 文件创建 SQL 语句的目标。我现在遇到的 2 个问题是 1) csv 文件中的日期列格式为 "General",因此显示为数字而不是日期,以及 2) 转换为日期时使用的是 1904 日期系统,并且当然将这一年显示为未来 4 年(2015 年显示为 2019 年)。我搜索了网络和 Excel 2004 Applescript 指南。
以下是我目前拥有的命令,它们至少编译 运行 没有错误,但也没有完成我希望做的事情:
tell application "Microsoft Excel"
try
close workbooks saving no
end try
open working_file
set date type of active workbook to date 1900
tell active workbook
tell active sheet
set datecolumn to range ("A2:A100" as string)
select datecolumn
set data type of datecolumn to date data
end tell
end tell
end tell
下面的脚本取消设置首选项标志日期 1904,并将范围格式化为日期格式 dd/mm/yyyy。如果需要,您还可以将其调整为其他格式,如美国格式 (mm/dd/yy) :
tell application "Microsoft Excel"
front document activate
set date 1904 of active workbook to false
set datecolumn to range "A2:A100" of active sheet of active workbook
set number format of datecolumn to "dd/mm/yyyy"
end tell
我编写了一个脚本,该脚本大部分成功实现了从 CSV 文件创建 SQL 语句的目标。我现在遇到的 2 个问题是 1) csv 文件中的日期列格式为 "General",因此显示为数字而不是日期,以及 2) 转换为日期时使用的是 1904 日期系统,并且当然将这一年显示为未来 4 年(2015 年显示为 2019 年)。我搜索了网络和 Excel 2004 Applescript 指南。
以下是我目前拥有的命令,它们至少编译 运行 没有错误,但也没有完成我希望做的事情:
tell application "Microsoft Excel"
try
close workbooks saving no
end try
open working_file
set date type of active workbook to date 1900
tell active workbook
tell active sheet
set datecolumn to range ("A2:A100" as string)
select datecolumn
set data type of datecolumn to date data
end tell
end tell
end tell
下面的脚本取消设置首选项标志日期 1904,并将范围格式化为日期格式 dd/mm/yyyy。如果需要,您还可以将其调整为其他格式,如美国格式 (mm/dd/yy) :
tell application "Microsoft Excel"
front document activate
set date 1904 of active workbook to false
set datecolumn to range "A2:A100" of active sheet of active workbook
set number format of datecolumn to "dd/mm/yyyy"
end tell