Google Sheets Script, how to create a NEW loose object of a sheet tab - object

I can't find the answer but it might be that I'm looking for the wrong things.
I got a sheet that got tabs for every letter in the alphabet and those includes data beginning
on that letter. I now want to copy those line into a summary sheet but before I just copy it
I need to remove the first line from every tab as that is the heading, the heading should not
appear over and over down all the lines in the new summary tab.
If I just do a variable of a tab and remove the first line, like:
var sheets = ss.getSheetByName(tabs[i]);, this will reflect into the tab itself
and that is wrong as the heading is now gone in that tab and that I can understand as it is not
a new object but a referencing variable.
I tried to create a new object like: var sheets = new Object(ss.getSheetByName(tabs[i]));
and then change that figuring it wouldn't touch the tab itself as this is now not a reference object
but it seems it is, as changing the 'sheets' variable still changes the original data in that tab.
I hope that makes it clear.
How can I create a new object of that tab and is NOT a reference but a COPY of it so I can do
whatever I want to that object without changing the original data in the tab it came from.

Perhaps something like this might work:
function summaryAZ() {
const sA=['A','B','C'];//etc
const ss=SpreadsheetApp.getActive();
const sumsh=ss.getSheetByName('Summary')
sumsh.getRange(2,1,sumsh.getLastRow()-1,sumsh.getLastColumn()).clearContent();//clear everything except header row
sA.forEach((n,i)=>{
let sh=ss.getSheetByName(n);
let [hA, ...data]=sh.getDataRange();
sumsh.getRange(sumsh.getLastRow()+1,1,data.length,data[0].length).setValues(data);
});
}

Related

Getting access to a sheets Title block using python

Dynamo Script
Within Dynamo I was able to adjust the title block per sheet but I was requested to simplify it into a button click using python only.
I can find the sheets but I can not adjust the parameters per sheet. I believe this is because the parameter I am trying to toggle on and off is located within the Titleblock and not on the sheet it self. I thought maybe I would need to unwrap these but I could not get the function to work outside of Dynamo. Any help would be appreciated.
sheet_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets) \
.WhereElementIsNotElementType() \
.ToElements()
for sheet in sheet_collector:
print(sheet.Name)
The snippet above is how I am sourcing all the sheets and I have been able to find everyone but when searching for the custome parameter, it comes up nil.
To get the FamilyInstance of the title block you can use this:
var titleBlockFamInst = new FilteredElementCollector(doc, viewSheetId).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstElement() as FamilyInstance;

How to change a particular column of an excel sheet in ui path

I have an excel sheet that has a data like this
Position URL Company Location
Developer /xyz/123/xyz ABC US
Manager /xyz/132/asd ASD US
Tester /xyz/142/asf ABD US
I wish to capture all the url from this sheet and add "www.xyz.com/" before them and replace the old url with the new url so that the sheet becomes like this
Position URL Company Location
Developer www.xyz.com//xyz/123/xyz ABC US
Manager www.xyz.com//xyz/132/asd ASD US
Tester www.xyz.com//xyz/142/asf ABD US
The work flow that i have till now is
1) Open excel application scope
2) Use read range
3) Use for each row to fetch the url
4) Use assign activity to create a new variable and save the new url in it
But i am not able to understand how to replace it
Would appreciate any help
I'm gonna start from your third point since you have the datatable from read range (With Add headers checked preferably).
With a For each row you can loop through the datatable and replace the value in column URL using an Assign activity like this:
Next, use Excel application scope again. Look for the activity Write range (System > File > Workbook > Write range) and enter the datatable. I recommend you to check Add headers.
This will add the datatable to the Excel file selected.
Changing the value of a particular cell in excel can be done without much efforts in G1ANT and don't forget to add addon xlxs to your robot. Here, is the sample code for your problem statement.
xlsx.open ♥environment⟦USERPROFILE⟧\path\filename.xlsx
xlsx.getvalue row 1 colname a result ♥val
dialog ♥val
xlsx.setvalue value ‴www.xyz.com/♥val‴ row 1 colindex 1 result ♥val
dialog ♥val
On cell E2, enter this formula:
="www.xyz.com/"&B2
And as indicated in the pic, double click that black point and the formula should be copied down to the end automatically. Or you can drag it down if you want. Try and let me know if this is what you are looking for.

Update google spreadsheet every n hours

I have google sheet that i want to use every day (like a main template), where I just need to add a few values in a specific cells,
i want to be able automatically or not to set those cell values everyday (let's say at midnight) back to my default values (let's say 0 or 1).
Any clue, any help,
Thanks.
You can use script triggers to run your script every nth hour.
Triggers: https://developers.google.com/apps-script/guides/triggers/installable
Check "Managing triggers manually" section.
You will have to create a script in google spreadsheet to change the values to a default value and setup up triggers to run that script every nth hour or so.
So all I need to do was create a script for a sheet
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange("B2");
var values = range.getValues();
if(values > 0) {
range.setValue(0);
}
}
And after that Click on Resources, Current project's triggers.
Add new trigger and set it like this:
I think that's it, it is tested and work.
If something is missing please edit my answer,deleting trigger or something like that.

Add-Ins for Office365: inserting data into an excel sheet from a task-pane add-in

I must be missing something:
[problem]:
I have a 2-dimensional array of data, that i would like to insert into the current sheet starting from cell A1. I also have to format this data.
The current document may be empty or not. I do not have control over this.
At a later point, i need to remove the data from the document and insert new data. This new set of data may have different dimensions.
This seems to be impossible to do using the Office JavaScript Api.
All the things I tried using TableBindings, etc. have failed. In many cases, functionality that should work according to MSDN failed, giving me cryptic error messages such as "internal error" (code 5001) or unsupported binding operation (3010). I have to use tablebindings, because i can't apply formatting to anything else according to the MSDN documentation.
The following solutions are unacceptable:
forcing the user to use a specific document template with preexisting named tables
forcing the user to select cell "A1" before my Add-In gets to work.
forcing the user to select a range prior to inserting the data.
All of which are nightmarish solutions from a usability point-of-view.
I can create a binding from named item and construct the range by counting columns and rows and building a string like this "A1:C232" but this only works once, because:
i can't delete the data (yes. calling "deleteAllDataValuesAsync" on a binding created with such a named range throws error 3010 (even though the binding say's it's a "table" binding.. wat?).
i can't overwrite it with data of different size (overwrite error)
i can't set formatting on it (yes, it's a binding created as a tablebinding, yes, i can call the setFormatAsync function, and it throws an "internal error, 5001" -> #headdesk
I hope someone from Microsoft reads this and can point me in the right direction. I really hope! Because i'm starting to fear that this is actually by design. (i'm so frustrated by office.js after the last few weeks of struggle, i'm having a hard time not ranting, so i'll stop right here.. don't get me started on ui fabric)
With the new Excel Javascript APIs introduced with Office 2016 (and available soon in Office Online), it is easy to manipulate worksheet data using the new Range object. The snippet below runs without requiring range selection or any other action on the part of the user.
var data = [
[1,2,3],
[2,6,7]
]
Excel.run(function (ctx) {
// make space for the data to be inserted
var sheet1 = ctx.workbook.worksheets.getItem("Sheet1");
var firstCell = sheet1.getCell(0,0);
var lastCell = sheet1.getCell(data.length - 1, data[0].length - 1);
var range = firstCell.getBoundingRect(lastCell).insert('down');
range.values = data; // insert data
range.format.font.bold = true;
range.delete('up'); // erase data, shift up
return ctx.sync();
}).catch(function(error) {
console.log(error);
})
Try it out in the Office JS Snippet explorer and see the blog post linked below for more info!
https://github.com/OfficeDev/office-js-snippet-explorer
https://dev.office.com/blogs/Office-js-Public-Preview

Delete Existing Ranges in Excel Open XML

I'm working with the Open XML SDK to create an Excel document. To save time, I start with an existing document, and just make the changes I need.
To locate certain cells, my existing document defines a number of ranges. However, when I'm done I'd like to remove those ranges.
I can't seem to find any way to remove ranges from an Excel document that already has them. Any tips, suggestions or links?
Ranges are stored as defined names under the workbook element. You will need to find the defined name element based on the name you gave it in the worksheet and then delete it that way.
public void DeleteRange(WorkbooPart workbookPart, string definedNameToDelete)
{
workbookPart.Workbook.DefinedNames.Descendants<DefinedName>().First(x => x.Name == definedNameToDelete).Remove();
}
This is just a quick snippet of what you might have to do. Obviously, you might need error checking if the DefinedNames element doesn't exist or the defined named you want to delete has already been deleted, but hopefully this will point you in the right direction.
Named ranges are defined in workbook.
Look at it's api and try finding it there. Or check out MSDN.
Also, take a look at Templater. Maybe it already does what you need. Disclamer: I'm the author.

Resources