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

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

问题描述

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



我的脚本获取像这样的图层名称和图层内容:

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

然后在Excel文件中输出这样的名字:

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

我尝试将字体样式更改为Arial,对于Thai为Tahoma,但不起作用。
我甚至尝试过转换LayerContents.toString();解决方案

您需要将您的文本设置为Unicode。在下面的例子中,我将图层名称写入一个文本文件。

  //引用源文档
var srcDoc = app.activeDocument;

var myLayerName = srcDoc.activeLayer.name; //警告
alert(myLayerName)//警告正常;

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


函数write_text(str,apath)
{
//创建一个文件输出的引用
var txtFile = new File(apath) ;

//打开文件,写入数据,然后关闭文件
txtFile.encoding =UTF8; // make unicode
txtFile.open(w,TEXT,????);
txtFile.writeln(str);
txtFile.close();
}


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;

Then output the names in the Excel file like this:

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

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();

解决方案

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天全站免登陆