使用 Photoshop JavaScript 在 Excel 文件中输出阿拉伯语/泰语文本 [英] Output Arabic/Thai text in Excel file using Photoshop JavaScript

查看:22
本文介绍了使用 Photoshop JavaScript 在 Excel 文件中输出阿拉伯语/泰语文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于 photoshop 的脚本,它将文本图层的名称和图层内容输出到 Excel CSV 文件中.如果文本是英语,它工作正常,但如果文本是阿拉伯语/泰语,则显示为??????".如何正确显示这些文本?

I have a script for photoshop which outputs the name of a text layer and layer content into Excel CSV file. It works fine if the text is english but if the text is Arabic/Thai it was displayed like this "??????". How can I display these texts properly?

我的脚本获取图层名称和图层内容如下:

My script gets the layername and layer content like this:

var iLayer = app.activeDocument.activeLayer.textItem;
var LayerContents = iLayer.contents;

然后像这样输出Excel文件中的名称:

Then output the names in the Excel file like this:

var Names =[ ];
Names.push([LayerName + "," + LayerContents]);

我尝试将阿拉伯语的字体样式更改为 Arial,将泰语的字体样式更改为 Tahoma,但它不起作用.我什至尝试转换 LayerContents.toString();

I tried changing the font style to Arial for Arabic and Tahoma for Thai, but it doesn't worked. I even tried converting LayerContents.toString();

推荐答案

您需要将文本设置为 Unicode.在下面的示例中,我会将图层名称写入文本文件.CSV 的主体相同.

You need to set your text to Unicode. In the example below I'll write the layer name to a text file. The principal is the same for CSV.

// refer to the source document
var srcDoc = app.activeDocument;

var myLayerName = srcDoc.activeLayer.name; // ملعقة
alert(myLayerName) // alerts fine;

write_text(myLayerName, "C:\\temp\\layer_name.txt");


function write_text(str, apath)
{
  // create a reference to a file for output
  var txtFile = new File(apath);

  // open the file, write the data, then close the file
  txtFile.encoding = "UTF8"; // make it unicode
  txtFile.open("w", "TEXT", "????");
  txtFile.writeln(str);
  txtFile.close();
}

这篇关于使用 Photoshop JavaScript 在 Excel 文件中输出阿拉伯语/泰语文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