//private List<WAElementLine> prp_Lines; //public List<WAElementLine> Lines { get => prp_Lines; set => prp_Lines = value; } //public WTOContent() //{ // prp_Lines = new List<WAElementLine>(); //} public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument) { Document DraftDoc = MWordApp.Documents.Add(); MWordDocument.Select(); MWordApp.Selection.Copy(); DraftDoc.Range().Paste(); DraftDoc.Activate(); List <WCSelection> TOCSelection = new List <WCSelection>(); for (int tcnt = 1; tcnt <= DraftDoc.TablesOfContents.Count; tcnt++) { TableOfContents toc = DraftDoc.TablesOfContents[tcnt]; toc.Range.Select(); WCSelection wcs = new WCSelection(); wcs.ContentSelectionStart = MWordApp.Selection.Start; wcs.ContentSelectionEnd = MWordApp.Selection.End; TOCSelection.Add(wcs); } { for (int ls = 0; ls < TOCSelection.Count; ls++) { TOCSelection[ls].ContentID = "WTOContents_" + (ls + 1); } } MWordDocument.Activate(); DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing); return(TOCSelection.ToArray()); }
public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument) { Document DraftDoc = MWordApp.Documents.Add(Visible: false); //Document DraftDoc = MWordApp.Documents.Add(null, null, null, false); MWordDocument.Select(); MWordApp.Selection.Copy(); DraftDoc.Range().Paste(); DraftDoc.Activate(); List <WCSelection> ListSelection = new List <WCSelection>(); for (int wlist = 1; wlist <= DraftDoc.Lists.Count; wlist++) { List dlist = DraftDoc.Lists[wlist]; dlist.Range.Select(); WCSelection wcs = new WCSelection() { ContentSelectionStart = MWordApp.Selection.Start, ContentSelectionEnd = MWordApp.Selection.End }; ListSelection.Add(wcs); } ListSelection = new List <WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray())); //{ // WCSelection[] TableSelections = WTableReader.GetAllContentSelections(MWordApp, MWordDocument, Logger); // ListSelection = new List<WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray(), TableSelections, Logger)); //} { for (int ls = 0; ls < ListSelection.Count; ls++) { ListSelection[ls].ContentID = "WList_" + (ls + 1); } } MWordDocument.Activate(); DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing); return(ListSelection.ToArray()); }
public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument) { try { Document DraftDoc = MWordApp.Documents.Add(Visible: false); MWordDocument.Select(); MWordApp.Selection.Copy(); DraftDoc.Range().Paste(); DraftDoc.Activate(); List <WCSelection> ParagWCS = new List <WCSelection>(); for (int prg = 1; prg <= DraftDoc.Paragraphs.Count; prg++) { //MyStringBuilder.Append(MyDraftDoc.Paragraphs[prg].Range.Text + Environment.NewLine); WCSelection wcs = new WCSelection(); //wparag.ParagraphProperties = wparagp; wcs.ContentID = "DParagraph_" + prg; wcs.ContentSelectionStart = DraftDoc.Paragraphs[prg].Range.Start; wcs.ContentSelectionEnd = DraftDoc.Paragraphs[prg].Range.End; ParagWCS.Add(wcs); } WCSelection[] NParagWCS = WCSelectionOperations.RemoveChilds(ParagWCS.ToArray()); for (int pindx = 0; pindx < NParagWCS.Length; pindx++) { NParagWCS[pindx].ContentID = "WParagraph_" + (pindx + 1); } DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing); return(NParagWCS); } catch (Exception Exp) { return(null); } }
public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger) { Document DraftDoc = MWordApp.Documents.Add(Visible: false); MWordDocument.Select(); MWordApp.Selection.Copy(); DraftDoc.Range().Paste(); DraftDoc.Activate(); List <WCSelection> TableSelections = new List <WCSelection>(); for (int tbli = 1; tbli <= DraftDoc.Tables.Count; tbli++) { //// Log info //AddToLog("Working on table: " + tbli); Table CurTable = DraftDoc.Tables[tbli]; //string TableXML = CurTable.Range.XML; //// Log info //AddToLog("Getting table content. Row count: " + CurTable.Rows.Count + "; Column count: " + CurTable.Columns.Count); //WTable wtbl = GetTableFromTableXMLData(TableXML); //for (int trow = 1; trow <= CurTable.Rows.Count; trow++) //{ // string[] TRow = new string[CurTable.Columns.Count]; // for(int tcol = 1; tcol <= CurTable.Columns.Count; tcol++) // { // try // { // TRow[tcol - 1] = CurTable.Cell(trow, tcol).Range.Text; // } // catch // { // TRow[tcol - 1] = string.Empty; // } // } // TList_Tables.Add(TRow); //} //// Log info //AddToLog("All content collected..."); CurTable.Select(); WCSelection wcs = new WCSelection() { ContentSelectionStart = MWordApp.Selection.Start, ContentSelectionEnd = MWordApp.Selection.End }; TableSelections.Add(wcs); //// Log info //AddToLog("Table was added as selection. Selection[Start, End] = [" + cs.RStart + ", " + cs.REnd + "]"); } TableSelections = new List <WCSelection>(WCSelectionOperations.RemoveChilds(TableSelections.ToArray())); //{ // WCSelection[] ListSelections = WListReader.GetAllContentSelections(MWordApp, MWordDocument, Logger); // TableSelections = new List<WCSelection>(WCSelectionOperations.RemoveChilds(TableSelections.ToArray(), ListSelections, Logger)); //} MWordDocument.Activate(); DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing); { for (int ls = 0; ls < TableSelections.Count; ls++) { TableSelections[ls].ContentID = "WTable_" + (ls + 1); } } return(TableSelections.ToArray()); }
public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger) { try { // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Elements", LogMessage = "Trying to get all paragraphs." }); // Log Logger.AddLog(new LogContent() { LogSubject = "Creating Document", LogMessage = "Trying to create draft document...", LogSeverity = LoggerParameters.LogSeverity.DEBUG }); Document DraftDoc = MWordApp.Documents.Add(Visible: false); MWordDocument.Select(); MWordApp.Selection.Copy(); DraftDoc.Range().Paste(); DraftDoc.Activate(); // Log Logger.AddLog(new LogContent() { LogSubject = "Creating Document", LogMessage = "Draft document created.", LogSeverity = LoggerParameters.LogSeverity.DEBUG }); List <WCSelection> ParagWCS = new List <WCSelection>(); // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "Trying to get all first level paragraph content selections" }); for (int prg = 1; prg <= DraftDoc.Paragraphs.Count; prg++) { //MyStringBuilder.Append(MyDraftDoc.Paragraphs[prg].Range.Text + Environment.NewLine); WCSelection wcs = new WCSelection(); //wparag.ParagraphProperties = wparagp; wcs.ContentID = "DParagraph_" + prg; wcs.ContentSelectionStart = DraftDoc.Paragraphs[prg].Range.Start; wcs.ContentSelectionEnd = DraftDoc.Paragraphs[prg].Range.End; // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "Paragraph [" + prg + "/" + DraftDoc.Paragraphs.Count + "] added. Content selection -> [" + wcs.ContentSelectionStart + " : " + wcs.ContentSelectionEnd + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG }); ParagWCS.Add(wcs); } // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "All paragraph content selection collected." }); //Thread.Sleep(500); WCSelection[] NParagWCS = WCSelectionOperations.RemoveChilds(ParagWCS.ToArray()); for (int pindx = 0; pindx < NParagWCS.Length; pindx++) { NParagWCS[pindx].ContentID = "WParagraph_" + (pindx + 1); } DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing); return(NParagWCS); } catch (Exception Exp) { // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "Error occured. Message -> " + Exp.Message }); return(null); } }
public static WCSelection[] GetAllContentSelections(Application MWordApp, Document MWordDocument, ILittleLyreLogger Logger) { // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "Trying to get all list content selections..." }); Document DraftDoc = MWordApp.Documents.Add(Visible: false); //Document DraftDoc = MWordApp.Documents.Add(null, null, null, false); MWordDocument.Select(); MWordApp.Selection.Copy(); DraftDoc.Range().Paste(); DraftDoc.Activate(); List <WCSelection> ListSelection = new List <WCSelection>(); for (int wlist = 1; wlist <= DraftDoc.Lists.Count; wlist++) { List dlist = DraftDoc.Lists[wlist]; dlist.Range.Select(); WCSelection wcs = new WCSelection() { ContentSelectionStart = MWordApp.Selection.Start, ContentSelectionEnd = MWordApp.Selection.End }; ListSelection.Add(wcs); // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "List [" + wlist + "/" + DraftDoc.Lists.Count + "] added. Content selection [start : end] = [" + wcs.ContentSelectionStart + " : " + wcs.ContentSelectionEnd + "]", LogSeverity = LoggerParameters.LogSeverity.DEBUG }); //// Log info //AddToLog("List [" + wlist + "/" + MyDraftDoc.Lists.Count + "] has been added as selection. Selection[Start, End] = [" + cs.RStart + ", " + cs.REnd + "]"); } ListSelection = new List <WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray())); // Log Logger.AddLog(new LogContent() { LogSubject = "Getting Selection", LogMessage = "Child content selections removed.", LogSeverity = LoggerParameters.LogSeverity.DEBUG }); //{ // WCSelection[] TableSelections = WTableReader.GetAllContentSelections(MWordApp, MWordDocument, Logger); // ListSelection = new List<WCSelection>(WCSelectionOperations.RemoveChilds(ListSelection.ToArray(), TableSelections, Logger)); //} { for (int ls = 0; ls < ListSelection.Count; ls++) { ListSelection[ls].ContentID = "WList_" + (ls + 1); } } MWordDocument.Activate(); DraftDoc.Close(WdSaveOptions.wdDoNotSaveChanges, WParameters.Missing, WParameters.Missing); return(ListSelection.ToArray()); }