openxml-sdk

Using Excel sheet as a template vs. a "real" Excel template in OpenXML

Does anyone have any good answer what kind of difference there is between using some arbitrary pre-formatted Excel 2007 *.xlsx file as a template, loading it in my C# app, and filling up some of its cells with data using the Microsoft OpenXML SDK versus creating specific Excel templates (*.xltx) files and using those as basis for...

Can I set auto-width on an Open XML SDK-generated spreadsheet without calculating the individual widths?

I'm working on creating an Excel file from a large set of data by using the Open XML SDK. I've finally managed to get a functional Columns node, which specifies all of the columns which will actually be used in the file. There is a "BestFit" property that can be set to true, but this apparently does not do anything. Is there a way to aut...

How to insert a date to an Open XML worksheet?

I'm using Microsoft Open XML SDK 2 and I'm having a really hard time inserting a date into a cell. I can insert numbers without a problem by setting Cell.DataType = CellValues.Number, but when I do the same with a date (Cell.DataType = CellValues.Date) Excel 2010 crashes (2007 too). I tried setting the Cell.Text value to many date forma...

Create page break using OpenXml

I use OpenXml to create Word document with simple text and some tables under this text. How can I force Paragraph with this text to show always on new page? Maybe this paragraph should be some Header but I'm not sure how to do this. Thanks ...

How to omit xml declaration in WordML document.xml when working with bytes and MemoryStream ?

I have 2 snippets of code which work differently using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(@"D:\Tests\WordML\ML_Example.docx", WordprocessingDocumentType.Document)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); ...

Add Hyperlink to Cell in Excel 2007 Using Open XML SDK 2.0

I can't seem to find any documentation or code samples on how to add a hyperlink to a cell in Excel 2007 using the Open XML SDK 2.0. I am using the following code, but is there a step I am missing? WorksheetPart workSheetPart = ExcelUtilities.GetWorkSheetPart(mWorkBookPart, "Program"); workSheetPart.AddHyperlinkRelationship(new Uri("h...

Associating Worksheets with their Names using OpenXML SDK 1.0

I'm using version 1.0 of Microsoft's OpenXML SDK to do some basic parsing of .xlsx files. I can get and parse the worksheets, and I can get a list of worksheet names, but I cannot for the life of me figure out how to link up what name goes with what worksheet. I understand that an element like <sheet name="My Sheet" sheetId="1" r:id="r...

Is there an alternative to open-xml sdk to generate word documents

I'm trying to generate word documents using open xml sdk. When the documents are small this is no problem (and rather easy). When the documents become larger (+500 pages) I notice the peformance (duration, memory usage, ...) goes down significantly. Googling this problem I came across some posts that point out the same problem. For exce...

Word 2007: Duplicate a table with content control from one page to another

Hello, Is there a way to clone table with predefined style, fonts, content control etc. from one page to another page so that i can fill in different data in different tales. so for instance I wwould have, lets say, a table that shows Name, Age, Address of one person in one table. then the next page has the same table style but the inf...

Order of Header/FooterParts in OpenXML document

I need to retrieve Header/Footer parts from an OpenXML document in the order that they appear in the document. The following:- foreach (HeaderPart header in document.MainDocumentPart.HeaderParts) { ... } -appears to iterate through the HeaderParts in no particular order. Can anyone explain how to order these correctly? Either by u...

How can I protect an excel sheet, except for a particular cell using Open XML 2.0?

Hi, I am generating a report using OpenXML and exporting it to excel. I want to protect the excel sheet except for a particular cell. If anyone has worked on this before, kindly help Thanks, Amolik ...

How change excel 2007 document orientation to landscape by OpenXML sdk

Hi everyone! I need help with changing excel 2007 document orientation to landscape. I have not found any helpful information about this. I am using OpenXML SDK for this. The only thing I have found: when I create a new Worksheet I should set PageSetup() { Orientation = OrientationValue.Landscape}; But this doesn't help. Can anybody hel...

OpenXML: Replace <sdt/> element with table in WordprocessingML

I'm using the OpenXML SDK to programatically replace some <w:sdt/> elements with chunks of OpenXML (WordProcessingML) markup. For example, I have a paragraph with these contents: <w:p> <w:run><w:text> Text before </w:text></w:run> <w:sdt><w:sdtPr> ...</w:sdtPr><w:sdtContent>...</w:sdtContent></w:sdt> <w:run><w:text> Text after </...

Inject Open XML into an Open PowerPoint Presentation

I'm looking for a way to inject PresentationML and/or DrawingML into an open PowerPoint 2007/2010 presentation using the Open XML SDK or just System.IO.Packaging. There is an article on doing this with Word, but in that example it is using the Range.XML routine in Word's object model, which I cannot find an equivalant for in PowerPoint's...

OpenXml: Copy OpenXmlElement between documents

Hi, I have two Word documents (WordprocessingDocument), and I want to replace the contents of an element in the first with the contents in the body of the second one. This is what I'm doing right now: var docA = WordprocessingDocument.Open(docAPath, true); var docB = WordprocessingDocument.Open(docBPath, true); var containerElement =...

Replace bookmark text in Word file using Open XML SDK

I assume v2.0 is better... they have some nice "how to:..." examples but bookmarks don't seem to act as obviously as say a Table... a bookmark is defined by two XML elements BookmarkStart & BookmarkEnd. We have some templates with text in as bookmarks and we simply want to replace bookmarks with some other text... no weird formatting is ...

C# Open Xml SDK 2.0 Spreadsheet Setting Cell DateTime Format

Hey guys, I'm having trouble finding this one. my situation: SDK 2.0 no template spreadsheet C# 4.0 in VS2010 my problem: Certain data in the excel files I want to build exists in DateTime format. As I don't wan't to use just strings (stringed datetimes can't be sorted properly) I want to set the cells that contain DateTime to a fo...

Word documents generation with c#

Possible Duplicates: How can a Word document be created in C#? Convert Word doc file to docx on a server without Word Hi everyone ! Using your experiences, i wanna found the better sdk/library to create Word doc/docx, with or without .doc template, but without interop ! Thanks ! kiRbytte ...

Difference between Open and Create on DocumentFormat.OpenXml.Packaging.WordprocessingDocument

The docs for both methods read virtually identical to me. I have a template (.DOTX) which I want to open and make changes to, saving as .DOCX. What's the right approach? And, in fact, how do I save the document? I see no Save method... ...

Open XML SDK: opening a Word template and saving to a different file-name

This one very simple thing I can't find the right technique. What I want is to open a .dotx template, make some changes and save as the same name but .docx extension. I can save a WordprocessingDocument but only to the place it's loaded from. I've tried manually constructing a new document using the WordprocessingDocument with changes ma...