openxml

Open XML word content controls

北战南征 提交于 2019-12-11 03:07:12
问题 Here is my code trying to get the content controls with the tag "company" using (WordprocessingDocument template = WordprocessingDocument.Open("d:/dev/ProposalTemplate1.dotx", true)) { MainDocumentPart mainPart = template.MainDocumentPart; SdtBlock block = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "TEST").Single(); Text t = block.Descendants<Text>().Single(); t.Text = "COMPANY_NAME"; } I got the error "Object reference not set to an

How to get MS Word total pages count using Open XML SDK?

半腔热情 提交于 2019-12-11 03:05:04
问题 I am using below code to get the page count but it is not giving actual page count(PFA). What is the better way to get the total pages count? var pageCount = doc.ExtendedFilePropertiesPart.Properties.Pages.Text.Trim(); Note: We cannot use the Office Primary Interop Assemblies in my Azure web app service Thanks in advance. 回答1: In theory, the following property can return that information from the Word Open XML file, using the Open XML SDK: int pageCount = (int) document

Embedding an OpenXML document within another OpenXml document

我是研究僧i 提交于 2019-12-11 02:15:39
问题 I have a need to gather a number of .docx files in a folder and "chain" them into a single document that will be displayed to the user. Now I've read Brian Jones' article but while it sounded promising I have encountered a problem. When I perform the actions manually using Word 2007 I end up with a copy of the docx file in the /embeddings folder and when I open the document I am presented with the embedded content. However, when I do the same thing through code I end up with a file called

Replacing in inner Text in open xml element?

坚强是说给别人听的谎言 提交于 2019-12-10 20:42:38
问题 I'm using open xml SDK 2.0 and i'm kind off new to this. I have actually created a quickpart (containg content control) in my word 2007 document named "hello.docx". Now I need to copy the quickpart into the other location of the same document named "hello.docx". I was very thank full for this post http://www.techques.com/question/1-3448297/Replacing-Content-Controls-in-OpenXML and same thing is posted on stack overflow forum for which i was very thank full :)...This post just deletes the

Replace text holder with image in OpenXML

蹲街弑〆低调 提交于 2019-12-10 20:22:07
问题 Below I have code that inserts an image at the end of a document in word using OpenXML. What I need to do is try and find and item called [Image Holder] within the document and replace that with the image I'm passing over. Here is the current code that adds it to the end of a document var element = new Drawing( new DW.Inline( new DW.Extent() { Cx = 990000L, Cy = 792000L }, new DW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }, new DW.DocProperties() { Id =

How do I add an XML Map programmatically to an Excel 2010 Spreadsheet?

给你一囗甜甜゛ 提交于 2019-12-10 20:10:53
问题 I have a basic XML file, which I need to add as an XML Map to an Excel 2010 Worksheet. How do I do this programmatically? I would prefer a solution which uses Microsoft OpenXML SDK. 回答1: You will need to add a CustomXmlMappingsPart to your WorkbookPart and populate it with the schema for your XML. Then you will need to add a ConnectionsPart that is linked to your xml file. The below xml lives on my desktop in the file note.xml: <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading

Open xml getting images from .pptx file

北城以北 提交于 2019-12-10 20:10:07
问题 I have a Windows forms app in .Net 4.0. I work in C#. I want to grab an image from a given slide in a .pptx file. This code gets every image on the slide: public static SlidePart GetSlidePart(PresentationDocument presentationDocument, int slideIndex) { if (presentationDocument == null) { throw new ArgumentNullException("presentationDocument", "GetSlidePart Method: parameter presentationDocument is null"); } int slidesCount = CountSlides(presentationDocument); if (slideIndex < 0 || slideIndex

How can I add an external image to a word document using OpenXml?

落爺英雄遲暮 提交于 2019-12-10 19:19:36
问题 I am trying to use C# and Open XML to insert an image from a url into a doc. The image may change so I don't want to download it, I want it to remain an external reference. I've found several examples like this one that allow me to add a local image: http://msdn.microsoft.com/en-us/library/bb497430.aspx How can I adapt that to take a URI? Or is there another approach altogether? 回答1: You can add an external image to an word document via a quick parts field. For a description please see the

OpenXML SDK: How to identify data type of cell?

流过昼夜 提交于 2019-12-10 18:18:36
问题 I am working on OPenXML SDK to work with excel. Currently, I am facing with one issue, how to identify data type of cell, datetime or numeric. Because, in case cell's type is date, we need to convert double value to datetime again. 回答1: Based on information I have found from the OpenXML SDK help files I have written the following code which should answer your question public class ExcelEngine : IExcelEngine { private readonly SpreadsheetDocument _wb; private WorkbookPart _wbp; private

Adding Date to Excel using Open XML [closed]

别来无恙 提交于 2019-12-10 17:17:23
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I would like to insert Date value to excel file using Open XML. Here is my code sample. cell.CellValue = new CellValue(value.ToString()); cell.DataType = new EnumValue<CellValues>(CellValues.Date); 回答1: