When using .getValues and .setValues to copy values from sheet A to sheet B, all values copy but date values in sheet A have no timestamp but a timestamp is added to date values in sheet b
Aside from below code, I have tried or researched:
sheet.copyTo(destination);// only to create new sheet
setValue(new Date(new Date().setHours(0,0,0,0))).setNumberFormat('MM/dd/yyyy');//removes timestamp but sets todays date
sonosFcstDestDateCells.setNumberFormat('dd/MM/yyyy');//did not remove date timestamp
Here is current code:
function cloneGoogleSheet(ssA, ssB) {
// source docs
var sssFcst = SpreadsheetApp.openByUrl('url');
// target/destination spreadsheet
var tss = SpreadsheetApp.openByUrl('url');
//set var for ssA and ssB source and destination
var ssAFcstSource = sssFcst.getSheetByName("ssA"); //
var ssAFcstSourceRange = ssAFcstSource.getDataRange(); //
var ssAFcstSourceA1Range = ssAFcstSourceRange.getA1Notation(); //
var ssAFcstSourceData = ssAFcstSourceRange.getValues(); //
var ssBFcstDest = tss.getSheetByName("ssB"); //
var ssBFcstDestDateCells = ssBFcstDest.getRange("5:5");
var ssAFcstSourceDateCells = ssAFcstSource.getRange("5:5");
var sNF = ssAFcstSource.getDataRange().getNumberFormats();
// Clear the destination sheet before paste
ssBFcstDest.clear({contentsOnly: true});
// set the target range to the values of the source data
ssBFcstDest.getRange(ssAFcstSourceA1Range).setValues(ssAFcstSourceData);
//this duplicates all formats from ssA to ssB, but does not remove added date
//timestamp
ssBFcstDest.getRange(1,1,ssAFcstSourceData.length,ssAFcstSourceData[0].length).setValues(ssAFcstSourceData).setNumberFormats(sNF);
};
Desired result is to have values copy from sheet A to Sheet B without adding timestamp to date values
There are many ways to copy data from the sheet of one spreadsheet to the sheet of another spreadsheet sheet.
In this example, I created a date field and entered two records: 23 March 2019 and 31 December 1985
This is the output using the following methods:
copyTo()
Ref
getValues()/setValues()
Ref
getDisplayValues()/setValues()
Ref
getValues()/setValues()
- push to array
Utilities.formatDate(ssAData[i][0], Session.getScriptTimeZone() ,"dd MMMM yyyy")
Ref
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.