public static void HighlightWord(WordprocessingDocument wordDoc, string word) { Body body = wordDoc.MainDocumentPart.Document.Body; var paragraph = body.Descendants <Paragraph>().Where(x => x.InnerText == word); foreach (var para in paragraph) { var subRuns = para.Descendants <Run>().ToList(); foreach (var run in subRuns) { var subRunProp = run.Descendants <RunProperties>().ToList().FirstOrDefault(); var newColor = new Color(); newColor.Val = "EF413D"; if (subRunProp != null) { var color = subRunProp.Descendants <Color>().FirstOrDefault(); subRunProp.ReplaceChild(newColor, color); } else { var tmpSubRunProp = new RunProperties(); tmpSubRunProp.AppendChild(newColor); run.AppendChild(tmpSubRunProp); } } } wordDoc.MainDocumentPart.Document.Save(); }
private static void UpdateWordBlock(OpenXmlPartContainer container, OpenXmlElement block, string content) { OXW.Text new_text = new OXW.Text(content); if (!string.IsNullOrEmpty(content) && (char.IsWhiteSpace(content[0]) || char.IsWhiteSpace(content[content.Length - 1]))) { new_text.Space = SpaceProcessingModeValues.Preserve; } OXW.Run run = new OXW.Run(new_text); OXW.RunProperties originalRunProp = block.Descendants <OXW.RunProperties>().FirstOrDefault(); if (originalRunProp != null) { run.RunProperties = (OXW.RunProperties)originalRunProp.CloneNode(true); } OpenXmlElement finalBlock = run; var cbcontainer = block.Parent; if (null != cbcontainer) { cbcontainer.Parent.ReplaceChild(finalBlock, cbcontainer); } var docPart = container.GetPartsOfType <MainDocumentPart>().FirstOrDefault(); if (docPart == null) { var p = container as OpenXmlPart; if (p != null) { docPart = p.GetParentParts().FirstOrDefault(_ => _ is MainDocumentPart) as MainDocumentPart; } } if (docPart != null) { docPart.Document.Save(); } }
/// <summary> /// Creates a line of text for the document /// </summary> /// <param name="text"></param> /// <param name="size"></param> /// <param name="bold"></param> /// <returns></returns> private Run GetText(string text, int size, bool bold = false) { Run HighLightRun = new Run(); RunProperties runPro = new RunProperties(); RunFonts runFont = new RunFonts() { Ascii = "Arial", HighAnsi = "Arial" }; FontSize fontSize = new FontSize() { Val = size.ToString() }; Text runText = new Text() { Text = text }; runPro.Append(runFont); if (bold) { runPro.Append(new Bold()); } runPro.Append(fontSize); HighLightRun.Append(runPro); HighLightRun.Append(runText); return(HighLightRun); }
private static Paragraph CreateDateParagraph(RunProperties runProperties) { var date = DateTime.Today; var dateParagraph = AddParagraph(runProperties, date.ToShortDateString(), null); return(dateParagraph); }
private static RunProperties AddRunProperties(string textFont, string textSize, bool bold, bool italic) { var runProperties = new RunProperties(); var font = new RunFonts { Ascii = textFont }; var size = new FontSize { Val = new StringValue(textSize) }; runProperties.AppendChild(font); runProperties.AppendChild(size); if (bold) { runProperties.AppendChild(new Bold()); } if (italic) { runProperties.AppendChild(new Italic()); } return(runProperties); }
public Word.Paragraph GenerateParagraph(string val, bool bold = false, string sz = "12", string s = "style22", string f = "Courier New", Word.JustificationValues align = Word.JustificationValues.Left) { Word.ParagraphStyleId pstyle = new Word.ParagraphStyleId { Val = s }; Word.Justification jut = new Word.Justification { Val = new EnumValue <Word.JustificationValues>(align) }; Word.ParagraphProperties pprop = new Word.ParagraphProperties(pstyle, jut); Word.RunProperties rprop = new Word.RunProperties( new Word.RunFonts { Ascii = f, ComplexScript = f, HighAnsi = f }, new Word.Bold { Val = new OnOffValue(bold) }, new Word.BoldComplexScript { Val = new OnOffValue(bold) }, new Word.FontSize { Val = sz }); Word.Text text = new Word.Text(val); Word.Run run = new Word.Run(rprop, text); return(new Word.Paragraph(pprop, run)); }
public static void InsertText(String text, String styleXml, OpenXmlElement parentNode) { // Разделить строку на подстроки //String[] runs = macroVarValue.Split(new char[] { '\r', '\n' }); //String[] runs = Regex.Split(macroVarValue, "\r\n|\r|\n"); String[] runs = Regex.Split(text, "\r\n"); // Вставить текст foreach (String run in runs) { // Создать новый Paragraph Paragraph newParagraph = parentNode.AppendChild(new Paragraph()); // Вернуть старый стиль в Paragraph ParagraphProperties newParagraphProperties = newParagraph.AppendChild(new ParagraphProperties()); newParagraphProperties.InnerXml = styleXml; // Создать новый Run Run newRun = newParagraph.AppendChild(new Run()); // Вернуть старый стиль в Run RunProperties newRunProperties = newRun.AppendChild(new RunProperties()); newRunProperties.InnerXml = styleXml; // Вставить в него текст newRun.AppendChild(new Text(run)); } }
public static Color EffectiveColor(this Word.RunProperties runProperties, IReadOnlyCollection <Word.StyleRunProperties> styleRuns, Color defaultBrush) { var runColor = EnumerableExtensions .MergeAndFilter(runProperties?.Color, styleRuns.Select(s => s.Color), c => c != null) .FirstOrDefault(); return(runColor?.ToColor() ?? defaultBrush); }
public static float EffectiveFontSize(this Word.RunProperties runProperties, IReadOnlyCollection <Word.StyleRunProperties> styleRuns, float defaultSize) { var effectiveFontSize = EnumerableExtensions .MergeAndFilter(runProperties?.FontSize, styleRuns.Select(s => s.FontSize), fs => fs?.Val != null) .FirstOrDefault(); return(effectiveFontSize.ToFloat(defaultSize)); }
private static Font Override(this Font font, Word.RunProperties runProperties, IReadOnlyCollection <Word.StyleRunProperties> styleRuns) { var typeFace = runProperties.EffectiveTypeFace(styleRuns, font.FontFamily.Name); var size = runProperties.EffectiveFontSize(styleRuns, font.Size); var fontStyle = runProperties.EffectiveFontStyle(styleRuns, font.Style); return(new Font(typeFace, size, fontStyle)); }
public static string EffectiveTypeFace(this Word.RunProperties runProperties, IReadOnlyCollection <Word.StyleRunProperties> styleRuns, string defaultTypeFace) { var effectiveRunFonts = EnumerableExtensions .MergeAndFilter(runProperties?.RunFonts, styleRuns.Select(s => s.RunFonts), rf => rf != null) .FirstOrDefault(); return(effectiveRunFonts?.Ascii ?? defaultTypeFace); }
/**public void getFooterWithPageNumber() * { * foreach (Section wordSection in this.adoc.Sections) * { * Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; * footerRange.InlineShapes.AddHorizontalLineStandard(); * footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed; * footerRange.Font.Size = 10; * footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; * adoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(); * } * }**/ public void generateCoverPage(string data) { body.Append(new Paragraph(new Run(new Break()))); body.Append(new Paragraph(new Run(new Break()))); body.Append(new Paragraph(new Run(new Break()))); body.Append(new Paragraph(new Run(new Break()))); //heading Paragraph heading = new Paragraph(); ParagraphProperties hp = new ParagraphProperties(); hp.Justification = new Justification() { Val = JustificationValues.Center }; heading.Append(hp); Run r = new Run(); RunProperties runProperties = r.AppendChild(new RunProperties()); Bold bold = new Bold(); bold.Val = OnOffValue.FromBoolean(true); FontSize size = new FontSize(); size.Val = "60"; runProperties.AppendChild(bold); runProperties.AppendChild(size); Text t = new Text(data); r.Append(t); heading.Append(r); body.Append(heading); //subheading Paragraph subheading = new Paragraph(); ParagraphProperties shp = new ParagraphProperties(); shp.Justification = new Justification() { Val = JustificationValues.Center }; subheading.Append(shp); Run rs = new Run(); RunProperties rhProperties = rs.AppendChild(new RunProperties()); Bold bs = new Bold(); bs.Val = OnOffValue.FromBoolean(true); FontSize sh = new FontSize(); sh.Val = "40"; rhProperties.AppendChild(bs); rhProperties.AppendChild(sh); Text subhead = new Text("BUSINESS PLAN"); rs.Append(subhead); subheading.Append(rs); body.Append(subheading); addPageBreak(); }
private static Run CreateParagraphRun(RunProperties runProperties, string paragraphText) { var run = new Run(); run.AppendChild(runProperties.CloneNode(true)); ParseTextForOpenXml(run, paragraphText); return(run); }
// Add the bold style at a Run object used by a Paragraph in order to insert text in a Document. public RunProperties getBold(Run run) { RunProperties runProperties = run.AppendChild(new RunProperties()); var bold = new Bold(); bold.Val = OnOffValue.FromBoolean(true); runProperties.AppendChild(bold); return(runProperties); }
public void GetRunDetails(Paragraph p) { RunProperties rPr = new RunProperties(); foreach (Run r in p.Descendants <Run>()) { rPr = r.RunProperties; richTextBox1.Text += r.InnerText; } }
public void InsertDecisionDetailViewMessage() { Paragraph para = _body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); RunProperties runProperties = getHeading2(run); run.AppendChild(new Text(++_diagmarCounter + ". Decision Detail View")); // _body.AppendChild(new Paragraph(new Run(new Text(++_diagmarCounter + ". Decision Detail View")))); _body.AppendChild(new Paragraph()); }
public void InsertDecisionWithoutTopicMessage() { Paragraph para = _body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); RunProperties runProperties = getHeading2(run); run.AppendChild(new Text(++_diagmarCounter + ". Decisions without topic")); //_body.AppendChild(new Paragraph(new Run(new Text("Decisions not included in a topic:")))); _body.AppendChild(new Paragraph()); }
protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, CharAtom item) { bool runCreated = false; var run = renderer.Peek() as Run; if (run == null) { runCreated = true; run = (Run)renderer.Push(new Run()); var runProperties = new W.RunProperties(); runProperties.AppendChild(new W.RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" }); // Foreground color var cf = renderer.PeekForegroundColor(); if (cf.R != 0 || cf.G != 0 || cf.B != 0) { runProperties.AppendChild(new W.Color() { Val = string.Format("{0:X2}{1:X2}{2:X2}", cf.R, cf.G, cf.B) }); } // Background color var cb = renderer.PeekBackgroundColor(); if (cb.R != 255 || cb.G != 255 || cb.B != 255) { runProperties.AppendChild(new W.Shading() { Color = "Auto", Fill = string.Format("{0:X2}{1:X2}{2:X2}", cb.R, cb.G, cb.B) }); } run.AppendChild(runProperties); } var text = new DocumentFormat.OpenXml.Math.Text() { Text = string.Empty + item.Character }; run.AppendChild(text); if (runCreated) { renderer.PopTo(run); } return(WriteResult.Completed); }
/// <summary> /// Initialize new cell header object. /// </summary> /// <param name="textValue">The content of cell.</param> /// <returns>The TableCell object.</returns> public virtual TableCell NewTableCellHeader(string textValue, string width = "") { //create cell object and its properties TableCell tableCell = new TableCell(); TableCellProperties tableCellProperties = new TableCellProperties(); //ConditionalFormatStyle conditionalFormatStyle = new ConditionalFormatStyle() { Val = "001000000000" }; if (!string.IsNullOrEmpty(width)) { TableCellWidth tableCellWidth = new TableCellWidth() { Width = width, Type = TableWidthUnitValues.Dxa }; tableCellProperties.Append(tableCellWidth); } //tableCellProperties.Append(hideMark); //create paragrpah object and its properties Paragraph paragraph = new Paragraph(); ParagraphProperties paragraphProperties = new ParagraphProperties(); Justification justification = new Justification() { Val = JustificationValues.Center }; paragraphProperties.Append(justification); //create Run and Text Run run = new Run(); DocumentFormat.OpenXml.Wordprocessing.RunProperties runProperties = new DocumentFormat.OpenXml.Wordprocessing.RunProperties(); runProperties.Append(new DocumentFormat.OpenXml.Wordprocessing.Bold()); Text text = new Text(); //add content in Text text.Text = textValue; // Set RunProperties run.RunProperties = runProperties; //add Text to Run run.Append(text); //add Run to paragraph paragraph.Append(paragraphProperties); paragraph.Append(run); //add Paragraph to cell tableCell.Append(tableCellProperties); tableCell.Append(paragraph); return(tableCell); }
public static WP.Paragraph CenterBigTextParagraph(string text) { var pp = new WP.ParagraphProperties(new WP.Justification { Val = WP.JustificationValues.Center }); var rp = new WP.RunProperties(new WP.FontSize() { Val = "32" }, new WP.Bold()); return(new WP.Paragraph(pp, new WP.Run(rp, new WP.Text(text)))); }
/// <summary> /// Create a new document, append a single paragraph, set font and color. /// </summary> /// <returns>Is valid document</returns> public bool CreateDocumentWithSimpleParagraph(string pFileName) { mHasException = false; var fileName = Path.Combine(DocumentFolder, pFileName); if (File.Exists(fileName)) { File.Delete(fileName); } using (var document = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = document.AddMainDocumentPart(); mainPart.Document = new Document(); var body = mainPart.Document.AppendChild(new Body()); var para = body.AppendChild(new Paragraph()); Run runPara = para.AppendChild(new Run()); // Set the font to Arial to the first Run. var runProperties = new RunProperties( new RunFonts() { Ascii = "Arial" }); var color = new Color { Val = Helpers.ColorConverter(System.Drawing.Color.SandyBrown) }; runProperties.Append(color); Run run = document.MainDocumentPart.Document.Descendants <Run>().First(); run.PrependChild <RunProperties>(runProperties); var paragraphText = "The most basic unit of block-level content within a Word processing document, paragraphs are " + "stored using the <p> element. A paragraph defines a distinct division of content that begins on " + "a new line. A paragraph can contain three pieces of information: optional paragraph properties, " + "inline content (typically runs), and a set of optional revision IDs used to compare the content " + "of two documents."; runPara.AppendChild(new Text(paragraphText)); mainPart.Document.Save(); } return(Helpers.ValidateWordDocument(fileName) == 0); }
public static TextStyle Override(this TextStyle baseStyle, Word.RunProperties runProperties, IReadOnlyCollection <Word.StyleRunProperties> styleRuns) { if (runProperties == null && styleRuns.Count == 0) { return(baseStyle); } var font = baseStyle.Font.Override(runProperties, styleRuns); var brush = runProperties.EffectiveColor(styleRuns, baseStyle.Brush); var background = runProperties?.Highlight.ToColor(); return(baseStyle.WithChanged(font: font, brush: brush, background: background)); }
public void InsertTopicTable(ITopic topic) { Paragraph para = _body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); RunProperties runProperties = getHeading3(run); run.AppendChild(new Text(_diagmarCounter + "." + (++_topicCounter) + ". " + topic.Name)); //_body.AppendChild(new Paragraph(new Run(new Text(_diagmarCounter + "." + (++_topicCounter) + ". " + topic.Name)))); //Topic Name if (topic.Description != "") { _body.AppendChild(new Paragraph(new Run(new Text(topic.Description)))); //Topic Desc } _body.AppendChild(new Paragraph()); }
private static Paragraph AddParagraph(RunProperties runProperties, string paragraphText, string headingStyle) { var paragraph = new Paragraph(); // Append elements appropriately. var paragraphProperties = GetJustifiedParagraphProperties(headingStyle); paragraph.PrependChild(paragraphProperties); var paragraphRun = CreateParagraphRun(runProperties, paragraphText); paragraph.AppendChild(paragraphRun); return(paragraph); }
public void InsertDiagramImage(IEADiagram diagram) { if (diagram.IsRelationshipView()) { Paragraph para = _body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); RunProperties runProperties = getHeading2(run); run.AppendChild(new Text(++_diagmarCounter + ". Relationship View: " + diagram.Name)); //_body.AppendChild(new Paragraph(new Run(new Text(++_diagmarCounter + ". Relationship Viewpoint")))); } else if (diagram.IsStakeholderInvolvementView()) { Paragraph para = _body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); RunProperties runProperties = getHeading2(run); run.AppendChild( new Text(++_diagmarCounter + ". Decision Stakeholder Involvement View: " + diagram.Name)); //_body.AppendChild(new Paragraph(new Run(new Text(++_diagmarCounter + ". Decision Stakeholder Involvement Viewpoint")))); } else if (diagram.IsChronologicalView()) { Paragraph para = _body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); RunProperties runProperties = getHeading2(run); run.AppendChild(new Text(++_diagmarCounter + ". Decision Chronological View: " + diagram.Name)); //_body.AppendChild(new Paragraph(new Run(new Text(++_diagmarCounter + ". Decision Chronological Viewpoint")))); } else { return; } _body.AppendChild(new Paragraph(new Run(new Text()))); ImagePart imagePart = _mainPart.AddImagePart(ImagePartType.Emf); FileStream fs = diagram.DiagramToStream(); imagePart.FeedData(fs); Image image = Image.FromFile(fs.Name); AddImageToBody(_mainPart.GetIdOfPart(imagePart), Utils.GetImageSize(image)); //cleanup: fs.Close(); image.Dispose(); File.Delete(fs.Name); }
private void NextLevel_1(string pFileName) { var fileName = Path.Combine(DocumentFolder, pFileName); if (File.Exists(fileName)) { File.Delete(fileName); } using (var document = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = document.AddMainDocumentPart(); mainPart.Document = new Document(); var body = mainPart.Document.AppendChild(new Body()); var para = body.AppendChild(new Paragraph()); Run runPara = para.AppendChild(new Run()); // Set the font to Arial to the first Run. var runProperties = new RunProperties( new RunFonts() { Ascii = "Arial" }); var color = new Color { Val = Helpers.ColorConverter(System.Drawing.Color.SandyBrown) }; runProperties.Append(color); Run run = document.MainDocumentPart.Document.Descendants <Run>().First(); run.PrependChild <RunProperties>(runProperties); var paragraphText = "Styling paragraph with font color"; runPara.AppendChild(new Text(paragraphText)); mainPart.Document.Save(); } Console.WriteLine(Helpers.ValidateWordDocument(fileName)); }
public void VisitRunProperties(RunProperties element) { if (_pdfParagraph == null) { return; } _pdfText.Font.Bold = element.Bold != null; _pdfText.Font.Italic = element.Italic != null; _pdfText.Font.Underline = element.Underline != null ? Underline.Single : Underline.None; if (element.FontSize != null) { _pdfText.Font.Size = Convert.ToSingle(element.FontSize.Val) / 2; _pdfText.Font.Name = element.RunFonts.Ascii.Value; _pdfText.Font.Color = element.Color != null?PdfColor.Parse("#" + element.Color.Val) : PdfColor.Empty; } }
private static Paragraph GenerateParagraph(string text, bool bold, string textColor) { Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "004F7104", RsidParagraphProperties = "008F2986", RsidRunAdditionDefault = "004F7104" }; ParagraphProperties paragraphProperties1 = new ParagraphProperties(); Justification justification1 = new Justification() { Val = JustificationValues.Center }; Shading shading = new Shading() { Color = textColor, Fill = textColor == "000000" ? "FFFFFF" : GetRatingColor(Double.Parse(text)) }; paragraphProperties1.Append(justification1); paragraphProperties1.Append(shading); DocumentFormat.OpenXml.Wordprocessing.Run run1 = new DocumentFormat.OpenXml.Wordprocessing.Run(); DocumentFormat.OpenXml.Wordprocessing.RunProperties runProperties1 = new DocumentFormat.OpenXml.Wordprocessing.RunProperties(new DocumentFormat.OpenXml.Wordprocessing.Color() { Val = textColor }); if (bold) { runProperties1.Append(new DocumentFormat.OpenXml.Wordprocessing.Bold()); } DocumentFormat.OpenXml.Wordprocessing.Text text1 = new DocumentFormat.OpenXml.Wordprocessing.Text { Text = text }; run1.Append(runProperties1); run1.Append(text1); paragraph1.Append(paragraphProperties1); paragraph1.Append(run1); return(paragraph1); }
// Add properties with a stykle similar to Heading 3 style at a Run object used by a Paragraph in order to insert text in a Document. public RunProperties getHeading3(Run run) { RunProperties runProperties = run.AppendChild(new RunProperties()); var bold = new Bold(); bold.Val = OnOffValue.FromBoolean(true); var color = new Color { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" }; var size = new FontSize { Val = new StringValue("25") }; runProperties.AppendChild(bold); runProperties.AppendChild(color); runProperties.AppendChild(size); return(runProperties); }
public void AddText(String text = "", uint fontSize = 12, bool bold = false, bool italic = false) { Wp.Run _r = new Wp.Run(); Wp.RunProperties _rp = new Wp.RunProperties(); Wp.RunFonts _rf = new Wp.RunFonts() { Ascii = "Calibri", HighAnsi = "Calibri", EastAsia = "Calibri", ComplexScript = "Calibri" }; Wp.FontSize _fs = new Wp.FontSize() { Val = fontSize.ToString() }; Wp.Languages _l = new Wp.Languages() { Bidi = "en-us" }; _rp.Append(_rf); _rp.Append(_fs); _rp.Append(_l); if (italic) { _rp.Append(new Wp.Italic()); } if (bold) { _rp.Append(new Wp.Bold()); } Wp.Text _t = new Wp.Text(); _t.Text = text; _r.Append(_rp); _r.Append(_t); this._Paragraph.Append(_r); }
/// <summary> /// The create image paragraph. /// </summary> /// <param name="relationshipId"> /// The relationship id. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="width"> /// The width. /// </param> /// <param name="height"> /// The height. /// </param> /// <returns> /// </returns> private DocumentFormat.OpenXml.Wordprocessing.Paragraph CreateImageParagraph( string relationshipId, string name, string description, double width, double height) { // http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.extents.aspx // http://polymathprogrammer.com/2009/10/22/english-metric-units-and-open-xml/ // cx (Extent Length) // Specifies the length of the extents rectangle in EMUs. This rectangle shall dictate the size of the object as displayed (the result of any scaling to the original object). // Example: Consider a DrawingML object specified as follows: // <… cx="1828800" cy="200000"/> // The cx attributes specifies that this object has a height of 1828800 EMUs (English Metric Units). end example] // The possible values for this attribute are defined by the ST_PositiveCoordinate simple type (§20.1.10.42). // cy (Extent Width) // Specifies the width of the extents rectangle in EMUs. This rectangle shall dictate the size of the object as displayed (the result of any scaling to the original object). // Example: Consider a DrawingML object specified as follows: // < … cx="1828800" cy="200000"/> // The cy attribute specifies that this object has a width of 200000 EMUs (English Metric Units). end example] // The possible values for this attribute are defined by the ST_PositiveCoordinate simple type (§20.1.10.42). var paragraph1 = new DocumentFormat.OpenXml.Wordprocessing.Paragraph { RsidParagraphAddition = "00D91137", RsidRunAdditionDefault = "00AC08EB" }; var run1 = new Run(); var runProperties1 = new RunProperties(); var noProof1 = new NoProof(); runProperties1.Append(noProof1); var drawing1 = new Drawing(); var inline1 = new Inline { DistanceFromTop = 0U, DistanceFromBottom = 0U, DistanceFromLeft = 0U, DistanceFromRight = 0U }; var extent1 = new Extent { Cx = 5753100L, Cy = 3600450L }; extent1.Cx = (long)(width * 914400); extent1.Cy = (long)(height * 914400); var effectExtent1 = new EffectExtent { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }; var docProperties1 = new DocProperties { Id = 1U, Name = name, Description = description }; var nonVisualGraphicFrameDrawingProperties1 = new NonVisualGraphicFrameDrawingProperties(); var graphicFrameLocks1 = new GraphicFrameLocks { NoChangeAspect = true }; graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main"); nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1); var graphic1 = new Graphic(); graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main"); var graphicData1 = new GraphicData { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; var picture1 = new Picture(); picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture"); var nonVisualPictureProperties1 = new NonVisualPictureProperties(); var nonVisualDrawingProperties1 = new NonVisualDrawingProperties { Id = 0U, Name = name, Description = description }; var nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties(); var pictureLocks1 = new PictureLocks { NoChangeAspect = true, NoChangeArrowheads = true }; nonVisualPictureDrawingProperties1.Append(pictureLocks1); nonVisualPictureProperties1.Append(nonVisualDrawingProperties1); nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1); var blipFill1 = new BlipFill(); var blip1 = new Blip { Embed = relationshipId }; var blipExtensionList1 = new BlipExtensionList(); var blipExtension1 = new BlipExtension { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }; var useLocalDpi1 = new UseLocalDpi { Val = false }; useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main"); blipExtension1.Append(useLocalDpi1); blipExtensionList1.Append(blipExtension1); blip1.Append(blipExtensionList1); var sourceRectangle1 = new SourceRectangle(); var stretch1 = new Stretch(); var fillRectangle1 = new FillRectangle(); stretch1.Append(fillRectangle1); blipFill1.Append(blip1); blipFill1.Append(sourceRectangle1); blipFill1.Append(stretch1); var shapeProperties1 = new ShapeProperties { BlackWhiteMode = BlackWhiteModeValues.Auto }; var transform2D1 = new Transform2D(); var offset1 = new Offset { X = 0L, Y = 0L }; var extents1 = new Extents { Cx = extent1.Cx, Cy = extent1.Cy }; transform2D1.Append(offset1); transform2D1.Append(extents1); var presetGeometry1 = new PresetGeometry { Preset = ShapeTypeValues.Rectangle }; var adjustValueList1 = new AdjustValueList(); presetGeometry1.Append(adjustValueList1); var noFill1 = new NoFill(); var outline1 = new Outline(); var noFill2 = new NoFill(); outline1.Append(noFill2); shapeProperties1.Append(transform2D1); shapeProperties1.Append(presetGeometry1); shapeProperties1.Append(noFill1); shapeProperties1.Append(outline1); picture1.Append(nonVisualPictureProperties1); picture1.Append(blipFill1); picture1.Append(shapeProperties1); graphicData1.Append(picture1); graphic1.Append(graphicData1); inline1.Append(extent1); inline1.Append(effectExtent1); inline1.Append(docProperties1); inline1.Append(nonVisualGraphicFrameDrawingProperties1); inline1.Append(graphic1); drawing1.Append(inline1); run1.Append(runProperties1); run1.Append(drawing1); paragraph1.Append(run1); return paragraph1; }
public Wordprocessing.Body insertinform() { Wordprocessing.Body body = new Wordprocessing.Body(); //Параграф1 Wordprocessing.Paragraph paragraph1 = new Wordprocessing.Paragraph(); Wordprocessing.ParagraphProperties paragraphProperties1 = new Wordprocessing.ParagraphProperties(); Wordprocessing.SpacingBetweenLines spacingBetweenLines1 = new Wordprocessing.SpacingBetweenLines() { After = "0" }; Wordprocessing.Justification justification1 = new Wordprocessing.Justification() { Val = Wordprocessing.JustificationValues.Center }; paragraphProperties1.Append(spacingBetweenLines1); paragraphProperties1.Append(justification1); Wordprocessing.Run run1 = new Wordprocessing.Run(); Wordprocessing.RunProperties runProperties1 = new Wordprocessing.RunProperties(); Wordprocessing.RunFonts runFonts2 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }; Wordprocessing.Bold bold2 = new Wordprocessing.Bold(); Wordprocessing.FontSize fontSize2 = new Wordprocessing.FontSize() { Val = "24" }; runProperties1.Append(runFonts2); runProperties1.Append(bold2); runProperties1.Append(fontSize2); Wordprocessing.Text text1 = new Wordprocessing.Text(); text1.Text = "ФГБОУВПО \"ПЕРМСКИЙ ГОСУДАРСТВЕННЫЙ НАЦИОНАЛЬНЫЙ ИССЛЕДОВАТЕЛЬСКИЙ УНИВЕРСИТЕТ\""; run1.Append(runProperties1); run1.Append(text1); paragraph1.Append(paragraphProperties1); paragraph1.Append(run1); //Параграф2 Wordprocessing.Paragraph paragraph2 = new Wordprocessing.Paragraph(); Wordprocessing.ParagraphProperties paragraphProperties2 = new Wordprocessing.ParagraphProperties(); Wordprocessing.SpacingBetweenLines spacingBetweenLines2 = new Wordprocessing.SpacingBetweenLines() { After = "0" }; Wordprocessing.Justification justification2 = new Wordprocessing.Justification() { Val = Wordprocessing.JustificationValues.Center }; paragraphProperties2.Append(spacingBetweenLines2); paragraphProperties2.Append(justification2); Wordprocessing.Run run2 = new Wordprocessing.Run(); Wordprocessing.RunProperties runProperties2 = new Wordprocessing.RunProperties(); Wordprocessing.RunFonts runFonts4 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }; Wordprocessing.FontSize fontSize4 = new Wordprocessing.FontSize() { Val = "24" }; runProperties2.Append(runFonts4); runProperties2.Append(fontSize4); Wordprocessing.Text text2 = new Wordprocessing.Text(); text2.Text = "Механико-математический факультет "; run2.Append(runProperties2); run2.Append(text2); Wordprocessing.Run run3 = new Wordprocessing.Run(); Wordprocessing.RunProperties runProperties3 = new Wordprocessing.RunProperties(); Wordprocessing.RunFonts runFonts5 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }; Wordprocessing.FontSize fontSize5 = new Wordprocessing.FontSize() { Val = "24" }; runProperties3.Append(runFonts5); runProperties3.Append(fontSize5); Wordprocessing.Break break1 = new Wordprocessing.Break(); Wordprocessing.Text text3 = new Wordprocessing.Text(); text3.Text = "очная форма обучения"; run3.Append(runProperties3); run3.Append(break1); run3.Append(text3); paragraph2.Append(paragraphProperties2); paragraph2.Append(run2); paragraph2.Append(run3); //Параграф2 Wordprocessing.Paragraph paragraph3 = new Wordprocessing.Paragraph() { RsidParagraphAddition = "004D49E1", RsidParagraphProperties = "004D49E1", RsidRunAdditionDefault = "004D49E1" }; Wordprocessing.ParagraphProperties paragraphProperties3 = new Wordprocessing.ParagraphProperties(); Wordprocessing.SpacingBetweenLines spacingBetweenLines3 = new Wordprocessing.SpacingBetweenLines() { After = "0" }; Wordprocessing.Justification justification3 = new Wordprocessing.Justification() { Val = Wordprocessing.JustificationValues.Center }; paragraphProperties3.Append(spacingBetweenLines3); paragraphProperties3.Append(justification3); Wordprocessing.Run run4 = new Wordprocessing.Run(); Wordprocessing.RunProperties runProperties4 = new Wordprocessing.RunProperties(); Wordprocessing.RunFonts runFonts7 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }; Wordprocessing.Bold bold4 = new Wordprocessing.Bold(); runProperties4.Append(runFonts7); runProperties4.Append(bold4); Wordprocessing.Text text4 = new Wordprocessing.Text(); text4.Text = "ЭКЗАМЕНАЦИОННАЯ ВЕДОМОСТЬ"; run4.Append(runProperties4); run4.Append(text4); Wordprocessing.Run run5 = new Wordprocessing.Run(); Wordprocessing.Break break2 = new Wordprocessing.Break(); run5.Append(break2); paragraph3.Append(paragraphProperties3); paragraph3.Append(run4); paragraph3.Append(run5); body.Append(paragraph1); body.Append(paragraph2); body.Append(paragraph3); return body; }
/// <summary>追加officeMathMl 到指定的word文档 /// </summary> /// <param name="officeMathMl"></param> /// <param name="filePath"></param> public void WritOfficeMathMLToWord(string officeMathMl) { using (MemoryStream ms = new MemoryStream()) { // Create a OfficeMath instance from the // OfficeMathML xml. DocumentFormat.OpenXml.Math.OfficeMath om = new DocumentFormat.OpenXml.Math.OfficeMath(officeMathMl); // Add the OfficeMath instance to our // word template. DocumentFormat.OpenXml.Wordprocessing.Paragraph par = _wordDoc.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().FirstOrDefault(); foreach (var currentRun in om.Descendants<DocumentFormat.OpenXml.Math.Run>()) { // Add font information to every run. DocumentFormat.OpenXml.Wordprocessing.RunProperties runProperties2 = new DocumentFormat.OpenXml.Wordprocessing.RunProperties(); RunFonts runFonts2 = new RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" }; runProperties2.Append(runFonts2); currentRun.InsertAt(runProperties2, 0); } par.Append(om); } }
/// <summary>追加officeMathMl 到指定的word文档 /// </summary> /// <param name="officeMathMl"></param> /// <param name="filePath"></param> public void WritOfficeMathMLToWord(string officeMathMl, Run par) { DocumentFormat.OpenXml.Math.OfficeMath om = new DocumentFormat.OpenXml.Math.OfficeMath(officeMathMl); foreach (var currentRun in om.Descendants<DocumentFormat.OpenXml.Math.Run>()) { // Add font information to every run. DocumentFormat.OpenXml.Wordprocessing.RunProperties runProperties2 = new DocumentFormat.OpenXml.Wordprocessing.RunProperties(); RunFonts runFonts2 = new RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" }; runProperties2.Append(runFonts2); currentRun.InsertAt(runProperties2, 0); } par.Append(om); }