如何在Google Drive和Google表中匹配字母数字?

发布于 2025-02-11 02:48:44 字数 482 浏览 2 评论 0 原文

在我的Google驱动器上,我有一个包含2006个文件的文件夹。 这些文件按名称排序。 (来自a - > z) 这是我的文件夹中的文件的确切顺序:

现在,我还有一个Google表,上面写着相同的文件名。每个单元格一个文件名。它们是字母顺序的(来自A - > z) 这是列内的文件的确切顺序:

文件名不按相同的顺序排序。 我该怎么做?

也许我应该使用Google表中的公式重新排序列中的文件名?

On my Google Drive I have a folder containing 2006 files.
These files are sorted by names. (from A -> Z)
Here's the exact order of the files inside my folder: https://gist.github.com/cuzureau/a36deb8e02ab0f2e0523cd58f2cf0950

Now, I also have a Google Sheet with the same file names written in a column. One file name per cell. They are order alphabetically (from A -> Z)
Here's the exact order of the files inside the column: https://gist.github.com/cuzureau/6fe722b821ce3aa60b697819b64d6b05

The files names are not sorted in the same order.
How can I do that ?

Maybe I should use a formula in Google Sheets to reorder the files names in the column ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2025-02-18 02:48:44

这是使用Google Apps脚本的两个可能的解决方案(均使用前100个文件测试):

使用DriveApp Enter在表中直接获取名称

  1. ,然后单击 Extensions>应用脚本
  2. 复制文件寿命的文件夹ID
  3. 复制此脚本。
const sheet = SpreadsheetApp.getActiveSheet()
function myFunction() {
  const folderId = "<FOLDER_ID>"
  // Get all files in the folder
  const files = DriveApp.getFolderById(folderId).getFiles()
  const toShortFiles = []
  while (files.hasNext()) {
    // save all the names
    const file = files.next()
    toShortFiles.push(file.getName())
  }
  // short A-Z
  const shorted = toShortFiles.sort((a, b) => a.localeCompare(b)).map(n => [n])
  sheet.getRange(1, 1, shorted.length, 1).setValues(shorted)
}

简单直接创建新的表,

则可以替代。

function shortRows() {
  /* Create a new sheet */
  const shortedSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet('shortedSheet')
  const range = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn())
  const values = range.getValues()
  /* Short by name */
  const result = values.sort((a, b) => {
    return a[0].toString().localeCompare(b[0].toString())
  })
  /* Paste the data in the new sheet */
  shortedSheet.getRange(1, 1, result.length, result[0].length).setValues(result)
}

如果您在同一行中有更多数据,如果您不想创建新表, /代码>我邀请您测试它们。

文档:

These are two possible solutions using Google Apps Script (both tested with the first 100 files):

Grab the names directly using DriveApp

  1. Enter in your sheet and click on Extensions > Apps Script
    enter image description here
  2. Copy the folder id where the files lives
  3. Copy this script.
const sheet = SpreadsheetApp.getActiveSheet()
function myFunction() {
  const folderId = "<FOLDER_ID>"
  // Get all files in the folder
  const files = DriveApp.getFolderById(folderId).getFiles()
  const toShortFiles = []
  while (files.hasNext()) {
    // save all the names
    const file = files.next()
    toShortFiles.push(file.getName())
  }
  // short A-Z
  const shorted = toShortFiles.sort((a, b) => a.localeCompare(b)).map(n => [n])
  sheet.getRange(1, 1, shorted.length, 1).setValues(shorted)
}

Short directly creating a new sheet

This is an alternative if you have more data in the same row

function shortRows() {
  /* Create a new sheet */
  const shortedSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet('shortedSheet')
  const range = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn())
  const values = range.getValues()
  /* Short by name */
  const result = values.sort((a, b) => {
    return a[0].toString().localeCompare(b[0].toString())
  })
  /* Paste the data in the new sheet */
  shortedSheet.getRange(1, 1, result.length, result[0].length).setValues(result)
}

If you don't want to create a new sheet, you have available the methods moveTo and moveRows I invite you to test them.

Documentation:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文