How to generate code cells in google colab? - google-colaboratory

Is it possible to generate code cells in google colab with a given text? A code that creates more code?
Something like:
create_cell("print('Hello world')")
So the result would be another cell with the code print('Hello world').

Related

How to retrive the notebook contents or the url of a particular cell in Google colab

Is there a way to get or compute the URL to a cell in Colab? I know you can click on a link button to get the url, or click on the TOC and get the #scrollTo=J1nFJPC9V1-X part of the URL, but I want a way to generate this.
The use case is I search colabs for headlines, and I want to generate a link that opens a colab to that heading. Suppose I know the id for a colab, and I know it has a heading called "Printing arrays". I want to generate a full link that opens it at that cell.
Is it possible to compute the scrollTo part, or retrieve it somehow?
Here's an example snippet that will find the cell ID with particular contents:
from google.colab import _message
# Load the notebook JSON.
nb = _message.blocking_request('get_ipynb')
# Search for the markdown cell with the particular contents.
for cell in nb['ipynb']['cells']:
if (cell['cell_type'] == 'markdown' and
'\n'.join(cell['source']).find('## Printing arrays') >= 0):
print (f'Cell ID for header is #{cell["metadata"]["id"]}')
Here's a complete example notebook:
https://colab.research.google.com/drive/11jOuhB7wzm1d2P85mrmhBWycogJ_9F0q

Is it possible to get the text from a text cell with a code cell in google colab?

I'm trying to make a word counter of my text cells. My idea was to somehow get the text from the text cells and then work the strings. I would like to know if it is possible.
Yup, here's an example:
https://colab.research.google.com/drive/1dxq_K3vgIYjxDL7DpxoHRfJEQbxThM57
The three cells do three things:
Authenticate for access to Drive.
Download the JSON content of the notebook.
Count the words for the markdown cells in the notebook.

How can I check the time a cell was edited and set the time and date in other cells? Google script

I have spreadsheet and I'm basically going to use it for inventory tracking and management.
In one sheet I'll have an app on my phone fill a list when it reads
a QR code.
In the second sheet there is also a list with the
specific QR codes of each item.
I need to know when a cell in the first sheet has been updated and put that information in the following two cells.
I'm using this trigger to check if ANY cell in the document has been updated.
function cellEditTrigger()
{
ScriptApp.newTrigger('coolFunction').forSpreadsheet('awsomeSpreadsheetID').onEdit().create();
}
It works fine and it runs the 'coolFunction' function. However I can't seem to be able to get the time and date for the cells that have been edited and put that information in the next two cells.
I know I could use onEdit(e), but I still can't get the information from e.range and I would like my script to not have to be bound to the Spreadsheet.
Is there any way to accomplish this?

Excel VBA: How to search and copy a value of a certain pattern found within large texts in a column to another column?

As shown in the image above, I need to get the values following a pattern like for example TK AK15590 (TK AK followed by a series of numbers as shown) into cell B2. The same with the rest of the cells in the description column using vba macro in excel. Appreciate if anyone could give me a sample vba code or some information on how I could do this.
VBA is not requiered here. You should use formulas that manipulate text. In this particular case, the following would work:
=IFERROR(MID(A2,FIND("TK AK",A2),FIND(" ",A2,FIND("TK AK",A2)+4)-FIND("TK AK",A2)), "ERROR MESSAGE HERE")
When the length of the string you want to extract is fixed (10 in this case), you could simply use this:
=IFERROR(MID(A2,FIND("TK AK",A2),10), "ERROR MESSAGE HERE")

Add a URL image to a cell where the URL is based on input in another cell

I am moving over a worksheet from GoogleDocs that has to be in Excel now.
It is a barcode generator sheet.
The image cell in GoogleDocs has the formula is
=image("www.somebarcodesite.com/image.php?code=" & A2 & "&style=197&type=C128B&width=300&height=50&xres=1&font=3", 3)
I've downloaded as Excel but that has not helped (I think due to text concatenation) and additional rows may be need to be added so it's not enough to embed the image once when downloading.
I've seen VB solutions to put an image in a cell, but I'm not sure it would allow the users to add new rows to the worksheet.
Does anyone know where I should start on finding a scalable way to show the image generated at a url, where the url is generated dynamically based on the input of other cells?