Output Arabic/Thai text in Excel file using Photoshop JavaScript

白昼怎懂夜的黑 提交于 2019-12-06 09:57:07

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/39314554/output-arabic-thai-text-in-excel-file-using-photoshop-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!