How to insert ContentContol in footnote with specific range word.interop - c#

How to go add content control in specific start and end range of footnote? I can add content control in document.range, but I am unable to add in footnote, please help to do this. If anyone reply quickly, I will be proved of you.
public void FindItalicFootnote(String FindText)
{
foreach (Word.Footnote footNote in Word.Document.Footnotes)
{
Word.Range RngFind = footNote.Range;
RngFind.Find.Forward = true;
if (RngFind.Find.Execute(FindText))
{
while (RngFind.Find.Found)
{
RngFind.Select();
object strtRange = Word.Selection.Range.Start;
object endRange = Word.Selection.Range.End;
string placeHolder = "";
bool findCase = false;
if (Word.Selection.Range.ParentContentControl == null && Word.Selection.Range.ContentControls.Count == 0)
{
RngFind.Select();
while (Word.Selection.Previous(Unit: Word.WdUnits.wdWord, Count: 1).Font.Italic == -1)
{
Word.Selection.Previous(Unit: Word.WdUnits.wdWord, Count: 1).Select();
strtRange = Word.Selection.Range.Start;
placeHolder = "{VerifiedBy='Italic'}";
findCase = true;
}
Word.ContentControl CC = RngFind.ContentControls.Add(Word.WdContentControlType.wdContentControlRichText,
footNote.range(strtRange, endRange));
//my query is, how to say footNote.range(start, end), in main part I wrote as Word.Document.range(startRange, endRange)
CC.Title = "Case Reference";
CC.Tag = Guid.NewGuid().ToString();
CC.SetPlaceholderText(Text: placeHolder);
}
RngFind.Find.Execute(FindText);
}
}
}
}
Regards,
Saran

Related

Openxml inserts italics at bookmarks.(several characters in a string are italics)

Here is the code for my work.
public void InsertValue(WordprocessingDocument doc, string bookMark, string txt)
{
try
{
RemoveBookMarkContent(doc, bookMark);
var bmStart = FindBookMarkStart(doc, bookMark);
if (bmStart == null)
return;
var run = new Run();
run.Append(GetRunProperties());
run.Append(new Text(txt));
bmStart.Parent.InsertAfter(run, bmStart);
}
catch (Exception c)
{
//not Exception
}
}
private void RemoveBookMarkContent(WordprocessingDocument doc, string bmName)
{
BookmarkStart bmStart = FindBookMarkStart(doc, bmName);
if (bmStart == null)
return;
BookmarkEnd bmEnd = FindBookMarkEnd(doc, bmStart.Id);
while (true)
{
var run = bmStart.NextSibling();
if (run == null)
{
break;
}
if (run is BookmarkEnd && (BookmarkEnd)run == bmEnd)
{
break;
}
run.Remove();
}
}
There are still several auxiliary classes not written.Work process, first find the bookmark location, delete the content of the bookmark location, and then add it.I've also tried to add one Paragraph to the bookmark location.But that doesn't work.
Document to insert in bookmark eg:露点:U=0.15℃(k=2);相对湿度:U=1.0%RH(k=2).Both u and K must be italics.Any help will be appreciated.Thanks.
I tried a new component.[Spire.Office.][1]
At the beginning, I didn't think of a solution, but I used the global search and replacement to determine whether the search location has bookmarks, which perfectly solved the problem.
Here is the code for my work.
var selection = document.FindAllString("U", false, true);
foreach (var sec in selection)
{
var t = sec.GetAsOneRange();
if (sec.GetAsOneRange()?.Owner?.LastChild?.DocumentObjectType == DocumentObjectType.BookmarkEnd)
{
sec.GetAsOneRange().CharacterFormat.Italic = true;
}
}
I didn't try to do this with openxml, but I think the principle should be consistent.
[1]: https://www.e-iceblue.cn/Buy/Spire-PDF-NET.html

How can I search Notes by sequence number

