How to set bold font to only one word from a cell? The documentation shows how to set all cells to a font type. As an example, I'll add a <b> tag to show which word will be in bold.
ws.cell(index + 4, 2).string(p[i].dataValues.diameter + '\n' + '<b>' + psw[i].dataValues.well + '</b>').style(styleText);
Related
The requirements from the customer state that a record's Comment and Description fields must be displayed in the same cell but the text of the Comment must be displayed in red while the Description should be black. Using a mutator, I can combine the 2 fields and display them in one cell, but I haven't seen how to make one have red text and the other black text within that cell.
Is there a way?
Thanks,
Matt
I wouldnt bother doing that, just use a Customer Formatter function
formatter:function(cell, formatterParams, onRendered){
return '<span style=color:red>' + cell.getRow().getData().Comment + '</span><P><span style=color:black>' + cell.getRow().getData().Description + '</span></p>';
}
In the cell below, I want to get whatever is separated by a comma to come to a new line. I can add these line breaks manually with alt+enter, but this time I want to automate it.
BCM:Open,Event:Site XXXX is down,Service Affected :2G,Impact :Coverage
Restored at XXXX Area,Reason:Under Investigation,Recovery Time :30
Minutes,Start time:14:25:13,End Time:15:18:03,Duration:00:52:50,SLA:1
Hour.
For some reason, none of the above worked for me. This DID however:
Selected the range of cells I needed to replace.
Go to Home > Find & Select > Replace or Ctrl + H
Find what: ,
Replace with: CTRL + SHIFT + J
Click Replace All
Somehow CTRL + SHIFT + J is registered as a linebreak.
To replace commas with newline characters use this formula (assuming that the text to be altered is in cell A1):
=SUBSTITUTE(A1,",",CHAR(10))
You may have to then alter the row height to see all of the values in the cell
I've left a comment about the other part of your question
Edit: here's a screenshot of this working - I had to turn on "Wrap Text" in the "Format Cells" dialog.
Use
=SUBSTITUTE(A1,",",CHAR(10) & CHAR(13))
This will replace each comma with a new line. Change A1 to the cell you are referencing.
You can also do this without VBA from the find/replace dialogue box. My answer was at https://stackoverflow.com/a/6116681/509840 .
Windows (unlike some other OS's, like Linux), uses CR+LF for line breaks:
CR = 13 = 0x0D = ^M = \r = carriage return
LF = 10 = 0x0A = ^J = \n = new line
The characters need to be in that order, if you want the line breaks to be consistently visible when copied to other Windows programs. So the Excel function would be:
=SUBSTITUTE(A1,",",CHAR(13) & CHAR(10))
I am trying to add few jpeg pictures (up to 6) from excel worksheet in a table (word document), but only one appears at the end. Each time I am adding a picture it goes over the previous one. Here a part of my code with the issue:
' Filling the table
For i = 1 To iNumChem
' Column 1
wdTable.Rows(i + 1).Cells(1).Range.Text = Sheet1.Cells(a + 1 + 2 * i - 2, 5).Value
' Column 2
wdTable.Rows(i + 1).Cells(2).Range.Text = Sheet1.Cells(a + 1 + 2 * i - 2, 31).Value
' Column 3
For p = 0 To 5
If Sheet1.Cells(a + 2 * i, 5 + 2 * p).Value <> 0 Then
Sheet3.Shapes(Sheet1.Cells(a + 2 * i, 5 + 2 * p).Value).Copy
wdTable.Rows(i + 1).Cells(3).Range.PasteSpecial
End If
Next p
' Column 4
Next i
I tried to work with the properties ParagraphFormat and Move, but it didn't help.
I usually find difficult to move "the cursor" to the right position to be able to add something, especially in this case with Pictures (not Shapes) to add side by side.
Any ideas/comments are welcome.
Note: Edited after comments as I mixed the terms shape and picture!
I am trying to take pictures from Excel and add them in the same cell of a table word.
When you paste the shape it won't be in the cell, it will be anchored to it but float above it. This is just the same as in Excel where the shape floats above the worksheet and hides the cells below it.
To have the shape in the table you'll need to set the wrap type to inline, otherwise the shapes will stack up on top of each other.
With wdTable.Rows(i + 1).Cells(3).Range
.PasteSpecial
.ShapeRange(1).WrapFormat.Type = wdWrapInline
End With
EDIT:
Pictures are pasted into Word as InlineShapes. They do not stack up one on top of the other. If you attempt to paste more than one into wdTable.Rows(i + 1).Cells(3).Range each one will overwrite the last. Instead you need to declare a variable outside the loop, something like wdCellRange as Word.Range, and then use it when inserting the pictures, e.g.
Set wdCellRange = wdTable.Rows(i + 1).Cells(3).Range
With wdCellRange
.Collapse Direction:= wdCollapseEnd
.PasteSpecial
End With
You could try:
...Range.Collapse Direction:= wdCollapseEnd
I want to highlight the strings before and after '--'. Example good -- bad here i want to highlight good and bad. when ever the -- is comes then before and after the strings are become highlight. Is it possible.
Let's assume you have the following text in a field "mytext":
This text comes before -- this text comes after.
LiveCode (as most applications) does not allow discontinuous selections, so the 'select' command only works on continuous runs of text.
select word 1 to 3 of fld "mytext"
But you can simulate selection highlighting by setting the backgroundColor property of separate text runs:
put wordOffset("--",fld "mytext") into tWordIndex
set the backgroundColor of word 1 to tWordIndex - 1 of fld "mytext" to the hiliteColor
set the backgroundColor of word tWordIndex + 1 to -1 of fld "mytext" to the hiliteColor
Of course you can use any valid text chunk expression in the two 'set' statements, depending on what part of the text preceding and following the " -- " you want to "highlight".
To clear the backgroundColor from the field do this:
set the backgroundColor of char 1 to -1 of fld "mytext" to empty
I have code that will automatically adjust the height of a cell, so that text will fit inside that cell.
However now I want to change the fontsize of the text inside the cell, so that the font will shrink and grow to make the text fit inside the cell, so I don't have to make the cell width a fixed size.
How do I do this in VBA?
I need to know the width of text, given a font size
Option 1.
TextWidth = WidthOfAText(Range("A1").Value)
FontAdjustmentFactor = Range("A1").EntireColumn.ColumnWidth / TextWidth
FontSize = Range("A1").Font.Size * FontAdjustmentFactor
Range("A1").Font.Size = Max(4, Min(10, FontSize))
or I need to know whether the text will fix and do some sort of trial and error routine.
Option 2.
Range("A1").Font.Size = 10
While (Text_does_not_fit AND Range("A1").Font.Size >= 5)
Range("A1").Font.Size = Range("A1").Font.Size - 1
Wend
How do I do this? (Preferably using code like in option 1)
Non programatically just right click on the cell -> Format Cells -> Alignment -> Shrink to Fit
Code wise is:
Sheet1.Range("A1").ShrinkToFit = True