简体   繁体   English

将谷歌表格数据复制到另一个工作簿,文本公式为 static 文本

[英]Copy google sheets data to another workbook with text formula as static text

I have the code below that copies data from one google sheets workbook to another however I do have a formula that is copying as a date value however I want it to copy as a text value.我有下面的代码,可以将数据从一个 google 工作表工作簿复制到另一个工作簿,但是我确实有一个公式正在复制为日期值,但是我希望它复制为文本值。 It is currently copying as 01/01/2023 11;20:00 (date) I want it to copy as 01/01/2020 11:20 AM (text)目前正在复制为 01/01/2023 11;20:00(日期)我希望它复制为 01/01/2020 11:20 AM(文本)

=arrayformula(text(A2:A, "dd/mm/yyyy hh:mm am/pm")
var sourceSpreadsheetID = "ID1";
var sourceWorksheetName = "Overview";
var targetSpreadsheetID = "ID2";
var targetWorksheetName = "Overview Static";
function importData() {
  

  var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
  var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
  var thisData = thisWorksheet.getDataRange();
  //Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.
  //var thisData = thisSpreadsheet.getRangeByName("data");
 
  var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
  var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
  var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns())
  toRange.setValues(thisData.getValues()); 
}
var sourceSpreadsheetID = "ID1";
var sourceWorksheetName = "Overview";
var targetSpreadsheetID = "ID2";
var targetWorksheetName = "Overview Static";
function importData() {
  

  var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
  var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
  var thisData = thisWorksheet.getDataRange();
  //Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.
  //var thisData = thisSpreadsheet.getRangeByName("data");
  var ts = thisSpreadsheet.getSpreadsheetTimeZone();
  var replacedData = thisData.getValues().map(row => 
    row.map((v, i) =>
      // Assuming the dates are in the first column
      i === 0 ? Utilities.formatDate(v, ts, 'dd/MM/yyyy HH:mm a') : v
    )
  );
 
  var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
  var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
  var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns())
  toRange.setValues(replacedData); 
}

Referneces:参考文献:

暂无
暂无

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

相关问题 将数据从一个 Google 工作表工作簿工作表复制到另一个工作簿 - Copy Data from One Google sheets Workbook Sheet to another Workbook 用于确定单元格中的文本是否为斜体的 Google 表格公式 - Google Sheets formula to determine if text in a cell is italic 替换 Google 表格查询公式中的文本 - Replace text in a Google Sheets Query Formula 使用任何数字或文本编辑单元格时,在 Google 表格中复制公式 - Copy down Formula in Google Sheets when cell is edited with any number or text 如何在同一工作簿中的多个谷歌工作表中替换链接中的文本 - How to replace text in a link across multiple google sheets in the same workbook 将数据复制到另一张Google表格中 - Copy data to another sheet Google Sheets 从其他单元格中的文本创建公式(Google 表格) - Create a formula from text in other cells (Google Sheets) 同一单元格中的动态超链接和文本与谷歌表格中的公式 - Dynamic hyperlink & Text in the same cell with a formula in google sheets Google脚本 - 将数据从一个工作簿复制到另一个工作簿 - importrange()替代方案 - Google Script - Copy Data from one Workbook To Another - importrange() Alternative 如何使用 zapier 自动将填充有 zapier 的新行的值复制到具有 google 工作表的同一工作簿中的另一个工作表? - How to automaticaly copy values of a new row populated with zapier to another sheet in same workbook with google sheets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM