首页 > 解决方案 > 带有Applescript的Excel货币字符串值

问题描述

这是我的情况:我有一个 InDesign 文件,需要读取一个包含项目描述、数量和价格的 Excel 电子表格。描述是文本,数量是数字,价格是货币。我将从世界各地获取这些文件,因此价格列采用具有各种货币符号的货币格式。

我能够找到一个 Applescript,它将整个工作表转换为一个文本数组以供 InDesign 读取,但价格单元格只给了我值,而不是格式化的值。

所以当我的行看起来像这样时:

Item A | 4 | 3.00 €
Item B | 7 | $4.50
...

我运行这个脚本:

tell application "Microsoft Excel"
   open file "excelFilePath"
   set theWorkbook to active workbook
   set theSheet to sheet 1 of theWorkbook
   set theMatrix to value of used range of theSheet
   set theRowCount to count theMatrix
   set str to ""
   set oldDelimiters to AppleScript's text item delimiters
   repeat with countRows from 1 to theRowCount
       set theRow to item countRows of theMatrix
       set AppleScript's text item delimiters to ";"
       set str to str & (theRow as string) & "|"
   end repeat
   set AppleScript's text item delimiters to oldDelimiters
   close theWorkbook saving no
end tell
tell application id "com.adobe.InDesign"
   tell script args
       set value name "excelData" value str
   end tell
end tell

然后我得到这个:

Item A,4,3,
Item B,7,4.5,
...

但我需要这个:

Item A,4,3.00 €,
Item B,7,$4.50,
...

如何获取货币的字符串值?

标签: excelapplescript

解决方案


您需要使用字符串 value而不仅仅是value

    set theMatrix to string value of used range of theSheet

干杯! Funtom


推荐阅读