private void RemoveExistingIndentation(List <Word.Paragraph> pars) { foreach (Word.Paragraph par in pars) { string line = par.Range.Text; if (line[line.Length - 1] == '\a') { line = line.Remove(line.Length - 1); // '\a' at the end causes problems, cause it's not whitespace, and thus "\r\a" is not an all whitesapces line } int whitespace_cntr = 0; while (true) { if (whitespace_cntr < line.Length && Char.IsWhiteSpace(line[whitespace_cntr])) { whitespace_cntr++; } else { break; } } if (whitespace_cntr == line.Length && line.Length > 0) // all whitespace line ('\r' is whitesapce, '\a' isn't) { whitespace_cntr--; } Word.Range range = par.Range; if (line.Length > 1 && whitespace_cntr > 0) { range.SetRange(par.Range.Start, par.Range.Start + whitespace_cntr); range.Delete(); // the reason for using SetRange is that removing the first character of the selection causes it do disappear } } }
public static void RemoveAllContent(Word.Document doc) { int startRange = -1, endRange = -1; foreach (Word.Paragraph para in doc.Paragraphs) { if (startRange == -1) { startRange = para.Range.Start; } endRange = para.Range.End; } Debug.WriteLine("Paragraph Start " + startRange + " Stop: " + endRange); if (startRange <= endRange && startRange >= 0 && endRange >= 0) { Word.Range range = doc.Range(startRange, endRange - 1); range.Delete(); } Word.Selection selection = Globals.ThisAddIn.Application.Selection; selection.TypeParagraph(); selection.set_Style(doc.Styles[Constants.ContentStyle]); }
private void button_Click(object sender, RoutedEventArgs e) { Word._Application application; Word._Document document; object missingObj = System.Reflection.Missing.Value; object trueObj = true; object falseObj = false; //создаем обьект приложения word application = new Word.Application(); // создаем путь к файлу object templatePathObj = "D:\\tmp\\test.doc";; // если вылетим не этом этапе, приложение останется открытым document = application.Documents.Add(ref templatePathObj, ref missingObj, ref missingObj, ref missingObj); //Word._Document docnew = application.Documents.Add(); //{ // document = application.Documents.Add(ref templatePathObj, ref missingObj, ref missingObj, ref missingObj); //} //catch (Exception error) //{ // document.Close(ref falseObj, ref missingObj, ref missingObj); // application.Quit(ref missingObj, ref missingObj, ref missingObj); // document = null; // application = null; // throw error; //} application.Visible = true; Word.Range bookmarkRange = document.Bookmarks["aaa"].Range; bookmarkRange.Delete(); }
private void button1_Click(object sender, EventArgs e) { try { //Shaby (start) : below line of code to delete the previously existing reference. //selectRngToModify.Text = selectRngToModify.Text.ToLower().Remove(selectRngToModify.Text.IndexOf(((string)refernc).ToLower()), ((string)refernc).Length); //Shaby (start) : below block of code to delete the previously existing reference without loosing its formatting. Object referenceRangeStart = selectRngToModify.Start + selectRngToModify.Text.ToLower().IndexOf(((string)refernc).ToLower()); Object referenceRangeEnd = (int)referenceRangeStart + ((string)refernc).Length; MSword.Range referenceRange = Activedoc.Range(ref referenceRangeStart, ref referenceRangeEnd); referenceRange.Text = ""; //Shaby (end) Object text = textboxvalue; object missing = Type.Missing; Object reference = refernc; Activedoc.Footnotes.Add(selectRngToModify, ref reference, ref text); footnotetext.Delete(ref missing, ref missing); this.Close(); } catch (Exception x) { MessageBox.Show(x.Message, "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void chkSpell_Click(object sender, EventArgs e) { Word.Application app = new Word.Application(); int errors = 0; //don't show word doing all the work app.Visible = false; //setting variables that are equivalent to null. object template = Missing.Value; object newTemplate = Missing.Value; object documentType = Missing.Value; object visible = true; //initalize a document Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible); //a counter token int i = 0; //a variable to hold the output string[] holder = Regex.Split(txtIssue.Text, "\r\n"); while (holder.Length > i) { doc1.Words.First.InsertBefore(holder[i]); Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors; errors = spellErrorsColl.Count; object optional = Missing.Value; doc1.CheckSpelling(ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional); object first = 0; object last = doc1.Characters.Count - 1; holder[i] = doc1.Range(ref first, ref last).Text; Word.Range deleteme = doc1.Range(ref first, ref last); deleteme.Delete(ref optional, ref optional); i = i + 1; } txtIssue.Text = ""; foreach (string line in holder) { txtIssue.Text += line + "\r\n"; } object saveChanges = false; object originalFormat = Missing.Value; object routeDocument = Missing.Value; app.Quit(ref saveChanges, ref originalFormat, ref routeDocument); }
public void AddField(string fieldName) { //add o field entre "{}" Range.Delete(); Range.InsertBefore("{" + fieldName + "}"); Range.Select(); Range.Application.Selection.Font.Color = Word.WdColor.wdColorRed; }
void DirtyTheDoc() { Word.Range rng = Globals.ThisAddIn.Application.ActiveDocument.Content; object collapseStart = Word.WdCollapseDirection.wdCollapseStart; rng.Collapse(ref collapseStart); rng.Text = " "; rng.Delete(); }
/// <summary> 代码向前缩进 </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Button_DeleteSapce_Click(object sender, RibbonControlEventArgs e) { // 要删除或者添加的字符数 int SpaceCount = 0; string InsertSpace = ""; try { SpaceCount = Convert.ToUInt16(this.EditBox_SpaceCount.Text); StringBuilder sb = new StringBuilder(4); for (var i = 1; i <= SpaceCount; i++) { sb.Append(" "); } InsertSpace = sb.ToString(); } catch (Exception) { MessageBox.Show("请先设置要添加或者删除的字符数"); return; } // try { _app.ScreenUpdating = false; int StartIndex = 0; int EndIndex = 0; Range rg = _app.Selection.Range; StartIndex = rg.Start; string str = ""; Range rgPara = default(Range); //每一段的起始位置 foreach (Paragraph para in rg.Paragraphs) { str = para.Range.Text; if (str.Length > SpaceCount && str.Substring(0, SpaceCount) == InsertSpace) { rgPara = para.Range; rgPara.Collapse(Direction: WdCollapseDirection.wdCollapseStart); rgPara.Delete(Unit: WdUnits.wdCharacter, Count: SpaceCount); } EndIndex = para.Range.End; } _activeDoc.Range(StartIndex, EndIndex).Select(); } catch (Exception) { // MessageBox.Show("代码缩进出错!" & vbCrLf & // ex.Message & vbCrLf & ex.TargetSite.Name, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error) } finally { _app.ScreenUpdating = true; } }
private void button3_Click(object sender, RibbonControlEventArgs e) { Word.Document document = Globals.ThisAddIn.Application.ActiveDocument; Word.Range rng = document.Content; // 获取全部文本范围 rng.Delete(); // 清空原先文本 addHeaderAndFooter(); creatTitle(); creatSingleSelection(); creatMultipleSelection(); creatExperimentTest(); creatCalculateTest(); }
public void WriteLabel(Word.Table table, LabelTemplate template) { if (table == null) { return; } ActiveDocument.ActiveWindow.View.TableGridlines = true; Word.Range cellRange = table.Cell(1, 1).Range; cellRange.Delete(); template.WriteToRange(cellRange); UpdateLabels(); }
public void RemoveClassificationButton(Office.IRibbonControl control) { Microsoft.Office.Interop.Word.Document nativeDocument = Globals.ThisAddIn.Application.ActiveDocument; Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(nativeDocument); Office.DocumentProperties properties = (Office.DocumentProperties)vstoDocument.CustomDocumentProperties; if (ReadDocumentProperty("Classification") != null) { properties["Classification"].Delete(); } foreach (Word.Section wordSection in Globals.ThisAddIn.Application.ActiveDocument.Sections) { Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; footerRange.Delete(); Word.Range headerRange = wordSection.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Delete(); } }
private void CaptureMyScreen(int startX, int startY, int width, int height) { try { string appDataFolder = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\TagUI\"; string tmpFile = appDataFolder + "Capture.png"; Directory.CreateDirectory(appDataFolder); Bitmap captureBitmap = new Bitmap(width, height); Rectangle captureRectangle = new Rectangle(startX, startY, width, height); Graphics captureGraphics = Graphics.FromImage(captureBitmap); captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size); captureBitmap.Save(tmpFile, ImageFormat.Png); Word.Range rng = Globals.ThisAddIn.Application.Selection.Range; rng.Delete(); var pic = rng.InlineShapes.AddPicture(tmpFile, false, true).ConvertToShape(); pic.WrapFormat.Type = Word.WdWrapType.wdWrapInline; captureBitmap.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//</Snippet22> //--------------------------------------------------------------------- //<Snippet26> private void ReplaceParagraphText() { //<Snippet27> Word.Range firstRange = this.Paragraphs[1].Range; Word.Range secondRange = this.Paragraphs[2].Range; string firstString = firstRange.Text; string secondString = secondRange.Text; //</Snippet27> //<Snippet28> firstRange.Text = secondString; secondRange.Text = firstString; //</Snippet28> //<Snippet29> firstRange.Select(); MessageBox.Show(firstRange.Text); secondRange.Select(); MessageBox.Show(secondRange.Text); //</Snippet29> //<Snippet30> object charUnit = Word.WdUnits.wdCharacter; object move = -1; // move left 1 firstRange.MoveEnd(ref charUnit, ref move); //</Snippet30> //<Snippet31> firstRange.Text = "New content for paragraph 1."; //</Snippet31> //<Snippet32> secondRange.Text = "New content for paragraph 2."; //</Snippet32> //<Snippet33> firstRange.Select(); MessageBox.Show(firstRange.Text); secondRange.Select(); MessageBox.Show(secondRange.Text); //</Snippet33> //<Snippet34> move = 1; // move right 1 firstRange.MoveEnd(ref charUnit, ref move); //</Snippet34> //<Snippet35> secondRange.Delete(ref missing, ref missing); //</Snippet35> //<Snippet36> firstRange.Text = firstString; //</Snippet36> //<Snippet37> firstRange.InsertAfter(secondString); firstRange.Select(); //</Snippet37> }
// Callback function for Keyboard hook. private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { IntPtr active = GetForegroundWindow(); if (!(active.Equals(self.MainWindowHandle) || active.Equals(GUIManager.GUIHandle))) { inputStatus = KEYBOARD_IDLE; GUIManager.disappear(); } #region KeyCheck else { currDoc = ThisAddIn.getCurrDocument(); int vkCode = Marshal.ReadInt32(lParam); if (active.Equals(GUIManager.GUIHandle)) { hotkeyTimer.Start(); int maxCount = tempList.Count - wrappedPage * REFERENCE_PER_PAGE - 1; if (vkCode == KeyboardMapping.Keys["1"]) { selectedItem = Math.Min(0, maxCount); } else if (vkCode == KeyboardMapping.Keys["2"]) { selectedItem = Math.Min(1, maxCount); } else if (vkCode == KeyboardMapping.Keys["3"]) { selectedItem = Math.Min(2, maxCount); } else if (vkCode == KeyboardMapping.Keys["4"]) { selectedItem = Math.Min(3, maxCount); } else if (vkCode == KeyboardMapping.Keys["5"]) { selectedItem = Math.Min(4, maxCount); } else if (vkCode == KeyboardMapping.Keys["VK_LEFT"]) { if (wrappedPage > 0) { wrappedPage -= 1; } selectedItem = 0; } else if (vkCode == KeyboardMapping.Keys["VK_RIGHT"]) { if (wrappedPage < maxPage) { wrappedPage += 1; selectedItem = 0; } else { selectedItem = maxCount; } } GUIManager.chooseItem(selectedItem, wrappedPage); } if (inputStatus == KEYBOARD_IDLE) { // Register place for starting typing. inputStatus = KEYBOARD_TYPING; Messenger.message("User is Typing!"); selStart = currDoc.Application.Selection.End; //start Timer resetTimer(); } else if (inputStatus == KEYBOARD_TYPING) { resetTimer(); } else if (inputStatus == KEYBOARD_PREFLISTSHOWED) { if (checkHotKey(vkCode, extendSentenceHotKey, 1)) { string extending = tempList[wrappedPage * REFERENCE_PER_PAGE + selectedItem].getContent(); sentenceLength.Add(extending.Length); int tempPos = selEnd; // Print string currDoc.Application.Selection.Start = selEnd; currDoc.Application.Selection.End = selEnd; currDoc.Application.Selection.TypeText(extending); // Move cursor selEnd = tempPos + extending.Length; selStart = tempPos; rng = currDoc.Range(selStart, selEnd); rng.Select(); Messenger.message("Sentence Extended!"); } else if (checkHotKey(vkCode, deleteSentenceHotKey, 4)) { if (sentenceLength.Any()) { int lastAdded = sentenceLength.Count - 1; selStart = selEnd - sentenceLength[lastAdded]; rng = currDoc.Range(selStart, selEnd); rng.Delete(); sentenceLength.RemoveAt(lastAdded); if (sentenceLength.Any()) { lastAdded = sentenceLength.Count - 1; selEnd = selStart; selStart = selEnd - sentenceLength[lastAdded]; rng = currDoc.Range(selStart, selEnd); rng.Select(); } else { selEnd = selStart; rng = currDoc.Range(selStart, selEnd); rng.Select(); } Messenger.message("Sentence Reverted!"); } else { Messenger.message("Nothing extended yet!"); } } else if (vkCode == KeyboardMapping.Keys["SPACE"]) { Messenger.message("KeyboardStatRestored!\n"); selStart = selEnd; rng = currDoc.Range(selStart, selEnd); rng.Select(); GUIManager.disappear(); inputStatus = KEYBOARD_TYPING; sentenceLength = new List <int>(); } } } #endregion } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
public static void DeployHeader(Header header) { try { XLDocument.UpdateCurrentDoc(); try { //in some circumstances this is not setting the attribute //still adds the header and footer correctly so just warn the user. currentDoc.PageSetup.DifferentFirstPageHeaderFooter = -1; } catch { MessageBox.Show("Unable to set the first page to a different header please double check the document"); } Microsoft.Office.Interop.Word.Paragraph para = null; Microsoft.Office.Interop.Word.Range rng = null; // Setting First page Header //Clear any existing header rng = currentDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range; rng.Delete(); rng.ParagraphFormat.RightIndent = header.HeaderRightIndent; rng.ParagraphFormat.LeftIndent = header.HeaderLeftIndent; rng.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight; //Then build the new one line by line foreach (Line line in header.HeaderLines) { para = currentDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range.Paragraphs.Add(); para.Range.Font.Name = line.Font; para.Range.Font.Size = line.Size; para.Range.Font.Bold = line.Bold; para.Range.Text = line.Text + Environment.NewLine; } //Setting First page footer //First delete and existing footer rng = currentDoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range; rng.Delete(); rng.ParagraphFormat.RightIndent = header.FooterRightIndent; rng.ParagraphFormat.LeftIndent = header.FooterLeftIndent; //Then build the new one line by line foreach (Line line in header.FooterLines) { para = currentDoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range.Paragraphs.Add(); para.Range.Font.Name = line.Font; para.Range.Font.Size = line.Size; para.Range.Font.Bold = line.Bold; para.Range.Font.Color = WdColor.wdColorGray50; para.Range.Text = line.Text + Environment.NewLine; } foreach (Image logo in header.Images) { Microsoft.Office.Interop.Word.Range anchorRng = currentDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range; currentDoc.Shapes.AddPicture(logo.SourceLocation, false, true, logo.PointsFromLeftEdge, logo.PointsFromTop, logo.Width, logo.Height, anchorRng); } } catch (Exception e) { MessageBox.Show("Unable to deploy header"); XLtools.LogException("DeployHeader", e.ToString()); } }
// Callback function for Keyboard hook. private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { IntPtr active = GetForegroundWindow(); if (!(active.Equals(self.MainWindowHandle) || active.Equals(GUIManager.GUIHandle))) { inputStatus = KEYBOARD_IDLE; GUIManager.disappear(); } #region KeyCheck else { currDoc = ThisAddIn.getCurrDocument(); int vkCode = Marshal.ReadInt32(lParam); if (active.Equals(GUIManager.GUIHandle)) { hotkeyTimer.Start(); int maxCount = tempList.Count - wrappedPage * REFERENCE_PER_PAGE - 1; if (vkCode == KeyboardMapping.Keys["1"]) { selectedItem = Math.Min(0, maxCount); } else if (vkCode == KeyboardMapping.Keys["2"]) { selectedItem = Math.Min(1, maxCount); } else if (vkCode == KeyboardMapping.Keys["3"]) { selectedItem = Math.Min(2, maxCount); } else if (vkCode == KeyboardMapping.Keys["4"]) { selectedItem = Math.Min(3, maxCount); } else if (vkCode == KeyboardMapping.Keys["5"]) { selectedItem = Math.Min(4, maxCount); } else if (vkCode == KeyboardMapping.Keys["VK_LEFT"]) { if (wrappedPage > 0) wrappedPage -= 1; selectedItem = 0; } else if (vkCode == KeyboardMapping.Keys["VK_RIGHT"]) { if (wrappedPage < maxPage) { wrappedPage += 1; selectedItem = 0; } else selectedItem = maxCount; } GUIManager.chooseItem(selectedItem, wrappedPage); } if (inputStatus == KEYBOARD_IDLE) { // Register place for starting typing. inputStatus = KEYBOARD_TYPING; Messenger.message("User is Typing!"); selStart = currDoc.Application.Selection.End; //start Timer resetTimer(); } else if (inputStatus == KEYBOARD_TYPING) { resetTimer(); } else if (inputStatus == KEYBOARD_PREFLISTSHOWED) { if (checkHotKey(vkCode, extendSentenceHotKey, 1)) { string extending = tempList[wrappedPage * REFERENCE_PER_PAGE + selectedItem].getContent(); sentenceLength.Add(extending.Length); int tempPos = selEnd; // Print string currDoc.Application.Selection.Start = selEnd; currDoc.Application.Selection.End = selEnd; currDoc.Application.Selection.TypeText(extending); // Move cursor selEnd = tempPos + extending.Length; selStart = tempPos; rng = currDoc.Range(selStart, selEnd); rng.Select(); Messenger.message("Sentence Extended!"); } else if (checkHotKey(vkCode, deleteSentenceHotKey, 4)) { if (sentenceLength.Any()) { int lastAdded = sentenceLength.Count - 1; selStart = selEnd - sentenceLength[lastAdded]; rng = currDoc.Range(selStart, selEnd); rng.Delete(); sentenceLength.RemoveAt(lastAdded); if (sentenceLength.Any()) { lastAdded = sentenceLength.Count - 1; selEnd = selStart; selStart = selEnd - sentenceLength[lastAdded]; rng = currDoc.Range(selStart, selEnd); rng.Select(); } else { selEnd = selStart; rng = currDoc.Range(selStart, selEnd); rng.Select(); } Messenger.message("Sentence Reverted!"); } else Messenger.message("Nothing extended yet!"); } else if (vkCode == KeyboardMapping.Keys["SPACE"]) { Messenger.message("KeyboardStatRestored!\n"); selStart = selEnd; rng = currDoc.Range(selStart, selEnd); rng.Select(); GUIManager.disappear(); inputStatus = KEYBOARD_TYPING; sentenceLength = new List<int>(); } } } #endregion } return CallNextHookEx(_hookID, nCode, wParam, lParam); }
private void buttonPDF_Click(object sender, RoutedEventArgs e) { var wrd_name = Convert.ToString(comboBox.SelectedValue); var xls_name = textBoxExcelPath.Text; if (string.IsNullOrEmpty(wrd_name)) { MessageBox.Show("Выберите шаблон КП"); return; } ProgressWnd pw = new ProgressWnd("Создаем КП по шаблону..."); pw.Show(); string fn = ""; try { WordApp = new Wd.Application() { Visible = false }; WordDoc = WordApp.Documents.Open(wrd_name); fn = SaveW(WordApp, WordDoc); var ad = DataContext as AllData; ReplaceAll(WordDoc, "[OurCompany]", ad.Our.OurCompany); ReplaceAll(WordDoc, "[ForWho]", ad.ForWho); ReplaceAll(WordDoc, "[ContractPeriodYears]", ad.HowLongYears); ReplaceAll(WordDoc, "[ServiceType]", ad.ServiceType); ReplaceAll(WordDoc, "[DaysToStart]", ad.DaysToStart); ReplaceAll(WordDoc, "[DateStart]", ad.DateStart); ReplaceAll(WordDoc, "[CostMonthString]", ad.CostMonthString); ReplaceAll(WordDoc, "[CostMonth]", ad.CostMonth); ReplaceAll(WordDoc, "[CostYear]", (o2d(ad.CostMonth) * 12).ToString()); ReplaceAll(WordDoc, "[Address]", ad.Address); ReplaceAll(WordDoc, "[Date]", ad.Date); ReplaceAll(WordDoc, "[Area]", ad.Area.ToString()); ReplaceAll(WordDoc, "[NameObject]", ad.ForWho); int kk = 1; foreach (var ee in ad.e1) { var trg = "[Extra" + kk + "]"; if (ee.IsSelected == true) { ReplaceAll(WordDoc, trg, ee.Text); } else { WordDoc.Bookmarks["bExtra" + kk].Range.Delete(); ReplaceAll(WordDoc, trg, ""); } ++kk; } kk = 1; foreach (var ee in ad.e2) { var trg = "[Sod" + kk + "]"; if (ee.IsSelected == true) { ReplaceAll(WordDoc, trg, ee.Text); } else { WordDoc.Bookmarks["bSod" + kk].Range.Delete(); ReplaceAll(WordDoc, trg, ""); } ++kk; } if (radioButton.IsChecked == true) { ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn1); } else { ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn2); } if (checkBoxServicePlan.IsChecked == false) { Wd.Range delRange = WordDoc.Range(); delRange.Start = WordDoc.Bookmarks["b0"].Range.Start; delRange.End = WordDoc.Bookmarks["b1"].Range.End; delRange.Delete(); } ReplaceAll(WordDoc, "[ServicePlanStart]", ""); ReplaceAll(WordDoc, "[ServicePlanEnd]", ""); //ReplaceAll(WordDoc, "[NameCost]", ad.ForWho); //Sebestoimost Wd.Table tt = FindTable(WordDoc, WordDoc.Bookmarks["tab6"]); double total = 0; foreach (var s in ad.Sebestimost) { tt.Rows.Add(); tt.Cell(tt.Rows.Count, 1).Range.Text = s.Name; tt.Cell(tt.Rows.Count, 2).Range.Text = s.CostMonth.ToString(); total += s.CostMonth; } tt.Rows.Add(); tt.Cell(tt.Rows.Count, 1).Range.Text = "Итого"; tt.Cell(tt.Rows.Count, 2).Range.Text = total.ToString(); /// //FOT Wd.Table ttFOT = FindTable(WordDoc, WordDoc.Bookmarks["tab7"]); total = 0; foreach (var s in ad.ShtatRasstanovka) { ttFOT.Rows.Add(); ttFOT.Cell(tt.Rows.Count, 1).Range.Text = s.Num.ToString(); ttFOT.Cell(tt.Rows.Count, 2).Range.Text = s.Name; ttFOT.Cell(tt.Rows.Count, 3).Range.Text = s.Quant.ToString(); ttFOT.Cell(tt.Rows.Count, 4).Range.Text = s.Smena.ToString(); } //// //os sredstv Wd.Table ttOS = FindTable(WordDoc, WordDoc.Bookmarks["tab8"]); total = 0; foreach (var s in ad.OsnSredstva) { ttOS.Rows.Add(); ttOS.Cell(tt.Rows.Count, 1).Range.Text = s.Num.ToString() + "."; ttOS.Cell(tt.Rows.Count, 2).Range.Text = s.Name; ttOS.Cell(tt.Rows.Count, 3).Range.Text = s.Quant.ToString(); ttOS.Cell(tt.Rows.Count, 4).Range.Text = s.CostMonth.ToString(); total += s.CostMonth; } ttOS.Rows.Add(); ttOS.Cell(tt.Rows.Count, 1).Range.Text = "Итого"; ttOS.Cell(tt.Rows.Count, 4).Range.Text = total.ToString(); //rash san Wd.Table ttSAN = FindTable(WordDoc, WordDoc.Bookmarks["tab9"]); total = 0; foreach (var s in ad.RashMaterials) { ttSAN.Rows.Add(); ttSAN.Cell(tt.Rows.Count, 1).Range.Text = s.Name; ttSAN.Cell(tt.Rows.Count, 2).Range.Text = s.Quant.ToString(); ttSAN.Cell(tt.Rows.Count, 3).Range.Text = s.Price.ToString(); ttSAN.Cell(tt.Rows.Count, 4).Range.Text = s.CostMonth.ToString(); total += s.CostMonth; } ttSAN.Rows.Add(); ttSAN.Cell(tt.Rows.Count, 1).Range.Text = "Итого в месяц"; ttSAN.Cell(tt.Rows.Count, 4).Range.Text = total.ToString(); StringBuilder sb = new StringBuilder(); foreach (var c in ad.Contacts) { if (c.IsSelected) { sb.AppendLine(c.Dolj); sb.AppendLine(c.Name); sb.AppendLine(c.Tel); sb.AppendLine(c.MobTel); sb.AppendLine(c.Email); sb.AppendLine(); } } ReplaceAll(WordDoc, "[Contacts]", sb.ToString()); WordDoc.TablesOfContents[1].Update(); foreach (Wd.Range docRange in WordDoc.Words) { docRange.HighlightColorIndex = Wd.WdColorIndex.wdNoHighlight; } } catch (Exception ee) { MessageBox.Show(ee.Message); } finally { WordDoc.Save(); WordApp.Documents.Close(); WordApp.Quit(Wd.WdSaveOptions.wdDoNotSaveChanges); string convertedXpsDoc = string.Concat(System.IO.Path.GetTempPath(), "\\", Guid.NewGuid().ToString(), ".xps"); XpsDocument xpsDocument = ConvertWordToXps(fn, convertedXpsDoc); if (xpsDocument != null) { documentViewer.Document = xpsDocument.GetFixedDocumentSequence(); } pw.Stop(); } // doc.Content.Find.Execute("[ND]", ReplaceWith: Doc.No); // SaveW(app, doc, TemplateFilePath); }