Reputation: 71
So I want to transfer datas from a sheet to another sheet. With that code, I transfered datas that i want to, but the problem is that I dont have the color, and the borders of the cells.
function copypaste(sourcelink, sourcesheet, soucerange, destilink, destisheet, destirange) {
var ssraw = SpreadsheetApp.openByUrl(sourcelink);
var sheetraw = ssraw.getSheetByName(sourcesheet);
var range = sheetraw.getRange(soucerange)
var data = range.getValues();
var ss = SpreadsheetApp.openByUrl(destilink);
var sheet = ss.getSheetByName(destisheet);
sheet.getRange(destirange).clearContent();
sheet.getRange(destirange).setValues(data);
}
function run() {
copypaste("link",
"Planning EDMZI",
"G10:JE130",
"link",
"Planning Export",
"G10:JE130")
}
So, I dont know if it is possible to tranfers datas with the form of the data from a sheet to another sheet.
The color is not the same for each cells, sometime the cell dont have any color, and oher times the cell have a specific color, but that will depend of what the user enter in the cell.
Upvotes: 0
Views: 178
Reputation: 71
UPDATE, here is the answer of my question : I added that line to my code :
var bg = range.getBackgroundObjects();
And I added that to my code :
sheet.getRange(destirange).setValues(data).setBackgroundObject(bg);
With that i have the data of each cells and the color that correspond of each cells :)
Upvotes: 0
Reputation: 15308
Try
sheet.getRange(destirange).setValues(data);
sheetraw.getRange(soucerange).copyTo(sheet.getRange(destirange), {formatOnly:true})
Upvotes: 1