Microsoft Interop Word Get Range from Heading - c#

I am looking to be able to get a range within a Word template from the Headings/Sections shown in the bookmarks.
For the template I have, I have multiple headings templated out and I need to automate the insertion to the document.
So, say I wanted to insert text under each heading without searching for the text (as this will likely change) how would I go about this?

I figured it out. I needed to add bookmarks to my template on the paragraph after and then use this to get the range:
Word.Range range = wordDoc.Bookmarks[bookmarkName].Range;
I can then use range.Text = text to insert the text.

Related

ASP NET, Xceed Docx, Table of content with heading that has no numbering

In my C# ASP.NET code I have:
doc.InsertTableOfContents("Table of Contents", TableOfContentsSwitches.H);
Which results into
How can I insert the table of contents without the title being numbered, I ideally need something that would result into
I tried to play around with the switches but unsucesfully, I tried to modify the Word settings when it comes to Headings or TOC but also unsucesfully
The way I did it was by using this:
doc.InsertDefaultTableOfContents();
Then I added the content to it by adding the StyleId of a HeadingX to it. For example:
paragraph.StyleId = "Heading1";

How to get Custom Table of Content in Aspose.word using C#

I am working in Report and using Aspose.word. I need to get customize Table of content. But in Word its giving only default template like as below,
Heading 1.............................. 1
Heading 1.1...........................2
Heading 1.2...........................3
But I need Table of content as below,
(1-3) Heading 1
(Heading 1.1,Heading 1.2)
Is it possible to create Custom table of content based on title and subtilte? Please give your comments...
In Aspose.Words you can create TOC using DocumentBuilder.InsertTableOfContents method. It accepts list of TOC field’s switches that define the final look of the Table Of Contents. If switches does not allow you to create the desired output then you can loop through paragraphs in the document, check each paragraphs style and in case of heading style compile your own TOC.

How to apply wrap text to MSProject 2010 column programmatically?

I have found code to set column best fit for long content. But when the cell content length is too long, while printing the MS project file the content was cut off. So to correct this issue I need to apply wrap text property to TaskName column in MS Project 2010 using C#.
My question
Is it possible to apply wrap text to each cell in Task name column they have multiple lines and to autofit row height?
What I've tried
I tried to select Task Name column alone and to apply text wrap property. But that is not successful. Till now I didn’t get any property to apply text wrapper in MS project using Microsoft.Office.Interop.MSProject.dll in C#.

Word interop cross referencing an endnote

I am trying to refer to an existing end note in word from a table cell in the document thus (using netoffice):
row.Cells[2].Range.InsertCrossReference(WdReferenceType.wdRefTypeEndnote, WdReferenceKind.wdEndnoteNumberFormatted, 1);
However, this appears to put the reference at the beginning of the row, rather than at the end of the text at Cell[2]. In general, I haven't found much help on the web on how to programmatically add a cross-reference to footnotes and end notes. How can I get the reference to display properly?
The problem is that the target Range specified in your code snippet is the entire cell. You need to "collapse" the Range to be within the cell. (Think of the Range like a Selection. If you click at the edge of a cell, the entire cell is selected, including its structural elements. If you then press left-arrow, the selection is collapsed to a blinking I-beam.)
To go to the start of the cell:
Word.Range rngCell = row.Cells[2].Range;
rngCell.Collapse(Word.WdCollapseDirection.wdCollapseStart);
rngCell.InsertCrossReference(WdReferenceType.wdRefTypeEndnote, WdReferenceKind.wdEndnoteNumberFormatted, 1);
If the cell has content and you want it at the end of the content, then you use wdCollapseEnd instead. The tricky part about that is this puts the target point at the start of the next cell, so it has to be moved back one character:
Word.Range rngCell = row.Cells[2].Range;
rngCell.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
rng.MoveEnd(Word.WdUnits.wdCharacter, -1);
rngCell.InsertCrossReference(WdReferenceType.wdRefTypeEndnote, WdReferenceKind.wdEndnoteNumberFormatted, 1);

How to read text that is present in text box of MS word document?

I have an word document which I want to convert to text (.txt) file programmatically. I am using C# for this.
I am able to read paragraphs and tables from word document and convert them to text. There are some textboxes in the word document and those textboxes contain text that I want to read and put them in text file.
My problem is I do not know in which collection those textboxes are stored. For example, all tables are stored in tables collection, paragraphs in paragraphs collection.
Can anyone please tell me how to read from these text boxes?
Please let me know if you need any additional information.
There are text boxes and text frames. I'm pretty sure any text inside text boxes will be part of the Doc.Content range.
To find all the text frames in a document, I use this VBA code:
Dim Doc As Document
Dim Range As Range
' Load document
Set Range = Doc.StoryRanges(wdTextFrameStory)
Do Until Range Is Nothing
' Do something with Range.Text
Set Range = Range.NextStoryRange
Loop

Categories

Resources