C# word document clone existing word file as a new document

As noted the above places the text in the code (certainly not shockingly). Just how do I acquire the industry location/Range so I can insert text message before or after the field?

If the customer close the original file he should be talked to if the record should be conserved and select a course.

Meanwhile I have actually tried the different strategies on Word 2016. Lastly I yearn for to assist 2010 to 2016.

Really, farmlands do give back Span objects. The majority of range types can return 2 kinds of variations: one for Field.Code, an additional for Field.Result.

Returning this Variation won’t put the emphasis outside the field, yet you can obtain there certainly …

As everyone understands, Word do certainly not deliver SaveCopyAs like PowerPoint or even Excel. I made an effort various strategies, however without a gratifying result.

I would certainly such as to loophole by means of all the fields in my documentation as well as place text after those of type wdFieldIndexEntry however Area do not have a Selection market value they way Bookmarks do.

First “very first” the Range to its end-point (think of it like pressing Right arrow straight a selection)Assortment Relocate the beginning factor of the Selection one character in the direction of the point of the paper – today it is actually outside the area.

I would like to create function to load template documents automated through C# Interop.Word public library. Customer picks template paper from existing documents. I must duplicate this paper to the brand-new document (including stuffing, frame plus all the style).

app=new Word.Application();
src_doc=app.Documents.Open(template_file_name);
document=app.Documents.Add();
src_doc.Content.Copy();
document.Content.PasteSpecial(DataType:Word.WdPasteOptions.wdKeepSourceFormatting);

This code maintains layout right. However after pasting it is bothersome to modify market value. “src_doc” maintains open even after closing it.

I yearn for to replicate an active Word paper to wait to a specific temp location. The customer has certainly not to conserve the document. I prefer the exact same bavior of the SaveCopyAs functionallity like in Microsoft.Office.Interop.PowerPoint or even Microsoft.Office.Interop.Word.

I manage to replicate the file on the fly either along with proper format (positioning of factors -> wdPasteDefault) or right styles (typeface as well as colours -> wdPasteDefault).

There is a well-known solution with IPersistFile, perhaps it’s good enough for you:

using System.Runtime.InteropServices.ComTypes;

var f = (IPersistFile)doc;
f.Save("[path]", false);

Leave a Reply

Your email address will not be published. Required fields are marked *