public void CopyToFile_Test_CopiesCorrectHyperlinks_WithMissingBookmarks() { Range range = _application.Documents.Add().Range(); const string bookmarkName = "bookmark1"; Interop.Paragraph paragraph1 = range.Paragraphs.Add(); paragraph1.Range.Text = "bookmark"; Interop.Bookmark bookmark = paragraph1.Range.Bookmarks.Add(bookmarkName); range.Paragraphs.Add(); Interop.Paragraph paragraph2 = range.Paragraphs.Add(); paragraph2.Range.Text = "link"; range.Hyperlinks.Add(paragraph2.Range, SubAddress: bookmark); _tmpFile = new OpenXmlHelper().CopyToFile(paragraph2.Range); _application.DisplayAlerts = Interop.WdAlertLevel.wdAlertsNone; _application.Windows[1].Close(Interop.WdSaveOptions.wdDoNotSaveChanges); using (WordprocessingDocument doc = WordprocessingDocument.Open(_tmpFile, true)) { OpenXml.Hyperlink hyperlink = doc.MainDocumentPart .Document .Body .Descendants <OpenXml.Hyperlink>() .First(); Assert.That(hyperlink.Anchor.Value, Is.EqualTo(bookmarkName)); } }
public int Compare(object x, object y) { Word.Paragraph px = (Word.Paragraph)x; Word.Paragraph py = (Word.Paragraph)y; int xStart = px.Range.Start; int xEnd = px.Range.End; int yStart = py.Range.Start; int yEnd = py.Range.End; if (xStart < yStart && xEnd < yEnd) { return(-1); } else if (xStart > yStart && xEnd > yEnd) { return(1); } else { } return(0); }
private void documentWriter() { //Create Word Application word.Application wordApp = new word.Application(); wordApp.Visible = true; //Create the Document word.Document wordDoc = wordApp.Documents.Add(); //Create the Heading Parahraph word.Paragraph wordPara = wordDoc.Paragraphs.Add(); wordPara.Range.Text = "Sales Report"; object styleName = "Intense Quote"; wordPara.Range.set_Style(ref styleName); wordPara.Range.InsertParagraphAfter(); //Create a New Paragraph word.Paragraph wordPara2 = wordDoc.Paragraphs.Add(); wordPara2.Range.Text = "This Document Contains all the required and crucial information regarding Sales made. This information includes the Item Sold Name, Quantity sold and Price per Sale. This will allow users to generate accurate and timely calculations regarding sales figures." + "\n" + "The Total Amount of Revenue Generated is: R" + TotalRevenue.ToString() + "\n" + "The Average Amount of Items Sold is:" + " " + lblAvGSold.Text.ToString() + "\n" + "The Average Amount of Revenue Generated is: R" + lblAVGRev.Text.ToString(); object styleName2 = "Subtle Emphasis"; wordPara2.Range.set_Style(ref styleName2); wordPara2.Range.InsertParagraphAfter(); word.Paragraph wordPara3 = wordDoc.Paragraphs.Add(); object styleName3 = "List Paragraph"; wordPara3.Range.set_Style(ref styleName3); wordPara3.Range.InsertParagraphAfter(); wordPara3.Range.Text = Details; }
public int Compare(object x, object y) { Word.Paragraph px = (Word.Paragraph)x; // 转换 Word.Paragraph py = (Word.Paragraph)y; // 转换 return((int)(px.Range.Font.Size - py.Range.Font.Size)); // 比较大小 }
private void documentWriter() { //Create Word Application word.Application wordApp = new word.Application(); wordApp.Visible = true; //Create the Document word.Document wordDoc = wordApp.Documents.Add(); //Create the Heading Parahraph word.Paragraph wordPara = wordDoc.Paragraphs.Add(); wordPara.Range.Text = "Suppliers Report"; object styleName = "Intense Quote"; wordPara.Range.set_Style(ref styleName); wordPara.Range.InsertParagraphAfter(); //Create a New Paragraph word.Paragraph wordPara2 = wordDoc.Paragraphs.Add(); wordPara2.Range.Text = "This Document contains a detailed Report on all Supplier Orders Sent and Received. It contains the following Crucial Information: Supplier Name, Product Ordered Name, Quantity Ordered, Received Date, Received Status and the Order Cost."; object styleName2 = "Subtle Emphasis"; wordPara2.Range.set_Style(ref styleName2); wordPara2.Range.InsertParagraphAfter(); word.Paragraph wordPara3 = wordDoc.Paragraphs.Add(); object styleName3 = "List Paragraph"; wordPara3.Range.set_Style(ref styleName3); wordPara3.Range.InsertParagraphAfter(); wordPara3.Range.Text = Details; }
public static void process(Word.Paragraph str) { str.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; str.Range.Font.Name = "Times New Roman"; str.Range.Font.Size = 14; str.Range.Paragraphs.Space1(); }
public void CopyToFile_Test_CopiesCorrectHyperlinksToBookmarks() { Range range = _application.Documents.Add().Range(); const string bookmarkName = "bookmark1"; Interop.Paragraph paragraph1 = range.Paragraphs.Add(); paragraph1.Range.Text = "bookmark"; Interop.Bookmark bookmark = paragraph1.Range.Bookmarks.Add(bookmarkName); range.Paragraphs.Add(); Interop.Paragraph paragraph2 = range.Paragraphs.Add(); paragraph2.Range.Text = "link"; range.Hyperlinks.Add(paragraph2.Range, SubAddress: bookmark); _tmpFile = new OpenXmlHelper().CopyToFile(range); using (WordprocessingDocument doc = WordprocessingDocument.Open(_tmpFile, true)) { OpenXml.Body body = doc.MainDocumentPart .Document .Body; OpenXml.BookmarkStart bookmarkStart = body.Descendants <OpenXml.BookmarkStart>().First(); OpenXml.Hyperlink hyperlink = body.Descendants <OpenXml.Hyperlink>().First(); Assert.That(bookmarkStart.Name.Value, Is.EqualTo(bookmarkName)); Assert.That(hyperlink.Anchor.Value, Is.EqualTo(bookmarkName)); } }
private void Ecrire_Medic(Word.Document doc, int nb, String nom, String forme, String dose, int quant, String utili, String durer, bool dernier) { Word.Paragraph parag = doc.Paragraphs.Add(); String boi = ""; if (quant == 1) { boi = " boite"; } else { boi = " boites"; } parag.Range.Text = "\t" + nb + ") " + nom + " " + forme.ToLower() + " " + dose.ToLower() + " " + quant + boi; parag.Range.Font.Size = 11; object start = parag.Range.Start + 1; object end = parag.Range.Start + nom.Length + 3 + nb.ToString().Length; Word.Range bold = doc.Range(ref start, ref end); Word.Range under = bold; bold.Bold = 1; under.Underline = Word.WdUnderline.wdUnderlineSingle; doc.Paragraphs.Add(); if (!dernier) { parag.Range.Text = "\t " + utili.ToLower() + " pendant " + durer.ToLower() + "\n\n"; } else { parag.Range.Text = "\t " + utili + " pendant " + durer; } }
private void documentWriter() { //Create Word Application word.Application wordApp = new word.Application(); wordApp.Visible = true; //Create the Document word.Document wordDoc = wordApp.Documents.Add(); //Create the Heading Parahraph word.Paragraph wordPara = wordDoc.Paragraphs.Add(); wordPara.Range.Text = "Wine Tasting Report"; object styleName = "Intense Quote"; wordPara.Range.set_Style(ref styleName); wordPara.Range.InsertParagraphAfter(); //Create a New Paragraph word.Paragraph wordPara2 = wordDoc.Paragraphs.Add(); wordPara2.Range.Text = "This Document contains all crucial information concerning made Wine Tasting Bookings. The Information presented includes, The Wine Tasting Date, Time, the Customer's Name who booked the Wine Tasting, the Customer's Phone Number and Email Address as well as the Group Size" + "\n" + "The Total Amount of bookings Made is:" + " " + BookingsMade.ToString(); object styleName2 = "Subtle Emphasis"; wordPara2.Range.set_Style(ref styleName2); wordPara2.Range.InsertParagraphAfter(); word.Paragraph wordPara3 = wordDoc.Paragraphs.Add(); object styleName3 = "List Paragraph"; wordPara3.Range.set_Style(ref styleName3); wordPara3.Range.InsertParagraphAfter(); wordPara3.Range.Text = Details; }
public void DetermineRangeToSearch(out SearchAreaType eType) { // this is either a selection chunk or "the rest of the document" from the insertion point theRangeToSearch = Document.Application.Selection.Range.Duplicate; // to determine if this is a selection or not, see if the start and end insertation points // are the same (i.e. no selection). // but we really don't want this to be considered a selection, if it's just one word, so // make sure that there are at least two words selected before calling it a selection // also, if the location hasn't changed since our last Find or Replace, then it's also // not a selection. if ((theRangeToSearch.Start == theRangeToSearch.End) || !m_bLocationChanged || (theRangeToSearch.Text.Trim().IndexOf(' ') == -1)) { ChangeToRestOfDocument(ref theRangeToSearch, out eType); } else { eType = SearchAreaType.eSelection; } // we call this function whenever the location has changed. In both cases, we then // want to restart the search from the beginning paragraph of the range. m_paraSearch = null; }
//особый гость public void PrintPar(string text, int align, bool subPar)//Вывод параграфа { Word.Paragraph p = doc.Content.Paragraphs.Add(ref missing); p.Range.Font.Bold = 1; p.Range.Font.Size = 14; p.Range.Text = text; switch (align) { case 0: p.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; break; case 1: p.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; break; case 2: p.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; break; } if (subPar) { object oStart = null; object oEnd = null; if (text.Contains("Занятие №")) { oStart = p.Range.Start + p.Range.Text.IndexOf('\"'); oEnd = p.Range.Start + p.Range.Text.LastIndexOf('\"'); } else { oStart = p.Range.Start + p.Range.Text.IndexOf(':'); oEnd = p.Range.Start + p.Range.Text.Length; } Word.Range pl = doc.Range(ref oStart, ref oEnd); pl.Bold = 0; } p.Range.InsertParagraphAfter(); }
public void CopyToFileTextOnly_Test_DoesNotKeepHyperlinksAndBookmarks() { Range range = _application.Documents.Add().Range(); const string bookmarkName = "bookmark1"; Interop.Paragraph paragraph1 = range.Paragraphs.Add(); paragraph1.Range.Text = "bookmark"; Interop.Bookmark bookmark = paragraph1.Range.Bookmarks.Add(bookmarkName); range.Paragraphs.Add(); Interop.Paragraph paragraph2 = range.Paragraphs.Add(); paragraph2.Range.Text = "link"; range.Hyperlinks.Add(paragraph2.Range, SubAddress: bookmark); _tmpFile = new OpenXmlHelper().CopyToFileTextOnly(range); using (WordprocessingDocument doc = WordprocessingDocument.Open(_tmpFile, true)) { OpenXml.Body body = doc.MainDocumentPart .Document .Body; CollectionAssert.IsEmpty(body.Descendants <OpenXml.BookmarkStart>()); CollectionAssert.IsEmpty(body.Descendants <OpenXml.Hyperlink>()); } }
/// <summary> /// Returns the offset of the starting of the /// previous paragraph /// </summary> /// <returns>the offset, -1 on error</returns> private int getStartOfPrevPara() { if (WordApp == null) { return(-1); } int caretPos = getCaretPos(); int paraStart = WordApp.Selection.Range.Paragraphs[1].Range.Start; Log.Debug("caretPos: " + caretPos + ", paraStart = " + paraStart); if (caretPos != paraStart) { return(paraStart); } Word.Paragraph para = WordApp.Selection.Range.Paragraphs[1]; int start = para.Range.Start; int prevStart = start; bool flag = false; int iteration = 0; bool breakOnFirst = false; while (true) { Word.Paragraph prev = para.Previous(); if (prev == null) { break; } start = prev.Range.Start; Log.Debug("start: " + start + ", prevStart: " + prevStart); if (prevStart - start == 1) { if (iteration == 0) { breakOnFirst = true; } } else if (prevStart - start > 1) { if (breakOnFirst || flag) { return(start); } flag = true; } para = prev; prevStart = start; iteration++; } return(-1); }
public Word.Document OpenResultDocTemplateNSave(string DocName, string SaveLocation) { Word.Application Wapp = new Word.Application(); Wapp.Visible = false; Word.Document Doc = Wapp.Documents.Open(@"C:\Surya\Work\ATS_Temp.docx"); Word.Paragraph Para = Doc.Paragraphs.Add(); Para.Range.Bold = 1; Para.Range.Text = "Test Script: " + FeatureContext.Current.FeatureInfo.Title + " Run #1 \n"; Para.Range.Bold = 0; Para.Range.Text = "Description: " + FeatureContext.Current.FeatureInfo.Description + " \n"; Para.Range.Text = "Application Name: \n"; Para.Range.Text = "Version: \n"; Para.Range.Text = "Environment: \n\n"; object Missing = System.Reflection.Missing.Value; object EndOfDoc = "\\endofdoc"; Word.Table TableObj; Word.Range Range = Doc.Bookmarks.get_Item(ref EndOfDoc).Range; TableObj = Doc.Tables.Add(Range, 1, 6, Missing, Missing); TableObj.Cell(1, 1).Range.Text = "Step #"; TableObj.Cell(1, 2).Range.Text = "Req ID"; TableObj.Cell(1, 3).Range.Text = "Action(s)"; TableObj.Cell(1, 4).Range.Text = "Expected Result(s)"; TableObj.Cell(1, 5).Range.Text = "Actual Result"; TableObj.Cell(1, 6).Range.Text = "Comments"; TableObj.Rows[1].Range.Bold = 1; TableObj.Borders.Enable = 1; Doc.SaveAs2(SaveLocation + DocName + ".docx"); Doc.Close(); Wapp.Quit(); return(Doc); }
private void PrintToWord(WordNet._Document oDoc, string toPrint, int fontSize, int bold, string align = FCMWordAlign.LEFT) { WordNet.WdParagraphAlignment walign = WordNet.WdParagraphAlignment.wdAlignParagraphLeft; if (align == FCMWordAlign.CENTER) { walign = WordNet.WdParagraphAlignment.wdAlignParagraphCenter; } if (align == FCMWordAlign.RIGHT) { walign = WordNet.WdParagraphAlignment.wdAlignParagraphRight; } object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; WordNet.Paragraph oPara = oDoc.Content.Paragraphs.Add(ref oRng); oPara.Range.Font.Name = "Arial"; oPara.Range.Font.Bold = bold; oPara.Range.Font.Size = fontSize; oPara.Range.Text = toPrint; oPara.Range.InsertParagraphAfter(); oPara.Alignment = walign; }
//设置固定行间距lineSpacing磅 public bool InsertText(string text, float fontsize, int fontbold, Word.WdParagraphAlignment align, int lineSpacing) { bool bRet = false; try { Word.Paragraph paragrah = m_WordDoc.Paragraphs.Add(ref missing); paragrah.Range.Text = text; paragrah.Range.Font.Size = fontsize; paragrah.Range.Font.Bold = fontbold; paragrah.Alignment = align; paragrah.LineSpacing = lineSpacing; //设置文档的行间距 paragrah.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceExactly; paragrah.Range.InsertParagraphAfter(); bRet = true; } catch (System.Exception) { bRet = false; } return(bRet); }
//插入文字 public bool InsertTextNewPage(string text, float fontsize, int fontbold, Word.WdParagraphAlignment align) { bool bRet = false; try { Word.Paragraph paragrah = m_WordDoc.Paragraphs.Add(ref missing); paragrah.Range.Text = text; paragrah.Range.Font.Size = fontsize; paragrah.Range.Font.Bold = fontbold; paragrah.Alignment = align; paragrah.Range.InsertParagraphAfter(); object pBreak = (int)Word.WdBreakType.wdSectionBreakNextPage; paragrah.Range.InsertBreak(ref pBreak); bRet = true; } catch (System.Exception) { bRet = false; } return(bRet); }
/*** * Szuka pojedynczego znacznika w p zaczynajac od miejsca poczatek * zwraca jego indeks * ***/ private int szukajZnacznikaHTML(int poczatek, String html, Wordy.Paragraph p) { return(0); /* poczatek =p.Range.Text.IndexOf("<"+html+">",(int)poczatek); * if ((int)poczatek < 0) * { poczatek = 0; } * else * { * koniec = p.Range.Text.IndexOf("</" + html, (int)poczatek); * if ((int)koniec < 0) * { koniec = 0; } * else * { * // p.Range.Text = p.Range.Text.Remove((int)poczatek, 3); * int dlstara = p.Range.Text.Length; * p.Range.Text = p.Range.Text.Substring((int)poczatek + 3, (int)koniec - (int)poczatek - 3); * koniec = (int)koniec - (dlstara - p.Range.Text.Length)+4; * } * } */ // koniec =p.Range.Text.IndexOf("</"+html,(int)poczatek); // if ((int)koniec < 0) // { koniec = 0; } // else // { //p.Range.Text= p.Range.Text.Remove((int)koniec, 4); // p.Range.Text.Replace("</" + html, ""); // koniec = (int)koniec - 4; // } }
/// <summary> /// Wkleja w aktualne miejsce zawartość załącznika z EAP /// </summary> public void wstawZalacznikRTF(EA.Element element) { string d = element.GetLinkedDocument(); if (d.Length == 0) { if (element.Notes.Length == 0) { Wordy.Paragraph oPar = doc.Content.Paragraphs.Add(); oPar.Range.Text = "Do uzupełnienia"; oPar.Range.Comments.Add(oPar.Range, "Brak treści - pole do uzupełnienia"); } return; } Thread th = null; if (th != null) { if (th.IsAlive) { th.Abort(); } } th = new Thread(() => CopySTA(d)); th.SetApartmentState(ApartmentState.STA); th.Start(); th.Join(); }
public void dodajRozdzialNaKoncu(String tekst, String styl) { Wordy.Paragraph par = wordApp.ActiveDocument.Paragraphs.Add(); String styl_txt = ""; if (styl == "1") { styl_txt = "HLD_tytul_rozdzialu"; } if (styl == "2") { styl_txt = "HLD_tytul_podrozdzialu"; } if (styl == "3") { styl_txt = "HLD_tytul_podrozdzialu"; } object indentStyle = styl_txt; par.set_Style(indentStyle); par.Range.Select(); par.Range.InsertAfter(tekst); }
public static void PrintToWord(IList outputs, string filename = "") { if (String.IsNullOrEmpty(filename)) { filename = "result"; } string path = $"{InvokeFolderBrowser()}\\{filename}.doc"; Word._Application word_app = new Word.Application(); Word._Document word_doc = word_app.Documents.Add(ref missing, ref missing, ref missing, ref missing); foreach (var row in outputs) { Word.Paragraph para = word_doc.Paragraphs.Add(ref missing); para.Range.Text = row.ToString(); para.Range.InsertParagraphAfter(); } object filepath = path; word_doc.SaveAs(ref filepath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); object save_changes = false; word_doc.Close(ref save_changes, ref missing, ref missing); word_app.Quit(ref save_changes, ref missing, ref missing); }
public Action AddToWordDocument(IResumeDataObject rdo, IResumeFormatObject rfo, Word.Document wordDoc) { return(() => { if (rdo.PublicationEntities.Count > 0) { // Publications label Word.Paragraph pubsLabelPara = wordDoc.Content.Paragraphs.Add(); Word.Range r7label = pubsLabelPara.Range; r7label.Text = "Selected Publications"; r7label.InsertParagraphAfter(); r7label.Font.Name = rfo.HeaderFontName; r7label.Font.Color = rfo.HeaderColorWord; r7label.Font.Size = rfo.HeaderFontSize; // Publication items int numPub = rdo.PublicationEntities.Count; for (int i = 0; i < numPub; i++) { Word.Paragraph pubParagraph = wordDoc.Content.Paragraphs.Add(); Word.Range r7 = pubParagraph.Range; r7.Text = rdo.PublicationEntities[i].Publication; r7.InsertParagraphAfter(); r7.Font.Name = rfo.BodyFontName; r7.Font.Size = rfo.BodyFontSize; r7.ParagraphFormat.SpaceAfter = 8; r7.ParagraphFormat.SpaceBefore = 8; } } }); }
protected WordRange GetStartingRange(Word.Range aRunRange) { // the search range might have a different start value than the paragraphs we're going to acquire if (m_paraSearch == null) { m_paraSearch = aRunRange.Paragraphs.First; System.Diagnostics.Debug.Assert(m_paraSearch != null); } Word.Range aParagraphRange = m_paraSearch.Range; System.Diagnostics.Debug.Assert(SearchAreaStart <= aParagraphRange.End); // if the end of the paragraph is exactly at the beginning of the search offset, then skip to // the next paragraph (this could be the case if we were searching for "\r" on a previous 'Find') if (SearchAreaStart == aParagraphRange.End) { m_paraSearch = m_paraSearch.Next(ref offset1); if (m_paraSearch == null) { return(null); // done } aParagraphRange = m_paraSearch.Range; } else if (SearchAreaStart > aParagraphRange.Start) { aParagraphRange.Start = SearchAreaStart; } return(new WordRange(aParagraphRange)); }
//Methods public void Execute(ObservableCollection <object> parameters) { ParameterPayload = parameters; DateTime StartDate = (DateTime)ParameterPayload[0]; DateTime EndDate = (DateTime)ParameterPayload[1]; if (VerifyParameters()) { List <RecordSearch> recordSearches = _rss.GetRecordSearchesByCriteria(string.Format("WHERE DatePaid BETWEEN #{0}# AND #{1}# AND CheckNumber IS NOT NULL OR CheckNumber <> ''", StartDate.ToShortDateString(), EndDate.ToShortDateString())); try { Word.Application wordApp = new Word.Application { ShowAnimation = false, Visible = true }; missing = Missing.Value; document = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing); document.Paragraphs.SpaceAfter = 0; AddTitle(StartDate, EndDate); //Create table Word.Paragraph tableSection = document.Content.Paragraphs.Add(ref missing); table = document.Tables.Add(tableSection.Range, recordSearches.Count + 1, 5, ref missing, ref missing); table.AllowAutoFit = true; table.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitWindow); SetColumnWidth(1, 15); SetColumnWidth(2, 15); SetColumnWidth(3, 45); SetColumnWidth(4, 15); SetColumnWidth(5, 10); //Create Header table.Rows[1].Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleSingle; table.Rows[1].Borders[Word.WdBorderType.wdBorderBottom].LineWidth = Word.WdLineWidth.wdLineWidth225pt; AddHeaderText(1, "Date Paid"); AddHeaderText(2, "IC File #"); AddHeaderText(3, "Project Name"); AddHeaderText(4, "Amount"); AddHeaderText(5, "Check #"); //Start Index at 2 to skip header row. int index = 2; foreach (RecordSearch rs in recordSearches) { AddEntry(index, rs); index++; } } catch (Exception exception) { MessageBox.Show(exception.Message); } } }
private void documentWriter() { //Create Word Application word.Application wordApp = new word.Application(); wordApp.Visible = true; //Create the Document word.Document wordDoc = wordApp.Documents.Add(); //Create the Heading Parahraph word.Paragraph wordPara = wordDoc.Paragraphs.Add(); wordPara.Range.Text = "Customer Report"; object styleName = "Intense Quote"; wordPara.Range.set_Style(ref styleName); wordPara.Range.InsertParagraphAfter(); //Create a New Paragraph word.Paragraph wordPara2 = wordDoc.Paragraphs.Add(); wordPara2.Range.Text = "This Document contains all needed information of Customers registered on the System. The information captured includes, The Customer's Name, Phone Number, Email Address, Date of Birth, if the Customer is a Member and the Loyalty Points the Customer has Available." + "\n" + " The Total amount of Loyalty Points Available on the System is:" + " " + TotalLoyaltyPoints.ToString(); object styleName2 = "Subtle Emphasis"; wordPara2.Range.set_Style(ref styleName2); wordPara2.Range.InsertParagraphAfter(); word.Paragraph wordPara3 = wordDoc.Paragraphs.Add(); object styleName3 = "List Paragraph"; wordPara3.Range.set_Style(ref styleName3); wordPara3.Range.InsertParagraphAfter(); wordPara3.Range.Text = Details; }
public Action AddToWordDocument(IResumeDataObject rdo, IResumeFormatObject rfo, Word.Document wordDoc) { return(() => { // Education label Word.Paragraph educationLabelPara = wordDoc.Content.Paragraphs.Add(); Word.Range r6label = educationLabelPara.Range; r6label.Text = "Education"; r6label.InsertParagraphAfter(); r6label.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; r6label.Font.Name = rfo.HeaderFontName; r6label.Font.Color = rfo.HeaderColorWord; r6label.Font.Size = rfo.HeaderFontSize; // Education items int numEduc = rdo.EducationEntities.Count; for (int i = 0; i < numEduc; i++) { Word.Paragraph educParagraph = wordDoc.Content.Paragraphs.Add(); Word.Range r6 = educParagraph.Range; r6.Text = rdo.EducationEntities[i].Credential + ", " + rdo.EducationEntities[i].Institution; r6.InsertParagraphAfter(); r6.Font.Name = rfo.BodyFontName; r6.Font.Size = rfo.BodyFontSize; r6.ParagraphFormat.SpaceAfter = 8; r6.ParagraphFormat.SpaceBefore = 8; } }); }
public void CheckboxInsert() { try { // Создание Word процесса var wordApp = new word.Application(); // Открытие Word документа var wordDocument = wordApp.Documents.Open(Program.doc); // Запись данных в протокол Object missing = System.Reflection.Missing.Value; word.Paragraph para1 = wordDocument.Content.Paragraphs.Add(ref missing); para1.Range.Text = " → " + Program.Insert; para1.Range.Font.Size = 12; para1.Range.Font.Color = word.WdColor.wdColorViolet; para1.Range.Font.Name = "Times New Roman"; para1.Range.InsertParagraphAfter(); // Сохранение документа и выход wordDocument.Save(); wordApp.Quit(); } catch { // Вывод сообщения MessageBox.Show("Отсутствует шаблон протокола! Обратитесь в службу поддержки.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private static bool IsPageStartParagraph(Word.Paragraph para) { return(para.PageBreakBefore == TrueValue && para.Range.Sentences != null && para.Range.Sentences.Count > 0 && !string.IsNullOrEmpty(CleanFileName(para.Range.Sentences[1].Text))); }
/// <summary> /// Create key value hyperlink section /// </summary> /// <param name="headername"></param> /// <param name="text"></param> /// <param name="hyperlink"></param> public override void CreateNamedSection(string headername, string text, string hyperlink) { // new heading CreateHeader(headername); Word.Paragraph accessParagraph = document.Paragraphs.Add(); // create caption string accessParagraphText = text; string webLink = hyperlink; accessParagraph.Range.Text = Utilities.ImplicitMalloc(accessParagraphText, webLink.Length); // several indents needed for (int i = 0; i < 3; i++) { accessParagraph.Indent(); } document.Hyperlinks.Add(document.Range(accessParagraph.Range.Start + accessParagraphText.Length, accessParagraph.Range.Start + accessParagraphText.Length + webLink.Length), webLink, Type.Missing, settings["Project Name"], webLink, Type.Missing); // split InsertTableSplit(accessParagraph); }
private void btngenerar_Click(object sender, EventArgs e) { string codigo, desc; if (dgvlistado.Rows.Count <= 0) { MessageBox.Show("No se ha encontrado ningun registro"); } else { objWord.Application objAplicacion = new objWord.Application(); objWord.Document objDocumento = objAplicacion.Documents.Add(); for (int i = 0; i < dgvlistado.RowCount - 1; i++) { codigo = dgvlistado.Rows[i].Cells[0].Value.ToString(); desc = dgvlistado.Rows[i].Cells[1].Value.ToString(); if (VeririficarCod(codigo)) { objWord.Paragraph objParrafo = objDocumento.Content.Paragraphs.Add(Type.Missing); objParrafo.Range.Font.Size = 14; objParrafo.Range.Font.Color = objWord.WdColor.wdColorBlack; objParrafo.Range.Text = codigo; objParrafo.Range.Font.Name = "Code39"; objParrafo.Range.InsertParagraphAfter(); } else { MessageBox.Show("No existe el codigo del producto"); } } objDocumento.SaveAs2(rutaw + "\\CodigoMarcas.docx"); objDocumento.Close(); objAplicacion.Quit(); } }
public void ProcessParagraphsFindAndReplace(FindWordProcessor aWordProcessor, Word.Range theRangeToSearch, BackgroundWorker worker) { // get Range object we can manipulate for searching (i.e. don't muck with the original WordRange aRunRange = GetStartingRange(theRangeToSearch); if (aRunRange == null) return; // how many paragraphs ahead we have to look for a match int nEndRangeToSearch = -1; // might change from loop to loop if we do replacements (so update inside loop) object nOffsetParagraph = aWordProcessor.NumOfParagraphsToSearch - 1; do { SearchAreaStart = aRunRange.Start; // this updates the progress bar worker.ReportProgress(SearchAreaStart); // if the search string contains multiple '\r's, then we have to look ahead that many paragraphs int SearchAreaEnd; nEndRangeToSearch = theRangeToSearch.End; // might change from loop to loop if we do replacements if (0 < (int)nOffsetParagraph) { Word.Paragraph aEndParagraph = m_paraSearch.Next(ref nOffsetParagraph); if (aEndParagraph == null) return; // means we can't possibly find it now SearchAreaEnd = Math.Min(aEndParagraph.Range.End, nEndRangeToSearch); aRunRange.End = SearchAreaEnd; } else { int nEndOfRun = aRunRange.End; if (nEndOfRun > nEndRangeToSearch) { aRunRange.End = SearchAreaEnd = nEndRangeToSearch; } else SearchAreaEnd = nEndOfRun; } // loop until the end of the paragraph and process it as a whole unit (we may have to do this multiple times) bool bGoToNext = true; while (SearchAreaStart < SearchAreaEnd) { // keep track of the last index so we can tell whether anything was found or not FindWordProcessor.FindResult res = aWordProcessor.FindReplaceCompare(aRunRange, ref SearchAreaStart, ref FoundAreaLength); // if we found it and need to stop (or if the user had cancelled the search)... bGoToNext = true; // assume we will if ((res == FindWordProcessor.FindResult.eFindFound) || worker.CancellationPending) return; // otherwise, it might have been a replacement and we have to update the end of the paragraph // value and the end of the range and do it again (e.g. find the next occurrence to replace) else if (res == FindWordProcessor.FindResult.eReplaceFound) { // we might have actually removed the paragraph mark, in which case the next paragraph // is now part of the current paragraph. Unfortunately, the aParagraphRange isn't // updated. // if the search string contained '\r's, then we have to look ahead all over again if (aWordProcessor.IsAnyCRs) { bGoToNext = false; break; } else { Word.Range aParagraphRange = m_paraSearch.Range; SearchAreaEnd = aParagraphRange.End; aRunRange.End = SearchAreaEnd; aRunRange.Start = SearchAreaStart; } } // otherwise, it means we didn't find it here and we're done with this paragraph else { System.Diagnostics.Debug.Assert(!aWordProcessor.IsFound); break; } } // advance to the next paragraph if (bGoToNext) m_paraSearch = m_paraSearch.Next(ref offset1); if (m_paraSearch != null) { aRunRange = new WordRange(m_paraSearch.Range); // in the case we replace some CRs, we re-start where we left off (after the replaced text) if (!bGoToNext) aRunRange.Start = SearchAreaStart; } } while ((m_paraSearch != null) && (aRunRange.Start < nEndRangeToSearch)); }
public void ResetPosition() { nSelectionStart = nSelectionEnd = SearchAreaStart = FoundAreaLength = -1; m_paraSearch = null; if (theSearchProcessor != null) theSearchProcessor.NumOfReplacements = 0; }
protected WordRange GetStartingRange(Word.Range aRunRange) { // the search range might have a different start value than the paragraphs we're going to acquire if (m_paraSearch == null) { m_paraSearch = aRunRange.Paragraphs.First; System.Diagnostics.Debug.Assert(m_paraSearch != null); } Word.Range aParagraphRange = m_paraSearch.Range; System.Diagnostics.Debug.Assert(SearchAreaStart <= aParagraphRange.End); // if the end of the paragraph is exactly at the beginning of the search offset, then skip to // the next paragraph (this could be the case if we were searching for "\r" on a previous 'Find') if (SearchAreaStart == aParagraphRange.End) { m_paraSearch = m_paraSearch.Next(ref offset1); if (m_paraSearch == null) return null; // done aParagraphRange = m_paraSearch.Range; } else if (SearchAreaStart > aParagraphRange.Start) { aParagraphRange.Start = SearchAreaStart; } return new WordRange(aParagraphRange); }
private int check_Kernel(List<OfficeElement> ls) { int points = 0, i; int curPart = -1; //当前正在分析哪一部分的考点 for (i = 0; i < ls.Count; i++) { OfficeElement oe = ls[i]; #region 具体考点对象定位 if (oe.AttribName == "Root") continue; if (oe.AttribName == "Documents") continue; if (oe.AttribName == "Paragraph") { #region 段落定位 try { int paraIdx = int.Parse(oe.AttribValue); stuPara = stuDoc.Paragraphs[paraIdx]; ansPara = ansDoc.Paragraphs[paraIdx]; } catch { points = 0; break; } #endregion curPart = PART_PARAGRAPH; continue; } if (oe.AttribName == "Table") { #region 表格定位 try { int tabIdx = int.Parse(oe.AttribValue); stuTab = stuDoc.Tables[tabIdx]; ansTab = ansDoc.Tables[tabIdx]; } catch { points = 0; break; } #endregion curPart = PART_TABLE; continue; } if (oe.AttribName == "Cell") { #region 单元格定位 try { int rowIdx, colIdx, commaIdx; commaIdx = oe.AttribValue.IndexOf(','); rowIdx = int.Parse(oe.AttribValue.Substring(0, commaIdx)); colIdx = int.Parse(oe.AttribValue.Substring(commaIdx + 1)); stuCell = stuTab.Cell(rowIdx, colIdx); ansCell = ansTab.Cell(rowIdx, colIdx); } catch { points = 0; break; } #endregion curPart = PART_CELL; continue; } if (oe.AttribName == "Textbox") { #region 文本框定位 try { int tbIdx = int.Parse(oe.AttribValue); object ob = tbIdx; stuSp = stuDoc.Shapes.get_Item(ref ob); ansSp = ansDoc.Shapes.get_Item(ref ob); stuTf = stuSp.TextFrame; ansTf = ansSp.TextFrame; } catch { points = 0; break; } #endregion curPart = PART_TEXTBOX; continue; } if (oe.AttribName == "PageSetup") { #region 页面设置定位 try { stuPs = stuDoc.PageSetup; ansPs = ansDoc.PageSetup; } catch { points = 0; break; } #endregion continue; } #endregion #region 段落属性判分 if (curPart == PART_PARAGRAPH) { switch (oe.AttribName) { case "Indent": break; case "Font": stuRange = stuPara.Range; ansRange = ansPara.Range; break; case "Dropcap": stuDc = stuPara.DropCap; ansDc = ansPara.DropCap; break; case "TextColumns": stuTc = stuPara.Range.PageSetup.TextColumns; ansTc = ansPara.Range.PageSetup.TextColumns; break; #region 段落部分 case "Alignment": if (stuPara.Alignment == ansPara.Alignment) points = int.Parse(oe.AttribValue); break; case "CharacterUnitFirstLineIndent": if (stuPara.CharacterUnitFirstLineIndent == ansPara.CharacterUnitFirstLineIndent) points = int.Parse(oe.AttribValue); break; case "CharacterUnitLeftIndent": if (stuPara.CharacterUnitLeftIndent == ansPara.CharacterUnitLeftIndent) points = int.Parse(oe.AttribValue); break; case "CharacterUnitRightIndent": if (stuPara.CharacterUnitRightIndent == ansPara.CharacterUnitRightIndent) points = int.Parse(oe.AttribValue); break; case "LineUnitBefore": if (stuPara.LineUnitBefore == ansPara.LineUnitBefore) points = int.Parse(oe.AttribValue); break; case "LineUnitAfter": if (stuPara.LineUnitAfter == ansPara.LineUnitAfter) points = int.Parse(oe.AttribValue); break; case "LineSpacingRule": if (stuPara.LineSpacingRule == ansPara.LineSpacingRule) points = int.Parse(oe.AttribValue); break; case "LineSpacing": if (stuPara.LineSpacing == ansPara.LineSpacing) points = int.Parse(oe.AttribValue); break; #endregion #region 文字部分 case "Text": if (stuRange.Text == ansRange.Text) points = int.Parse(oe.AttribValue); break; case "FontSize": if (stuRange.Font.Size == ansRange.Font.Size) points = int.Parse(oe.AttribValue); break; case "FontName": if (stuRange.Font.Name == ansRange.Font.Name) points = int.Parse(oe.AttribValue); break; case "Bold": if (stuRange.Font.Bold == ansRange.Font.Bold) points = int.Parse(oe.AttribValue); break; case "Italic": if (stuRange.Font.Italic == ansRange.Font.Italic) points = int.Parse(oe.AttribValue); break; case "Underline": if (stuRange.Font.Underline == ansRange.Font.Underline) points = int.Parse(oe.AttribValue); break; case "UnderlineColor": if (stuRange.Font.UnderlineColor == ansRange.Font.UnderlineColor) points = int.Parse(oe.AttribValue); break; case "ForeColor": if (stuRange.Font.Color == ansRange.Font.Color) points = int.Parse(oe.AttribValue); break; case "HighLightColor": if (stuRange.HighlightColorIndex == ansRange.HighlightColorIndex) points = int.Parse(oe.AttribValue); break; case "Superscript": if (stuRange.Font.Superscript == ansRange.Font.Superscript) points = int.Parse(oe.AttribValue); break; case "Subscript": if (stuRange.Font.Subscript == ansRange.Font.Subscript) points = int.Parse(oe.AttribValue); break; case "Spacing": if (stuRange.Font.Spacing == ansRange.Font.Spacing) points = int.Parse(oe.AttribValue); break; case "Animation": if (stuRange.Font.Animation == ansRange.Font.Animation) points = int.Parse(oe.AttribValue); break; case "BackgroundPatternColor": if (stuRange.Shading.BackgroundPatternColor == ansRange.Shading.BackgroundPatternColor) points = int.Parse(oe.AttribValue); break; #endregion #region 首字下沉 case "Position": if (stuDc.Position == ansDc.Position) points = int.Parse(oe.AttribValue); break; case "DcFontName": if (stuDc.FontName == ansDc.FontName) points = int.Parse(oe.AttribValue); break; case "LinesToDrop": if (stuDc.LinesToDrop == ansDc.LinesToDrop) points = int.Parse(oe.AttribValue); break; case "DistanceFromText": if (stuDc.DistanceFromText == ansDc.DistanceFromText) points = int.Parse(oe.AttribValue); break; #endregion #region 分栏与栏宽 case "TextColumnsCount": if (stuTc.Count == ansTc.Count) points = int.Parse(oe.AttribValue); break; case "TextColumnsWidth": if (stuTc.Width == ansTc.Width) points = int.Parse(oe.AttribValue); break; case "TextColumnsSpacing": if (stuTc.Spacing == ansTc.Spacing) points = int.Parse(oe.AttribValue); break; case "TextColumnsLineBetween": if (stuTc.LineBetween == ansTc.LineBetween) points = int.Parse(oe.AttribValue); break; #endregion } continue; } #endregion #region 表格属性判分 if (curPart == PART_TABLE) { switch (oe.AttribName) { case "Rows": if (stuTab.Rows.Count == ansTab.Rows.Count) points = int.Parse(oe.AttribValue); break; case "Columns": if (stuTab.Columns.Count == ansTab.Columns.Count) points = int.Parse(oe.AttribValue); break; } continue; } #endregion #region 单元格属性判分 if (curPart == PART_CELL) { switch (oe.AttribName) { case "Text": if (stuCell.Range.Text == ansCell.Range.Text) points = int.Parse(oe.AttribValue); break; case "Height": if (stuCell.Height == ansCell.Height) points = int.Parse(oe.AttribValue); break; case "Width": if (stuCell.Width == ansCell.Width) points = int.Parse(oe.AttribValue); break; } continue; } #endregion #region 文本框属性判分 if (curPart == PART_TEXTBOX) { switch (oe.AttribName) { case "Text": if (stuTf.TextRange.Text == ansTf.TextRange.Text) points = int.Parse(oe.AttribValue); break; case "Orientation": if (stuTf.Orientation == ansTf.Orientation) points = int.Parse(oe.AttribValue); break; case "FontName": if (stuTf.TextRange.Font.Name == ansTf.TextRange.Font.Name) points = int.Parse(oe.AttribValue); break; case "FontSize": if (stuTf.TextRange.Font.Size == ansTf.TextRange.Font.Size) points = int.Parse(oe.AttribValue); break; case "ForeColor": if (stuTf.TextRange.Font.Color == ansTf.TextRange.Font.Color) points = int.Parse(oe.AttribValue); break; case "HighLightColor": if (stuTf.TextRange.HighlightColorIndex == ansTf.TextRange.HighlightColorIndex) points = int.Parse(oe.AttribValue); break; case "Spacing": if (stuTf.TextRange.Font.Spacing == ansTf.TextRange.Font.Spacing) points = int.Parse(oe.AttribValue); break; case "Alignment": if (stuTf.TextRange.ParagraphFormat.Alignment == ansTf.TextRange.ParagraphFormat.Alignment) points = int.Parse(oe.AttribValue); break; } continue; } #endregion #region 页面设置属性判分 if (curPart == PART_PAGESETUP) { switch (oe.AttribName) { case "TopMargin": if (stuPs.TopMargin == ansPs.TopMargin) points = int.Parse(oe.AttribValue); break; case "BottomMargin": if (stuPs.BottomMargin == ansPs.BottomMargin) points = int.Parse(oe.AttribValue); break; case "LeftMargin": if (stuPs.LeftMargin == ansPs.LeftMargin) points = int.Parse(oe.AttribValue); break; case "RightMargin": if (stuPs.RightMargin == ansPs.RightMargin) points = int.Parse(oe.AttribValue); break; case "HeaderDistance": if (stuPs.HeaderDistance == ansPs.HeaderDistance) points = int.Parse(oe.AttribValue); break; case "FooterDistance": if (stuPs.FooterDistance == ansPs.FooterDistance) points = int.Parse(oe.AttribValue); break; case "Orientation": if (stuPs.Orientation == ansPs.Orientation) points = int.Parse(oe.AttribValue); break; case "GutterPos": if (stuPs.GutterPos == ansPs.GutterPos) points = int.Parse(oe.AttribValue); break; } continue; } #endregion } return points; }
private ParagraphInfo(Word.Paragraph para, Word.Paragraph previousPara, WrapperType wt) : this() { _strategy = _strategyMap.GetValueOrDefault( new StrategyKey(wt , para == null ? 0 : (int)para.OutlineLevel , para == null ? string.Empty : para.get_Style().NameLocal.ToString() , previousPara == null ? string.Empty : previousPara.get_Style().NameLocal.ToString()) , Strategy.Default); _wrapperType = wt; Paragraph = para; }