void detail_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
{
if (e.VariableName == "Annotations")
{
StringBuilder annotationsSB = new StringBuilder();
int row = 0;
TimeSpan Time = new TimeSpan(1,1,1);
String annotationLine =
String.Format(
@"\trowd\irow{2}\irowband{2}\trbrdrt\brdrs\brdrw10\trbrdrl\brdrs\brdrw10\trbrdrb\brdrs\brdrw10\trbrdrr\brdrs\brdrw10\trleft-108\trftsWidth1\trautofit1\trpaddfl3\trpaddl108\trpaddfr3\trpaddr108\clvertalt\clbrdrt\brdrnone\clbrdrl\brdrnone\clbrdrb\brdrnone\clbrdrr\brdrnone\cltxlrtb\clftsWidth3\clwWidth1564\clpadfr3\clpadr108\clpadft3\clpadt108\cellx1454\clvertalt\clbrdrt\brdrnone\clbrdrl\brdrnone\clbrdrb\brdrnone\clbrdrr\brdrnone\cltxlrtb\clftsWidth3\clwWidth8342\clpadfr3\clpadr108\clpadft3\clpadt108\cellx9792{3}\pard\plain\ql\intbl{{\f2\cf0 {0}}}\cell\pard\plain\ql\intbl{{\f2\cf0 {1}}}\cell",
String.Format("{0:D2}:{1:D2}:{2:D2}", Time.Hours, Time.Minutes, Time.Seconds),
"Polish chars: Ą,Ć,Ę,Ł,Ń,Ó,Ś,Ź,Ż,ą,ć,ę,ł,ń,ó,ś,ź,ż", row, (row > 0) ? @"\row" : "" );
annotationsSB.Append(Encode(annotationLine));
RichEditDocumentServer result = new RichEditDocumentServer();
result.CreateNewDocument();
result.Document.AppendRtfText(
@"{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}{\f1 Symbol;}{\f2 Arial;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{\stylesheet {\ql\cf0 Normal;}{\*\cs1\cf0 Default Paragraph Font;}{\*\cs2\sbasedon1\cf0 Line Number;}{\*\cs3\ul\cf1 Hyperlink;}}\sectd\pard\plain\ql" + annotationsSB.ToString() + @"\trowd\irow" + row + @"\irowband" + row + @"\lastrow\trbrdrt\brdrs\brdrw10\trbrdrl\brdrs\brdrw10\trbrdrb\brdrs\brdrw10\trbrdrr\brdrs\brdrw10\trleft-108\trftsWidth1\trautofit1\trpaddfl3\trpaddl108\trpaddfr3\trpaddr108\clvertalt\clbrdrt\brdrnone\clbrdrl\brdrnone\clbrdrb\brdrnone\clbrdrr\brdrnone\cltxlrtb\clftsWidth3\clwWidth1564\clpadfr3\clpadr108\clpadft3\clpadt108\cellx1454\clvertalt\clbrdrt\brdrnone\clbrdrl\brdrnone\clbrdrb\brdrnone\clbrdrr\brdrnone\cltxlrtb\clftsWidth3\clwWidth8342\clpadfr3\clpadr108\clpadft3\clpadt108\cellx9792\row\pard\plain\ql\par}");
e.Value = result;
e.Handled = true;
}
}
Miroslaw,
Thank you for the feedback. I am afraid that I still cannot replicate a similar issue by using XtraRichEdit demo project. Attached is a sample screencast that illustrates my actions. Please let me know if I missed anything important.
Thanks,
Alessandro.
It is all about Document.AppendRtfText and insert it within CalculateDocumentVariables. Editing document itself in richedit control works fine (national characters are replaced with its code representation) so there is no problem like in Your screencast. The problem is when I want to insert national characters into document from code.
When I encode this chars manually by uning additional method Encode(annotationLine) and replace all chars with its code representation there is ok. But Is threre a way to insert rtf with this chars from code by using AppendRtfText?
Additionally when I use code to merge master detail like in demo example it doesn't work (this is copy paste from demo example project):
void Document_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
{
if (e.VariableName == "Annotations")
{
details.Options.MailMerge.DataSource = annotations;
RichEditDocumentServer result = new RichEditDocumentServer();
MailMergeOptions options = details.CreateMailMergeOptions();
options.MergeMode = MergeMode.JoinTables;
result.CalculateDocumentVariable += detail_CalculateDocumentVariable; // it should be called
details.MailMerge(options, result);
result.CalculateDocumentVariable -= detail_CalculateDocumentVariable;
}
}
// this method is never called
void detail_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
{
string time = e.Arguments[0].Value;
if (e.VariableName == "Time")
{
e.Value = "x";
e.Handled = true;
}
}
Hi Miroslaw,
Thank you for your clarification.
Please note that all high-characters (all above 127) symbols should be escaped with \u in the RTF format. See the specs here: http://support.microsoft.com/kb/q86999/
>>>>
Additionally when I use code to merge master detail like in demo example it doesn't work (this is copy paste from demo example project):
<<<<
Would you please modify the How to use document variable (DOCVARIABLE) fields code example to reproduce this issue on our side? This will make the situation clearer
Thanks,
Elliot
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.
Facebook
Twitter
Google+