openxml

Find a specific Table (after a bookmark) in open xml

穿精又带淫゛_ 提交于 2019-12-07 16:25:18
问题 I have a document with multiple tables in it. I need to fill some of those tables. The problem im having is how do i locate them? I can interate through them var doc = document.MainDocumentPart.Document; var tables= doc.Body.Elements< Table >(); But how do i find a specific table? The table can change so i cant rely on the order. I was thinking of placing a bookmark ahead of the specific table and just locate the first table after the bookmark, but i have failed to find out how to do that...

Adding image to word document using OpenXML

时光总嘲笑我的痴心妄想 提交于 2019-12-07 13:42:49
问题 I developed an app that is supposed to add an image to a word document. It takes a copy from the word document and adds the picture to the copy. I tried to add text and it worked just fine but by adding images the word document wants to open a file, by giving an error (the file "name" cannot be opened because there are problems with the content.) My code looks like this : File.Copy(file, newFile, true); WordprocessingDocument wordFile = WordprocessingDocument.Open(newFile, true); Body body =

OpenXml - iterate through a paragraph's runs and find if a run has italic or bold text

牧云@^-^@ 提交于 2019-12-07 13:23:27
问题 I am trying to iterate through paragraph runs, find if a run has italized/bold text and replace that text with something else. Which is the best method in terms of performance. 回答1: If you are interested only in inline tags, the following code can help. Just change the Convert() method to whatever you want. using System.Linq; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; class Program { static void Main(string[] args) { using (var doc =

copying openXML image from one document to another

梦想与她 提交于 2019-12-07 13:11:23
问题 We have conditional Footers that INCLUDETEXT based on the client: IF $CLIENT = "CLIENT1" "{INCLUDETEXT "CLIENT1HEADER.DOCX"}" "" Depending on our document, there could be a varying amount of IF/ELSE , and these all work correctly for merging the correct files in the correct place. However, some of these documents may have client specific images/branding, which also need to be copied across from the INCLUDETEXT file. Below is the method that is called to replace any Picture elements that exist

How to insert text in to a word document from Rich Text Box

拈花ヽ惹草 提交于 2019-12-07 13:04:50
问题 I have a rich text box in my c# application and it contains different lines of text(one to many lines). I want to get those lines and insert it to a Word document with the font and the font size I want. This is how it should look like. OBSERVATIONS: Line 1 from the rich text box Line 2 from the rich text box Line 3 from the rich text box I want this to happen by using interop library. I need some sample code for this since I'm a newbie 回答1: You could use the OpenXML SDK Package: http://www

Why does OpenXML read rows twice

心不动则不痛 提交于 2019-12-07 12:53:18
问题 I count rows in two worksheets like this: foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts) { OpenXmlPartReader reader = new OpenXmlPartReader(worksheetPart); if (count == 0) { while (reader.Read()) { if (reader.ElementType == typeof(Row)) { count_first++; } } } else if (count == 1) { while (reader.Read()) { if (reader.ElementType == typeof(Row)) { count_second++; } } } count++; } For both worksheets in count_first and count_second I get twice as much as there are rows with

Adding multiple Cells to a single Row

瘦欲@ 提交于 2019-12-07 11:54:46
问题 I am new to this and when I try to add more than one cell to a row it says there is unreadable content. Here is what I have. SpreadsheetDocument ssDoc = SpreadsheetDocument.Create(saveFile, SpreadsheetDocumentType.Workbook); // Add a WorkbookPart to the document WorkbookPart workbookPart = ssDoc.AddWorkbookPart(); workbookPart.Workbook = new Workbook(); // Add a WorksheetPart to theWorkbookPart WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>(); worksheetPart.Worksheet =

Mocking OpenXML with Moq

这一生的挚爱 提交于 2019-12-07 09:53:37
How should I test the following GetWorksheetPart method: public class ExcelDocument : IExcelDocument { private readonly string _filePath; public ExcelDocument(string filePath) { _filePath = filePath; } public WorksheetPart GetWorksheetPart(ISpreadsheetDocument excelDoc, string sheetName) { Sheet sheet = excelDoc.GetSheet(sheetName); if (sheet == null) { throw new ArgumentException( String.Format("No sheet named {0} found in spreadsheet {1}", sheetName, _filePath), "sheetName"); } return excelDoc.GetPartById(sheet.Id); } } Where IExcelDocument and wrapper's SpreadsheetDocumentWrapper interfaces

Can EPPlus distinguish between blank cells and empty text cells in an Excel worksheet?

☆樱花仙子☆ 提交于 2019-12-07 07:25:11
问题 I'm using the EPPlus .NET library (v4.0.4) to interpret saved Excel workbooks. In one such worksheet, some empty cells have been set to 'text' format using the Excel 'apostrophe' trick (that is, the user has entered a single apostrophe in those cells, so that Excel will display them as blank). Sample XML for two such cells is as follows: <c r="F6" s="1" t="inlineStr"> <is> <t /> </is> </c> <c r="G6" s="1" /> Here, F6 has an apostrophe (i.e. is an empty text cell) and G6 is genuinely blank. Is

OpenXml: Convert an XElement to an OpenXmlElement

喜欢而已 提交于 2019-12-07 05:28:40
问题 How would I go about converting an XElement to an OpenXmlElement ? Either my google-fu fails or this has not been addressed. 回答1: You can convert a given OpenXmlElement to a XElement using the following code: OpenXmlElement el = ...; // Code to get the xml element from your office doc. // Then use XElement.Parse and the OuterXml property. XElement xel = XElement.Parse(el.OuterXml); To convert an XElement to an OpenXmlElement try the following code: XElement xe = ...; using(StreamWriter sw =