All negative numbers in my report will need to be red. Is there any way I can do this through the number formatting? If not, is it possible to create a dynamic conditional somewhere that would check the current text field?
for example:
If this Textfield < 0 then this texfield font is red
Keep in mind, it would need to be dynamic in the sense that I could drop it on all the textfields without changing the condition.
I do understand conditional styles, however rather than using specific fields for the condition (as in the question this is marked for duplicate against) I'd like to allow the condition to be dragged onto any text field and distinguish whether or not it is less than 0.
You cannot achieve this with conditional styles.
The solution would be to create a custom formatter that would output styled text and have the textField configured with markup="styled" like so:
<textField>
<reportElement x="72" y="16" width="100" height="24" uuid="698866c8-7d26-4bc7-8727-b4a56d239a53"/>
<textElement markup="styled"/>
<textFieldExpression><![CDATA[NegativeNumberFormatter.format($F{A1}, "#,##0.###")]]></textFieldExpression>
</textField>
NegativeNumberFormatter might look like this(using default package):
import java.text.DecimalFormat;
public class NegativeNumberFormatter {
public static String format(Number n, String pattern) {
if (n != null) {
if (n.doubleValue() < 0) {
DecimalFormat df = new DecimalFormat();
if (pattern != null) {
df.applyPattern(pattern);
}
return "<font color=\"red\">" + df.format(n) + "</font>";
} else {
return "" + n;
}
}
return null;
}
}
Related
I am doing Gtkmm GUI programming now and I am new to this programming language.
How to allow the user to only enter the numeric value in Gtkmm Entry text box.
Use Gtk::SpinButton instead of Gtk::Entry to allow numeric input only.
you need to add a key release signal for your Entry for example this is my entry "m_EntryAmount"
m_EntryAmount.signal_key_release_event().connect(sigc::mem_fun(*this, &Vente::entryKeyReleaseAmount));
and add the signal function
bool Sales::entryKeyReleaseAmount(GdkEventKey* /* event */ )
{
if(m_EntryAmount.get_text()!="" && is_number(m_EntryAmount.get_text()) ){
//now the Entry is not empty and its a number
//do what you want here
}else{
//here the Entry is not a number you can just delete it
m_EntryAmount.set_text("");
}
return true;
}
and add the is_number function
bool Vente::is_number(const string& s)
{
return !s.empty() && std::find_if(s.begin(),
s.end(), [](char c) { return !std::isdigit(c); }) == s.end();
}
this is just a simple example to make an idea about that, you can do it by your self using your way
By the help of some very kind community members here I managed to programatically create a function to replace text inside content controls in a Word document using open xml. After the document is generated it removes the formatting of the text after I replace the text.
Any ideas on how I can still keep the formatting in word and remove the content control tags ?
This is my code:
using (var wordDoc = WordprocessingDocument.Open(mem, true))
{
var mainPart = wordDoc.MainDocumentPart;
ReplaceTags(mainPart, "FirstName", _firstName);
ReplaceTags(mainPart, "LastName", _lastName);
ReplaceTags(mainPart, "WorkPhoe", _workPhone);
ReplaceTags(mainPart, "JobTitle", _jobTitle);
mainPart.Document.Save();
SaveFile(mem);
}
private static void ReplaceTags(MainDocumentPart mainPart, string tagName, string tagValue)
{
//grab all the tag fields
IEnumerable<SdtBlock> tagFields = mainPart.Document.Body.Descendants<SdtBlock>().Where
(r => r.SdtProperties.GetFirstChild<Tag>().Val == tagName);
foreach (var field in tagFields)
{
//remove all paragraphs from the content block
field.SdtContentBlock.RemoveAllChildren<Paragraph>();
//create a new paragraph containing a run and a text element
Paragraph newParagraph = new Paragraph();
Run newRun = new Run();
Text newText = new Text(tagValue);
newRun.Append(newText);
newParagraph.Append(newRun);
//add the new paragraph to the content block
field.SdtContentBlock.Append(newParagraph);
}
}
Keeping the style is a tricky problem as there could be more than one style applied to the text you are trying to replace. What should you do in that scenario?
Assuming a simple case of one style (but potentially over many Paragraphs, Runs and Texts) you could keep the first Text element you come across per SdtBlock and place your required value in that element then delete any further Text elements from the SdtBlock. The formatting from the first Text element will then be maintained. Obviously you can apply this theory to any of the Text blocks; you don't have to necessarily use the first. The following code should show what I mean:
private static void ReplaceTags(MainDocumentPart mainPart, string tagName, string tagValue)
{
IEnumerable<SdtBlock> tagFields = mainPart.Document.Body.Descendants<SdtBlock>().Where
(r => r.SdtProperties.GetFirstChild<Tag>().Val == tagName);
foreach (var field in tagFields)
{
IEnumerable<Text> texts = field.SdtContentBlock.Descendants<Text>();
for (int i = 0; i < texts.Count(); i++)
{
Text text = texts.ElementAt(i);
if (i == 0)
{
text.Text = tagValue;
}
else
{
text.Remove();
}
}
}
}
I am struggling with kendo-ui grid foreign key column and mvvm
I would like to be able to combine the "Foreign Key Column" example with the "MVVM" example
My question is: "how do I data-bind the values property of a look-up field?"
So this is kind of an older post, but I just had to work around the same issue and found this while trying to solve. Figured I'd answer the question for posterity.
The "values" property doesn't seem to work 100% in the kendo grid in MVVM. I have worked around this in a two step process.
Tack "this.viewModel" (where "viewModel" is whatever you are calling your VM) in front of the "loggerSeverityValues". This will give you a dropdownlist when editing the field.
Utilize the template functionality to display the correct value in the grid. I use a little function to make this easier:
getText: function (matchValue, valuesArray, text, value)
{
if (text === undefined)
{
text = 'text';
}
if (value === undefined)
{
value = 'value';
}
var retText = "No Value Found";
finalArr = $.grep(valuesArray, function (val, integer)
{
return val[value] == matchValue;
});
if (finalArr.length > 0)
{
retText = finalArr[0].text;
}
return retText;
}
The final look of the field will be something along the lines of this:
{ field: 'severity', width: 270, values: this.viewModel.loggerSeverityValues, template: '#: getText(severity, this.viewModel.loggerSeverityValues) #' }
Note that with the getText() function you can override the text and value parameters if you need to.
Anyway this worked for me. Kind of a workaround, but as of release 2014.3.1411 anyway it doesn't appear that the kendo MVVM bindings will work properly with foreign keys.
EDIT:
For anyone now using the kendo ng2+ components, same pattern but with a pipe transform works.
Pipe:
import { Pipe, PipeTransform } from '#angular/core';
#Pipe({ name: 'getText' })
export class GetTextPipe implements PipeTransform {
transform(value: any, idPropertyName: string, valuePropertyName: string, valueArray: any[]): any {
if (value != null && valueArray != undefined) {
let retIndex = valueArray.map(v => v[idPropertyName]).indexOf(value);
return valueArray[retIndex][valuePropertyName];
}
else {
return '';
}
}
}
Usage:
<kendo-grid-column field="severity" title="Severity" width="150px">
<template kendoGridCellTemplate let-dataItem="dataItem">
{{dataItem.severity | getText:'severity':'severityName':loggerSeverityValues}}
</template>
</kendo-grid-column>
I'm using getElementsByTagName to return all the select lists on a page - is it possible to then filter these based upon an option value, ie of the first or second item in the list?
The reason is that for reasons I won't go into here there are a block of select lists with number values (1,2,3,4,5 etc) and others which have text values (Blue and Black, Red and Black etc) and I only want the scripting I have to run on the ones with numerical values. I can't add a class to them which would more easily let me do this however I can be certain that the first option value in the list will be "1".
Therefore is there a way to filter the returned list of selects on the page by only those whose first option value is "1"?
I am pretty sure that there is a better solution, but for the moment you can try something like:
var allSelect = document.getElementsByTagName("select");
var result = filterBy(allSelect, 0/*0 == The first option*/, "1"/* 1 == the value of the first option*/);
function filterBy(allSelect, index, theValue) {
var result = [];
for (var i = 0; i < allSelect.length; i++) {
if(allSelect[i].options[index].value == theValue ) {
result.push(allSelect[i]);
}
}
return result;
}
I managed to get this working by wrapping a simple IF statement around the action to be performed (in this case, disabling options) as follows:
inputs = document.getElementsByTagName('select');
for (i = 0; i < inputs.length; i++) {
if (inputs[i].options[1].text == 1) {
// perform action required
}
}
No doubt there is a slicker or more economic way to do this but the main thing is it works for me.
I am trying to retrieve the value of all fields in a word document via office automation using c#. The code is shown below however if the field is a drop-down then the value of the range text is always empty even though I know it is populated. If it is a simple text field then I can see the range text. How do I get the selected drop down item? I feel there must be something quite simple that I'm doing wrong...
private void OpenWordDoc(string filename) {
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Document doc = app.Documents.Open(filename, ReadOnly: true, Visible: false);
foreach (Field f in doc.Fields) {
string bookmarkName = "??";
if (f.Code.Bookmarks.Count > 0) {
bookmarkName = f.Code.Bookmarks[1].Name; // have to start at 1 because it is vb style!
}
Debug.WriteLine(bookmarkName);
Debug.WriteLine(f.Result.Text); // This is empty when it is a drop down field
}
doc.Close();
app.Quit();
}
Aha - If I scan through FormFields instead of Fields then all is good...
foreach (FormField f in doc.FormFields) {
string bookmarkName = "??";
if (ff.Range.Bookmarks.Count > 0) {
bookmarkName = ff.Range.Bookmarks[1].Name; // have to start at 1 because it is vb style!
}
Debug.WriteLine(bookmarkName);
Debug.WriteLine(ff.Result); // This is empty when it is a drop down field
}
Problem solved. Phew.