I use Evernote C# API. I understand how filters working.
ENNoteStoreClient store = ENSessionAdvanced.SharedSession.PrimaryNoteStore;
SyncState currentState = store.GetSyncState();
int currentUpdateCount = currentState.UpdateCount;
if (currentUpdateCount > latestUpdateCount)
{
latestUpdateCount = currentUpdateCount;
// Here synchronization code
}
I have latestUpdateCount and how I can get notes with sequence number >= this number?
You'll want to use GetFilteredSyncChunk using code something like the following:
List<SyncChunk> syncBlocks = new List<SyncChunk>();
int maxEntries = 250;
// These are sample filter settings; you should use what's appropriate for you based on
// what data you want returned in your note objects.
SyncChunkFilter filter = new SyncChunkFilter();
filter.IncludeNotes = true;
filter.IncludeNoteAttributes = true;
filter.IncludeNotebooks = true;
filter.IncludeTags = false;
filter.IncludeSearches = false;
filter.IncludeResources = false;
filter.IncludeLinkedNotebooks = false;
filter.IncludeExpunged = false;
filter.IncludeNoteApplicationDataFullMap = false;
filter.IncludeResourceApplicationDataFullMap = false;
filter.IncludeNoteResourceApplicationDataFullMap = false;
do
{
SyncChunk chunk = store.getFilteredSyncChunk(currentUpdateCount, maxEntries, filter);
if (chunk == null)
{
return null; // This can happen if there is a "503 - Service unavailable" error accessing this person's Evernote info
}
syncBlocks.Add(chunk);
currentUpdateCount = chunk.ChunkHighUSN;
} while (currentUpdateCount < serverSyncState.UpdateCount);
foreach (SyncChunk chunk in syncBlocks)
{
if (chunk != null && chunk.Notes != null)
{
foreach (Note chunkNote in chunk.Notes)
{
// do something with the retrieved chunkNote object
}
}
}

Display sequence messages

