简体   繁体   English

谷歌应用程序脚本电子表格字符串检索问题

[英]google apps script spreadsheet string retrieving issue

I can't figure out why the following code isn't working properly in case of special characters: 我无法弄清楚为什么以下代码在使用特殊字符时无法正常工作:

[...]
// get strings (names) from spreadsheet
var persons = SpreadsheetApp.getActiveSheet().getRange(2, 1, 31, 4).getValues();

// for each row
for (var row in persons) {

    // build the filename
    var myFile = persons[row][1] + "_" + persons[row][0] + "_20180124.txt";

    [...]

    // handle from Google Drive only file             
    var driveFiles = DriveApp.getFilesByName(myFile);
    while (driveFiles.hasNext()) {
        var file = driveFiles.next();

        if(driveFiles.getName() == myFile) {

            /* write to Log

            Saša_KLANJŠČEK_20180124.txt     not written
            Peter_MARINČIČ_20180124.txt     not written
            Peter_KLANJŠČEK_20180124.txt    not written
            Niko_ČERNIC_20180124.txt        not written
            Tjaša_KOGOJ_20180124.txt        written
            */

            Logger.log(myFile + "\n");

        [...]

Strings with uppercase unicode characters causes the conditional statement to fail. 具有大写unicode字符的字符串会导致条件语句失败。 I tried with toString("UTF-8") method, but it still doesn't work. 我尝试了toString(“ UTF-8”)方法,但仍然无法正常工作。 Is it an encoding problem? 这是编码问题吗?

Change: 更改:

if(driveFiles.getName() == myFile) {

into 进入

 if(file.getName() == myFile) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM