google spreadsheet script - how to get the reference to a specific block inside method - reference

I am currently trying to fill a block with a int from a method that I wrote with the script editor.
And ofcourse I know I can just left click a block and type the number in, but I need to do more than that.
I have no experience in java script, but I code in JAVA, so I could understand a lot of it.
I have the following code inside my method:
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet[5][15] = 60 ; // I have stripe down almost everything to where my problem occurred
I am trying to fill row 5, column O with 60. But it isn't working.
I tried sheet[5][O] = 60; but this doesn't work neither.
So how can I refer to the location 5,O on the sheet and give it a value?

sheet.getRange("O5").setValue(60);
or
sheet.getRange(5, 15).setValue(60);

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;

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.

QTP row and column count is always 1

I am writing a piece of code to copy data from a web table to an excel sheet. I don't understand why I am getting row count and column count 1. Is there something else that I need to add?
Here is my code:
Dim XL
Set XL=createobject("Excel.Application")
XL.Workbooks.Open "D:\QTP\RailwaysforSurat.xlsx"
Set nsheet = XL.Sheets.Item(1)
row=Browser("title:=.*").Page("title:=.*").WebTable("html tag:=TABLE", "index:=0").GetROProperty("rows")
msgbox row
cols=Browser("title:=.*").Page("title:=.*").WebTable("html tag:=TABLE", "index:=1").GetROProperty("cols")
msgbox cols
This not complete code. I have trouble getting rows and columns count. Please help!
P.S. I am using this website for the testing "http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi"
I noticed that you are using Descriptive Programming techniques to identify the WebTable, but you're using extremely generic descriptions for everything. Perhaps that's just scrubbed for the sake of posting publicly, but the important thing that I notice is that your code to read Rows is trying to find a table with Index of 0 and your code to read Cols is trying to find a table with index of 1...
This means you are accessing two different tables. Are you sure that your descriptions are finding the table that you think you want?
My suggestion is to:
1) bring up the page in your browser so that you can see the table.
2) Bring up QTP and open the GuiSPY
3) Click the pointing hand over a cube button to begin spying
4) Click on something inside the table you are trying to work with.
GuiSPY will snap back and show a hierarchy of objects that it found. Next, you want to positively identify what level in that hierarchy is the table at... I would...
5) starting at the top (Browser), select the top row and click "Highlight in Application" and watch what gets lit up.
6) go down the hierarchy list clicking the next item in the hierarchy and clicking "Highlight in Application" until you see it flash on the exact table you're trying to target.
7) Once you have isolated the table, click the button for "Copy the identification properties to the clipboard" button, then close GuiSPY.
8) Open a notepad, or just use QTP's editor window itself and paste in what GuiSPY copied to clipboard.
Ok, you now have a complete list of everything QTP was able to see about the specific table you want to detect. From here, you want to look through the list of properties and find one (or two) that would positively identify that table every time.. For example, on this very page, the table that holds your question could be identified as:
WebTable("text:=I am writing a piece of code to copy data")... (*note I've shaved it down because it's automatically a Regex string... With some cleanup, it could be:
Browser("StackOverFlow.Com").Page("Question 36663629").WebTable("text:=I am writing a piece of code to copy data"))
Now replace your .WebTable("html tag:=TABLE", "index:=0") with that data you've selected, and try it again. Hopefully you can lock in on the exact table you're expecting and get the info you need.
The indianrail page did not open so cannot see the table you are testing. But QTP provides default methods for rows and columns, try using that and see if it works.
NumRows = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").RowCount
NumColumns = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").ColumnCount(1)
ColumnCount takes row number as parameter
Not sure what tables you are looking at, but if it is Services and information then the rows/cols value for those table is 1.The whole web page is consisted of concatenated web tables. So its going to be little tricky to capture that information. Try using a child object method and count the number of links within the web table, its going to look something like this -
Set oWebEdit=Description.Create
oWebLink("micclass").value="Link"
Set olink = Browser("title:=.*").Page("title:=.*").WebTable("").childobjects(oWebLink)
olink.count
msgbox olink.count
'Then initiate a for loop
For i = 0 to olink.count-1
' Get the link name
olink. count(i).GetRoproperty("name")
'Initiate an array and save the link names
If get link name does not work then you can use childitem method.
Also make sure you are using the correct index for the tables or define some other properties as well.
P.S. If you are going to use DP in future and haven't already then read about Childitems/childobjects methods.They come in real handy while using DP.

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

Limit of 50 =importData functions per sheet - workaround?

In a sheet of mine I used 50 importData functions to shorten links via bit.ly automatically. Unfortunately, there is a limit of 50 functions per sheet which doesn't allow me to add more functions.
I don't want to open up more and more sheets, because that would be messy long term. Do you have recommendations for a workaround?
Create a custom function and put this to get the contents of your url:
var info = UrlFetchApp.fetch("yourURL");
Process the info and return it.
You might need to use
Utilities.sleep(1000);
...between the calls in order to get a value for every cell.

Resources