I want to keep each sentence in the paragraph it's own Text view, because it has unique functionality on hover. Currently I'm using the WrappingHStack from here.
WrappingHStack(1...6, id:\.self) {
Text("This is number \($0). ")
}
This creates text like this:
This is number 1. This is number 2. | // bounds
This is number 3. This is number 4. |
This is number 5. This is number 5. |
What I want is like this:
This is number 1. This is number 2. This
is number 3. This is number 4. This is
number 5. This is number 6.
What's the best way to achieve this?
EDIT:
More context on what I'm trying to achieve. Let's say I have two sentences: Does the seal work? and el sello funciona? When a user hovers on seal, I'd like to highlight sello(that logic I can implement as the two sentences are structured and broken down). Where i'm struggling is to get text to look like a regular block of text, but to have unique hover behaviour on the sentence/word level.
I'm not sure but you can try it
ZStack {
(Text("title-1".localized)
+ Text("title-2".localized)
+ Text("title-3".localized))
.modifier(TitleTextRegular(foregroundColor: .bronze, font: .title))
}.frame(width: 800)
#peter you can achive Text as a paragraph by following code:
var varPara: String = ""
for index in 1...6 {
varPara = varPara != "" ? varPara + " This is number \(index)." : " This is number \(index)."
}
Output:
"This is number 1. This is number 2. This is number 3. This is number 4. This is number 5. This is number 6."
After that you need to assign string parameter to Text and then give highlight logic to Text.
Related
In Google Sheet, I want to highlight only 2 columns out of 5 columns.
5 columns here but I want to highlight only 'Name' and 'Weight' columns if a cell contain the word 'Smith'
The outcome should be like this.
I want to input more name and if the name contain the word 'Smith', I want it to be automatically highlighted for name and weight columns.
I tried to use conditional formatting in Google sheet, and I could highlight only the name column.
This is what I tried.
Outcome was this.
You are not far, try the following formula in the conditional formatting:
=IF(REGEXMATCH($C3, "Smith"), 1, 0)
The formula given by #nabais works.
In conditional formatting though one does not need to use the starting IF function.
"Format cells if" is how conditional formatting rules are formed by default as noted in the official help page.
Create a rule.
Single color: Under "Format cells if," choose the condition that you want to trigger the rule. Under "Formatting style, choose what the
cell will look like when conditions are met.
Color scale: Under "Preview," select the color scale. Then, choose a minimum and maximum value, and an optional midpoint value. To choose
the value category, click the Down arrow Down Arrow.
So the following formula is all that is needed:
(Please adjust ranges to your needs)
=REGEXMATCH($G2, "Smith")
You can try the following code:
function highlight() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data = ss.getRange('A1:E').getValues();
for (i = 1; i < data.length; i++) {
var tf = ss.getRange("B" + i).createTextFinder('smith');
tf.matchEntireCell(false);
tf.matchCase(false);
var result = tf.findNext();
if (result !== null) {
var range = result.getRow();
ss.getRange('B' + range).setBackground('Yellow');
ss.getRange('D' + range).setBackground('Yellow');
}
};
};
I have a Google Sheets cell containing a list of people attending an event. Some of the guests will bring friends. So the cell (A1) can look like this:
Ben, Sarah + 2, James , Mary + 5
I need to count the total number of people attending, which in this case is 11. And so I was thinking of using a formula along these lines:
=count(SPLIT(SUBSTITUTE(A1,"+",","),","))
But this doesn't work because it's only counting the numbers as 1 item, and the COUNT function doesn't appear to work.
How can I make this work, so that it correctly gives the number of attendees as 11?
You can use the following formula
=IF(LEN(A2),
SUM(COUNTA(SPLIT(A2,",")),
IFERROR(SPLIT(REGEXREPLACE(A2,"\D"," ")," "))),"")
Functions used:
IF
LEN
SUM
COUNTA
SPLIT
IFERROR
REGEXREPLACE
You can obtain the total sum by doing this:
=if(regexmatch(A1,"\+"),sum(ArrayFormula(query(split(transpose(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0))),if(isblank(A1),"",counta(split(A1,","))))
Explanation:
if(regexmatch(A1,"\+"), something, if(isblank(A1),"",counta(split(A1,",")))) => if there are not + signs in the answer, then check if the cell is empty or not, if empty, print blank, else just count how many people are between commas, otherwise calculate with the plus ones. (explanation below)
split(A1,",")),"\+") => red area => will separate the cell by commas, and the result can be seen in the red area in the picture
split(TRANSPOSE(split(A1,",")),"\+") => green area => will loop through each of the results above and separate to a cell on the right the values that have a + sign between them, can be seen in the green area in the image
query(split(TRANSPOSE(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0) => blue area => then we will query the 2 columns, in the left one we want to count the number of rows in that column (the columns with the names), on the next column we want to sum the values (the plus ones)
sum(ArrayFormula(query(split(transpose(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0))) => yellow area => then we will sum the values of the 2 columns to get the final result
I have a Actuals column like so:
ID | Airport
------------
A | 98.4
B | 98.0
C | 95.3
I'm attempting to format the numbers above into percentages for a front-end report. I have this written in a switch statement - for ease I'll just write the logic as an IF boolean.
example_measure =
VAR Nums = SELECTEDVALUES(Table[Actuals])
VAR FormatNums = IF(DIVIDE(ROUND(nums,1), nums) = 1,
format(nums,"0%"),format(nums,"0.0%")
-
RETURN
FormatNums
no matter what I do this always returns a number with a floating point value of 1f
so in my raw data of 98.0 I'm expecting the format to return "98%" rather than "98.0%"
the measures are used on individual cards, and are filtered so they can only ever show one value or blank, meaning they will only ever display one value on their own.
I've toyed with using if(nums = int(nums) which should evaluate to true for 98.0 but it I always get false.
There is a simpler way - just use built-in formatting codes:
Formatted Actuals =
VAR x = SELECTEDVALUE(Data[Actuals])
RETURN
FORMAT(x, "General Number") & "%"
Result:
Built-in style "General Number" handles your situation correctly, you just need to add % symbol to the formatted string. No need to test for whole numbers.
To convert a column/measure into percentage, you can simply divide the column by 100 and then format it as a percentage. Use the following steps:
Create a new column/measure: Perc_value = Table[Actuals]/100
Then go into the modelling tab, select the created column/measure and format it as a % and limit the number of decimal places to 0
This should give the view you are looking for. Hope this helps.
Edit:
You can use the below formula to achieve the desired result:
Column4 = IF('Table'[Column2]-ROUND('Table'[Column2],0)=0,FORMAT('Table'[Column2]/100,"0%"),FORMAT('Table'[Column2]/100,"0.0%"))
Replace Column2 withyour field and you should be good to go.
I'm am exploring methods of giving scores to different datapoints within a dataset. These points come from a mix of numbers and text string attributes looking for certain characteristics, e.g. if Col. A contains more than X number of "|", then give it a 1. If not, it gets a 0 for that category. I also have some that give the point when the value is >X.
I have been trying to do this with =IF, for example, =IF([sheet] = [Text], "1","0").
I can get it to give me 1 or 0, but I am unable to get a point total with sum.
I have tried changing the formatting of the text to both "number", "plain text", and have left it as automatic, but I can't get it to sum. Thoughts? Is there maybe a better way to do this?
FWIW - I'm trying to score based on about 12 factors.
Best,
Alex
The issue here might be that you're having the cell evaluate to either the string "0" or the string "1" rather than the number 0 or the number 1. That would explain why you're seeing the right things but the math isn't coming out right - the cell contents look like numbers, but they're really text, which the summation would then ignore.
One option would be to drop the quotation marks and write something like this:
=IF(condition, 1, 0)
This has the condition evaluate to 1 if it's true and 0 if it's false.
Alternatively, you could write something like this:
=(condition) * 1
This will take the boolean TRUE or FALSE returned by condition and convert it to either the numeric value 1 (true) or the numeric value 0 (false).
I have a google sheet that receives a list of phone numbers from an outside source. Phone numbers arrive in one of two formats:
Numbers that appear as 12345678901 are seen without error.
Numbers that appear as 1(234)567-8901 result in #ERROR!.
It seems that google sheets is reading the second set of numbers as a formula. When I click into an error cell, the phone number is preceded with "=+", as in "=+1(234)567-8901". I can fix this manually for the entire document by using Find and Replace with "Search within Formulas" checked.
Find: "=+"
Replace: " "
Is there any way to automate this within google apps scripts? I would like to run this function onEdit() so that #ERROR! phone numbers are fixed in real time.
You can remove the ()- characters using a spreadsheet formula, let's say the number was in cell A1, then in another cell you can put:
=CONCATENATE(SPLIT(A1, "()-" ))
which will remove the ()- characters.
If you would like to do this with a script then you can use replace to remove the ()-
.replace(/[()-]/gi, "")
apply above your number column range to properly format number.
EDIT
This should work, change "A1:A" to your column
function onEdit(){
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:A" + sheet.getLastRow());
var data = range.getValues();
var formulas = range.getFormulas();
for (var i=0;i< formulas.length;i++) {
if(typeof formulas[i] !== "undefined" && formulas[i] != ""){
formulas[i][0] = formulas[i][0].replace(/[=()+-]/gi, "");
data[i][0] = formulas[i][0].toString();
}
}
range.setValues(data).setNumberFormat("0");
}