I am trying to fill text of FormFieldData in word with open xml
i use this code to get formFieldData list and their FormFieldName from a word document :
var FormFieldDataList= wordDoc.MainDocumentPart.Document.Body.Descendants<FormFieldData>();
foreach (FormFieldData block in x2)
{
if (block != null)
{
FormFieldName tag = block.ChildElements.OfType<FormFieldName>().ElementAt(0);
}
}
but i can`t fill their text in doc
Related
I'm trying to write a Language Extension for VS Code in JavaScript and I seem to be missing something.
I have a Lexer.g4 and Parser.g4 for my language and can generate a tree using them.
My issue is that the VS Code API gives me a document and a position in that document (line #, character #). From any of the examples I've looked at for ANTLR4 I can't seem to find any functions generated that take a position in the file and give back the nodes of a tree at that position.
I want to know, for example that the cursor is placed on the name of a function.
Am I supposed to be walking the entire tree and checking the position of tokens to see if they enclose the position I'm in in the editor? Or maybe I'm not using the right tool for the job? I feel like I'm probably missing something more fundamental.
Yes, you have to walk the parse tree to find the context at a given position. This is a pretty simple task and you can see it in action in my ANLTR4 exension for vscode. There are multiple functions returning something useful for a given position. For instance this one:
/**
* Returns the parse tree which covers the given position or undefined if none could be found.
*/
function parseTreeFromPosition(root: ParseTree, column: number, row: number): ParseTree | undefined {
// Does the root node actually contain the position? If not we don't need to look further.
if (root instanceof TerminalNode) {
let terminal = (root as TerminalNode);
let token = terminal.symbol;
if (token.line != row)
return undefined;
let tokenStop = token.charPositionInLine + (token.stopIndex - token.startIndex + 1);
if (token.charPositionInLine <= column && tokenStop >= column) {
return terminal;
}
return undefined;
} else {
let context = (root as ParserRuleContext);
if (!context.start || !context.stop) { // Invalid tree?
return undefined;
}
if (context.start.line > row || (context.start.line == row && column < context.start.charPositionInLine)) {
return undefined;
}
let tokenStop = context.stop.charPositionInLine + (context.stop.stopIndex - context.stop.startIndex + 1);
if (context.stop.line < row || (context.stop.line == row && tokenStop < column)) {
return undefined;
}
if (context.children) {
for (let child of context.children) {
let result = parseTreeFromPosition(child, column, row);
if (result) {
return result;
}
}
}
return context;
}
}
I want to add clipboard contents in existing Object Text using dxl script.
I searched around, including dxl_reference_manual but nothing helped.
The object in selection has some text for example "Already existing text in this object" and clipboard contents for example "My Clipboard text" should add at the beginning and form as a single object.
(Output should be something like below in a single object.)
My Clipboard text
Already existing text in this object
My code:
Skip fGetSelectedObjects(Module in_mod)
{
Skip skpObjects = create() // Return KEY and DATA both 'Object'
if (null in_mod) return(skpObjects)
Object oCurr = current,
o
for o in entire (in_mod) do
{ if (isSelected(o) or
o == oCurr) put(skpObjects, o, o)
}
return(skpObjects)
} // end fGetSelectedObjects()
Skip skpObjects = fGetSelectedObjects(current Module)
Object o
for o in skpObjects do
{ // deal with the selected o
string s = o."Object text"
// I don't know the way to activate the object text attribute instead of manual click. Thus it loops through selection and pastes the clipboard contents.
pasteToEditbox
//For Single Indentation use 360 points, double indentation 720 points and so on...
o."Object text" = richText (applyTextFormattingToParagraph(richText s,false,360,0))
}
delete(skpObjects)
Not sure why you would be using a Skip for this. I would look to do the following:
// Create Variables
Module mod = current
Object obj = null
Buffer buf = create
string str = stringOf ( richClip )
// Loop through Module
for obj in entire ( mod ) do {
// Grab the rich text from the clip and reset the buffer
buf = str
// Check if it's selected and object heading is empty
if ( ( isSelected ( obj ) ) && ( obj."Object Heading" "" == "" ) ) {
// If it is, add the text to the buffer
buf += " " richText ( obj."Object Text" )
// Set the object text with the clip stuff in front
obj."Object Text" = richText ( buf )
}
}
delete buf
Of note, this only works on items that have been specifically selected.
Edit- added exclusion for objects with an Object Heading. Unfortunately, DOORS does not (as far as I know) allow for non-contiguous object selection (the equivalent of ctrl-left click in Windows) which can be very frustrating.
I am trying to navigate through MSHTML (TWebBrowser) document word by word for spell checking each word. But I have problems:
1) it selects words oddly - For example "Abc: def" - the selection is "Abc" as first and ":" as second word. Also, if a word ends with space for example "Abc def" it would select "Abc " with the trailing space included. Is there a way to select only what is the word and not the trailing spaces or non-word characters? Or is this the best move can offer and it is up to programmer to filter the words correctly?
2) Is there a way to specify which delimiters it will use for example only to let it use space as a delimiter and not colons, dashes or other characters? (Microsoft docs say - "Word - Moves one or more words. A word is a collection of characters terminated by a space or other white space character. ", but it also uses other delimiters, not just space, tabs and similar)
Current code is:
bool SelectNext(bool firstonly = false)
{
DelphiInterface<IHTMLDocument2> diDoc = WB->Document;
if (diDoc)
{
DelphiInterface<IHTMLSelectionObject> diSel = diDoc->selection;
if (diSel)
{
if (firstonly) diSel->empty();
if (diSel->type_ == "None" || diSel->type_ == "Text")
{
DelphiInterface<IDispatch> diRangeDisp;
if (SUCCEEDED(diSel->createRange(diRangeDisp)) && diRangeDisp)
{
DelphiInterface<IHTMLTxtRange> diRange;
if (SUCCEEDED(diRangeDisp->QueryInterface(IID_IHTMLTxtRange, reinterpret_cast<void**>(&diRange))) && diRange)
{
int Result;
unsigned short Res;
diRange->move("word", 1, Result);
diRange->expand("word", Res);
diRange->select();
return true;
}
}
}
}
}
return false;
}
SelectNext(true); // Select the first "word"
// navigate first 200 words
for (int i = 0; i <= 200; i++)
{
SelectNext();
// do spell checking of selected word here...
}
I tried to add Arabic letters at the Browse page by using the below code but i did not succeeded,the Arabic Letters were not appearing at the Browse page.
The code which i tried is as below:-
else
{
// Create a clickable list of the alphabet
List jumpList = jump.addList("jump-list", List.TYPE_SIMPLE, "alphabet");
// browse params for each letter are all the query params
// WITHOUT the second-stage browse value, and add STARTS_WITH.
Map<String, String> letterQuery = new HashMap<String, String>(queryParamsGET);
for (String valueKey : BrowseParams.FILTER_VALUE)
{
letterQuery.remove(valueKey);
}
letterQuery.put(BrowseParams.STARTS_WITH, "0");
jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, letterQuery), "0-9");
for (char c = 'A'; c <= 'Z'; c++)
{
letterQuery.put(BrowseParams.STARTS_WITH, Character.toString(c));
jumpList.addItemXref(super.generateURL(BROWSE_URL_BASE, letterQuery), Character
.toString(c));
}
//I HAVE ADDED BELOW CODE TO CREATE A BROWSE LIST FOR ARABIC TEXT
// I HAVE CREATED A LIST FOR ARABIC CHARACTERS
List jumpList2 = jump.addList("jump-list2", List.TYPE_SIMPLE, "alphabet");
// I HAVE CREATED A HASHMAP FOR ARABIC CHARACTERS
Map<String, String> ddQuery = new HashMap<String, String>(queryParamsGET);
for (String valueKey : BrowseParams.FILTER_VALUE)
{
ddQuery.remove(valueKey);
}
//I HAVE ADDED BELOW CODE TO CREATE A BROWSE LIST FOR ARABIC TEXT
for (char d = 'ا'; d <= 'ى'; d++)
{
ddQuery.put(BrowseParams.STARTS_WITH, Character.toString(d));
jumpList2.addItemXref(super.generateURL(BROWSE_URL_BASE, ddQuery), Character
.toString(d));
}
I do it with javascript because i cant rebuild dspace.
window.addEventListener('DOMContentLoaded', function(event){
var elem = jQuery('ul.alphabet.list-inline li:first-child').clone()
if (elem.length){
jQuery('ul.alphabet.list-inline').append('<br>')
var href = elem.children('a').attr('href');
var str = 'ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی'
for (var i = 0; i != str.length ; i++){
var c = str.charAt(i)
elem.children('a').text(c)
elem.children('a').attr('href',href.replace('starts_with=0','starts_with='+c));
jQuery('ul.alphabet.list-inline').append(elem.clone())
jQuery('ul.alphabet.list-inline').append(' ')
}
}
});
i wanna ask how to change title in
name
so i want to make link name copy to title automatic
so if i make this code
title link
to
title link
how to do that in php or javascript
i know some in php
but need to make all words in link at database or make for every link variable $
can some one help me in that?
I'd suggest:
function textToTitle(elem, attr) {
if (!elem || !attr) {
// if function's called without an element/node,
// or without a string (an attribute such as 'title',
// 'data-customAttribute', etc...) then returns false and quits
return false;
}
else {
// if elem is a node use that node, otherwise assume it's a
// a string containing the id of an element, search for that element
// and use that
elem = elem.nodeType == 1 ? elem : document.getElementById(elem);
// gets the text of the element (innerText for IE)
var text = elem.textContent || elem.innerText;
// sets the attribute
elem.setAttribute(attr, text);
}
}
var link = document.getElementsByTagName('a');
for (var i = 0, len = link.length; i < len; i++) {
textToTitle(link[i], 'title');
}
JS Fiddle demo.
And since it seems traditional to offer a concise jQuery option:
$('a').attr('title', function() { return $(this).text(); });
JS Fiddle demo.
If you don't want to use a library:
var allLinks = document.getElementsByTagName('a');
for(var i = 0; i < allLinks.length; i++){
allLinks[i].title = allLinks[i].innerHTML;
}
Since you wanted to do all this to one element on the page, consider using something like this:
var allLinks = document.getElementById('myelement').getElementsByTagName('a'); // gets all the link elements out of #myelement
for ( int i = 0; i < allLinks.length; i++ ){
allLinks[i].title = allLinks[i].innerHTML;
}
Actually, this is roughly the same as before but we are changing the input elements.
Or, assuming you use jQuery, you could do something like this:
$('a').each(function(){ // runs through each link element on the page
$(this).attr('title', $(this).html()); // and changes the title to the text within itself ($(this).html())
});
In JQuery you can change an attribute by knowing the current tag and using the .attr() feature. Something like $('a').attr('title', 'new_title'); http://api.jquery.com/attr/