This is a follow up question to this previous question: Google sheets IMPORTXML Return no Data N/A
Given the following XML (has namespace) I want to query the CODE number inside CPV_CODE.
<CPV_CODE CODE="90524400"/>
With XPATH I would simply use: /CPV_CODE/#CODE but as I have to use local-name (due to namespace) I have no idea how to get it.
I tried
=importxml(url,"//*[local-name() ='CPV_CODE']")
but it does not return the #CODE number.
In your situation, how about the following xpath?
Sample xpath:
//*[local-name()='CPV_MAIN']/*[local-name()='CPV_CODE']/#CODE
Or
//*[local-name()='CPV_MAIN']//#CODE
Modified formula:
=IMPORTXML(A1,"//*[local-name()='CPV_MAIN']/*[local-name()='CPV_CODE']/#CODE")
Or
=IMPORTXML(A1,"//*[local-name()='CPV_MAIN']//#CODE")
In this case, the URL is put in the cell "A1".
Result:
Note:
In the URL, it seems that there are 2 CPV_CODE tags. If you want to retrieve <CPV_CODE CODE="90524200"/>, how about the following formula?
=IMPORTXML(A1,"//*[local-name()='CPV_ADDITIONAL']/*[local-name()='CPV_CODE']/#CODE")
Or
=IMPORTXML(A1,"//*[local-name()='CPV_ADDITIONAL']//#CODE")
Reference:
IMPORTXML
Related
I'm currently interested in building a custom function/formula in Google Spreadsheet where the function will intake a cell and return a value that is related to a specific text in a list.
As you can see in the screenshot, which is a demo that I drafted to give a better idea of what I'm trying to accomplish, column A contains a list of items that has random texts. In the texts, there are some keywords that I would like to identify into different categories.
Column B is just a demo of how I envision to use my custom function that I want to create. Column C is the expected result that I would get by using the custom function.
Column E is the list of keywords that I would like the custom function to search for in cells and Column F is the category that I would like the custom function to return once it finds the relevant keyword in a text.
Thank you!
I tried searching for this topic, but I only came across how to set up an array formula to achieve what I want to do. If there was any post about this, I would really appreciate if you could just link it in the comment.
Given your scenario, you can try with this formula:
=FILTER(F:F,INDEX(REGEXMATCH(A2,"(?i)"&E:E)),E:E<>"")
If you wish to have it for the whole row:
=BYROW(A2:A,LAMBDA(each,IF(each="","",FILTER(F:F,INDEX(REGEXMATCH(each,"(?i)"&E:E)),E:E<>""))))
If you could have more than one result, you can add JOIN:
=BYROW(A2:A,LAMBDA(each,IF(each="","",JOIN(", ",FILTER(F:F,INDEX(REGEXMATCH(each,"(?i)"&E:E)),E:E<>"")))))
So the main idea is I want to put a Hyperlink on a cell that contains a formula, But google sheet don't like that.
I had 2 ideas.
1- Put the formula in cell A1 and the output of that formula is dumped into cell A2 which is gonna be Hyperlinked.
(I tried to use FILTER to pull data into the Hyperlinked cell but it would give me a #REF! error:Array result was not expanded because it would overwrite data in A2.)
2- Use some sort of apps-script of which I have very little understanding of, so I didn't find any scripts relating to my question.
I didn't understand the reason why you can't put a Hyperlink AND a formula in the same cell, But as far as I understood:
Hyperlink is a formula it self → =HYPERLINK(url, [link_label])
So instead of Hyperlinking our cell using the UI, we can use the formula form to Hyperlink the cell and use our formula in the place of [link_label] which is gonna be the name of our cell:
=HYPERLINK( url , [link_label])
=HYPERLINK("google.com", SUM(B2:B5 ))
I'm trying to use a function to get the hexadecimal code of the cell background and concatenate it with the text contained in the same cell.
i.e. in sht1.cell(A1) I type "Hello" with red background, I would have in sht2.cell(A1) the following text: "[#FF0000]Hello"
I was trying this:
function getHexValue(range) {
return SpreadsheetApp.getActiveSheet().getRange(range).getBackground();
}
but it doesn't always work, especially if I share the file. I tried to setup some triggers using edit, change or open events but id keeps not updating
this is what i tried to do.
Any suggestion?
If I type: =gethexvalue("A5") I get the color code, if I type the formula to another cell or another sheet and I update the values or reload the sheet it doesn't work.
In your formula =gethexvalue("A5"), "A5" is text, not a dynamic range.
Read How to pass a range into a custom function in Google Spreadsheets? for a full discussion and 11 different answers. This is itself a possible duplicate of passing cell references to spreadsheet functions.
This =getHexValue(ADDRESS(ROW(A1), COLUMN(A1)))&A1 is dynamic. It will return:
"#ff0000Hello"
. If you want the hex in Uppercase, then use UPPER with getHexvalue.
I have the following script in my Code.hs file:
function getData() {
return SpreadsheetApp
.openById('17zMVbzevOV7HNpGIjkFKi_l_kUeuX7NX2jG5GIL8Jow')
.getActiveSheet()
.getDataRange()
.getValues();
}
However, if a cell contains:
"this is a test"
where "is" is in bold, when I get the data in the spreadsheet, I have:
"this is a test"
Without bolding.
Is there a way to get the text contents and the IN-string formatting (NOT the cell formatting) somehow?
Unfortunately there is not a way to get the in-string formatting. The closest I can find is a Range method getFontStyle()
However this returns 'italic' if the whole string is italic, and 'normal' if it isn't. It does not identify bold, nor does it identify if part of the string is bold or italic.
The Spreadsheet Service of Google Apps Script doesn't includes yet a method to handle the format for cell content parts. At this time one alternative is to use copyTo(destination) or copyTo(destination, options) from the Class Range.
I have a simple ImportXml function in Google spreadsheet:
=ImportXml( "http://www.google.com/finance?q=0322.hk", "//span[#class='chr']" )
but it is giving me 2 cells of data, the cell direction underneath it is a =Continue(blah blah)... automatically placed by Google.
Here is the HTML code associated with this page. Looks like it has 2 items. I've replaced "<" & ">" with "(" & ")"
(span class="ch bld")(span class="chr" id="ref_673324_c")-0.45(/span)
(span class="chr" id="ref_673324_cp")(-2.02%)(/span)
How do I change my ImportXml function so that I'm only importing the "-0.45" without the "(-2.02%)?
I've also found that the INDEX command works... useful too if you want the 2nd (-2.02%) item in the results. One important note, though, is that you've got to first transpose the output of ImportXML or it won't work.
=INDEX( TRANSPOSE (ImportXML (...)), {num}) where num is the desired result.
I found a work around... I put =NOEXPAND function infront of it and it works. but if anybody has another solution let me know.