I'm trying to display the messages from a sequence diagram, but so far no luck
Here's my code:
The function browse recursively calls itself to discover the diagrams, but i'm having no luck with DiagramLinks or DiagramObjects, any hint ?
private void browse(EA.Repository Repository, int ID, EA.ObjectType otype)
{
if (otype == EA.ObjectType.otPackage)
{
EA.Package pack = Repository.GetPackageByID(ID);
foreach(EA.Element el in pack.Elements)
{
ID = el.ElementID;
otype = el.ObjectType;
this.browse(Repository, ID, otype);
}
}
if (otype == EA.ObjectType.otElement)
{
EA.Element el = Repository.GetElementByID(ID);
foreach (EA.Diagram diag in el.Diagrams)
{
ID = diag.DiagramID;
otype = diag.ObjectType;
this.browse(Repository, ID, otype);
}
}
if (otype == EA.ObjectType.otDiagram)
{
EA.Diagram diag = Repository.GetDiagramByID(ID);
//foreach (EA.DiagramLink dobj in diag.DiagramLinks)
//{
MessageBox.Show(diag.Name+diag.Type);
//}
}
}
Here's the function that recognizes if the addin is launched from mainmenu, treeview or diagram.
It calls the above function Browse
private string simplify(EA.Repository Repository, string Location)
{
String s = "";
if (Location == "MainMenu") {
s = "ROOT";
MessageBox.Show("test");
}
else if (Location == "TreeView")
{
//Get the element in the tree view which was clicked
Object obj = null;
EA.ObjectType otype = Repository.GetTreeSelectedItem(out obj);
//Si le type n'arrive pas a etre determiné
if (!Enum.IsDefined(typeof(EA.ObjectType), otype))
{
//Should not occur
String error = "Type indeterminé.";
MessageBox.Show(error, "Erreur");
}
//The user clicked on a package - try to determine the stereotype
else if (otype == EA.ObjectType.otPackage)
{
EA.Package p = (EA.Package)obj;
//If the package has no superpackage, it must be the very top package
//-> if the very top package is clicked, ALL will be validated
int ID = p.PackageID;
bool hasParent = false;
try
{
int dummy = p.ParentID;
if (dummy != 0)
hasParent = true;
}
catch (Exception e) { }
if (!hasParent)
{
s = "ROOT";
}
else
{
this.browse(Repository, ID, otype);
}
}
else
{
int ID = 0;
if (otype == EA.ObjectType.otDiagram)
{
ID = ((EA.Diagram)obj).DiagramID;
EA.Diagram d = Repository.GetDiagramByID(ID);
this.browse(Repository, ID, otype);
}
else if (otype == EA.ObjectType.otElement)
{
ID = ((EA.Element)obj).ElementID;
EA.Element e = Repository.GetElementByID(ID);
this.browse(Repository, ID, otype);
}
}
if (obj == null)
s = "From Main Menu";
}
//If the users clicks into a diagram we must determine to which package
//the diagram belongs
else if (Location == "Diagram")
{
int ID = 0;
try
{
Object obj = null;
EA.ObjectType otype = Repository.GetContextItem(out obj);
if (otype == EA.ObjectType.otDiagram)
{
ID = ((EA.Diagram)obj).DiagramID;
EA.Diagram d = Repository.GetDiagramByID(ID);
this.browse(Repository, ID, otype);
}
else if (otype == EA.ObjectType.otElement)
{
ID = ((EA.Element)obj).ElementID;
EA.Element e = Repository.GetElementByID(ID);
this.browse(Repository, ID, otype);
}
else
{
Repository.Models.GetAt(0);
s = "From Main Menu";
}
}
catch (Exception ex)
{ }
}
return s;
this.encours = true;
}
The following Perl script snippet (hopefully it's readable) demonstrates what to do to get the connectors:
my $dia = $rep->GetDiagramByGUID("{7EA250AD-F37A-4e9a-9C52-BF8FCA3D87F7}"); # access the diagram
for (my $i = 0 ; $i < $dia->DiagramObjects->Count; $i++) { # every object inside the diagram
my $do = $dia->DiagramObjects->GetAt($i);
my $e = $rep->GetElementByID($do->ElementID); # the according element
next unless $e->Type eq "Sequence"; # look only at life lines
for (my $j = 0 ; $j < $e->Connectors->Count; $j++) { # now go through its connectors
my $con = $e->Connectors->GetAt($j);
print $con->Type . "\n"; # will print Sequence
}
}
Thanks a lot for your help Thomas
Here's the code i translated in C#
if (otype == EA.ObjectType.otDiagram)
{
EA.Diagram diag = Repository.GetDiagramByID(ID);
foreach (EA.DiagramObject dobj in diag.DiagramObjects)
{
EA.Element el = Repository.GetElementByID(dobj.ElementID);
foreach (EA.Connector con in el.Connectors)
{
if (con.Type == "Sequence")
{
MessageBox.Show(con.Name);
}
}
}
}

ApplicationData.LocalSettings not storing data?

I'm making an app where a use enters values for two times (starthour, startminute, endhour, endminute). I wrote a function that saves the values and then checks for value and puts the values inside the text boxes. However, it isn't working and I'm not sure why. I'm assuming its a mistake on my part, but I'm not exactly sure. Here's the code:
public async Task savedata()
{
while (true)
{
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["starthour1"] = starthour1.Text;
localSettings.Values["starthour2"] = starthour2.Text;
localSettings.Values["starthour3"] = starthour3.Text;
localSettings.Values["starthour4"] = starthour4.Text;
localSettings.Values["starthour5"] = starthour5.Text;
localSettings.Values["starthour6"] = starthour6.Text;
localSettings.Values["starthour7"] = starthour7.Text;
localSettings.Values["startminute1"] = startminute1.Text;
localSettings.Values["startminute2"] = startminute2.Text;
localSettings.Values["startminute3"] = startminute3.Text;
localSettings.Values["startminute4"] = startminute4.Text;
localSettings.Values["startminute5"] = startminute5.Text;
localSettings.Values["startminute6"] = startminute6.Text;
localSettings.Values["startminute7"] = startminute7.Text;
localSettings.Values["endhour1"] = endhour1.Text;
localSettings.Values["endhour2"] = endhour2.Text;
localSettings.Values["endhour3"] = endhour3.Text;
localSettings.Values["endhour4"] = endhour4.Text;
localSettings.Values["endhour5"] = endhour5.Text;
localSettings.Values["endhour6"] = endhour6.Text;
localSettings.Values["endhour7"] = endhour7.Text;
localSettings.Values["endminute1"] = endminute1.Text;
localSettings.Values["endminute2"] = endminute2.Text;
localSettings.Values["endminute3"] = endminute3.Text;
localSettings.Values["endminute4"] = endminute4.Text;
localSettings.Values["endminute5"] = endminute5.Text;
localSettings.Values["endminute6"] = endminute6.Text;
localSettings.Values["endminute7"] = endminute7.Text;
//get data
Object starthour1o = localSettings.Values["starthour1"];
if (starthour1o == null)
{
// No data
}
else
{
starthour1.Text = starthour1o.ToString();
}
Object starthour2o = localSettings.Values["starthour2"];
if (starthour2o == null)
{
// No data
}
else
{
starthour2.Text = starthour2o.ToString();
}
Object starthour3o = localSettings.Values["starthour3"];
if (starthour3o == null)
{
// No data
}
else
{
starthour3.Text = starthour3o.ToString();
}
Object starthour4o = localSettings.Values["starthour4"];
if (starthour4o == null)
{
// No data
}
else
{
starthour4.Text = starthour4o.ToString();
}
Object starthour5o = localSettings.Values["starthour5"];
if (starthour5o == null)
{
// No data
}
else
{
starthour5.Text = starthour5o.ToString();
}
Object starthour6o = localSettings.Values["starthour6"];
if (starthour6o == null)
{
// No data
}
else
{
starthour6.Text = starthour6o.ToString();
}
Object starthour7o = localSettings.Values["starthour7"];
if (starthour7o == null)
{
// No data
}
else
{
starthour7.Text = starthour7o.ToString();
}
await Task.Delay(10);
}
}
Two things you need to do, first you need to explicitly save your settings for them to be persisted by calling Save(). Somewhere in your code you need to do localSettings.Save() and it should work.
2nd, if you have saved settings the first thing your code does is overwrite them with the current values of the text boxes, the whole top section where it is localSettings.Values["Foo"] = Foo.Text needs to be moved to the bottom.
As a side comment, do you really need to be updating your code every 10 miliseconds? That is going to eat up a TON of resources in your program. A much more normal approach is load the values at start-up then save them at shutdown.

Binding Links in a Custom Object using Upsert function in C# SalesForce?

I have the following code which creates a Task in Salesforce and then tracks a user's browsing history and stores it in SalesForce. Currently, it displays each and every page the user has browsed as an individual entry. I want to group all those entries together in the Browsing_History__c object instead of task being created every time a user visits a page.
Any help would be appreciated..I am not familiar with SF very much. :)
private void CreateTaskInSF(string id, string type, string details, string description)
{
// if there's a similar Event in the past 2 hours, don't add it
QueryResult qr = null;
try // get events from past 2 hours
{
qr = Binding.query("Select Details__c from Task WHERE WhoId='" + id + "' and Type__c='" + type + "' and CreatedDate > " + DateTime.UtcNow.AddHours(-2).ToString("s") + "Z");
}
catch (Exception e)
{
return;
}
bool logged = false;
if (qr != null) // if there are Tasks in past 2 hours
{
sforce.sObject[] browsing = qr.records;
if (browsing != null)
{
// iterate through events to make sure the new Task isn't logged
for (int i = 0; i < browsing.Length; i++)
{
Task currTask = (Task)browsing[i];
if (currTask.Details__c == details)
{
if (description != "") // is there a description to check for?
{
string oldTaskDescription = "";
if (currTask.Description != null)
oldTaskDescription = currTask.Description;
if (oldTaskDescription == description) // if there is a description match
logged = true;
}
else
logged = true; // there's no description, so check only on details field
}
}
}
}
if (logged == true)
{
return; // if Activity is already logged, don't log it again
}
else if (type == "Browsing")
{
QueryResult browsingQuery = null;
try // get events from past 2 hours
{
browsingQuery = Binding.query("Select Web_Browsing__c from Task WHERE WhoId='" + id + "' and Subject='" + type + "' and Details__c='" + details + "' and CreatedDate > " + DateTime.UtcNow.AddHours(-2).ToString("s") + "Z");
}
catch
{
}
Boolean createNewBrowsing = false;
if (browsingQuery != null) // if there are Tasks in past 2 hours
{
sforce.sObject[] webBrowsing = browsingQuery.records;
if (webBrowsing != null)
{
//find correct object and update Browsing_History__c
//Binding.update
}
else
{
createNewBrowsing = true;
}
}
else
{
createNewBrowsing = true;
}
if (createNewBrowsing)
{
Web_Browsing__c newTask = new Web_Browsing__c();
newTask.Lead__c = id;
newTask.Browsing_History_255__c = details;
newTask.Type__c = type;
newTask.Browsing_History__c = details;
newTask.CreatedDate = DateTime.Now;
//if(type == "Browsing") newTask. = details;
//SaveResult[] createResult = Binding.create(new sObject[] { newTask });
try
{
SaveResult[] createResult = Binding.create(new sObject[] { newTask });
}
catch (Exception e)
{
return;
}
}
}
else
{
// if this new Activity isn't logged, then create a new Activity Task
sforce.Task newTask = new sforce.Task();
newTask.WhoId = id;
newTask.Subject = type;
newTask.Details__c = details;
if (description != "") newTask.Description = description;
newTask.Status = "Completed";
newTask.Priority = "Normal";
newTask.ActivityDate = DateTime.Now;
newTask.ActivityDateSpecified = true;
// insert it
try
{
SaveResult[] createResult = Binding.create(new sforce.sObject[] { newTask });
}
catch (Exception e)
{
return;
}
}
}
You'll need to update your query to ask for the browsing history object and update the code to create a browsing history object instead of a task.
If you haven't already, review the Web Services API docs, it has examples for querying and creating in java/c#.

Categories

Resources