openxml-sdk

Open XML SDK: get “Unreadable content” error when trying to populate more than 25 columns

China☆狼群 提交于 2019-12-05 22:52:24
问题 I have created a spreadsheet using Open XML SDK in C#, and successfully populated two worksheets. When trying to populate a third, I get an "Unreadable content" error when opening the completed document, and it appears to occur when I attempt to populate more than 25 cells in a row on the third. I'm using the same code fragment as has worked successfully elsewhere in the document: string[] headers2 = { "Reference", "Raised", "Priority", "Affected", "Linked incidents", "Points", "SLA",

Excel add data to WorksheetPart in code behind

荒凉一梦 提交于 2019-12-05 22:47:21
问题 Hello guys I am creating an Excel file with 3 worksheets in the following code. using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Create(path + @"\UrlReport.xlsx", SpreadsheetDocumentType.Workbook)) { // create the workbook spreadSheet.AddWorkbookPart(); spreadSheet.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook(); // CREATE FIRST SHEET WorksheetPart newWorksheetPart1 = spreadSheet.WorkbookPart.AddNewPart<WorksheetPart>(); newWorksheetPart1.Worksheet = new

C# OpenXML (Word) Table AutoFit to Window

我怕爱的太早我们不能终老 提交于 2019-12-05 22:32:18
问题 Open a Word (2007/2010) document that has a table in it, select the table and right click, select AutoFit-->AutoFit to Window How can I implement this action in C# using the OpenXML SDK 2.5? 回答1: You can set the width of the table to 100% of the page, or 5000 fiftieths-of-a-percent. Table table = ... TableWidth width = table.GetDescendents<TableWidth>().First(); width.Width = "5000"; width.Type = TableWidthUnitValues.Pct; 来源: https://stackoverflow.com/questions/18025424/c-sharp-openxml-word

copying openXML image from one document to another

前提是你 提交于 2019-12-05 18:54:10
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 in the IEnumerable<Run> that is copied from the Source document to the Target document. The image is

OPEN XML add custom not visible data to paragraph/table

两盒软妹~` 提交于 2019-12-05 16:14:19
Is there a way to store additional data for a paragraph, that would be persisted after user opens and saves a document in MS Word. Ive been using CusotmXML for this, but it turns out that this is no logner possible due to the fact that MS-Word strips all CusotmXML elements from the document structure. Every single paragraph or a table has an ID that I would like to "pair back" to my data-source. So later when I read the docx again I can identify origins of every unchanged paragraph/table in the document. A possibility would be to insert a SET field. This creates a bookmark in the document to

Read only or Lock the particular cells or rows using open xml sdk

空扰寡人 提交于 2019-12-05 15:22:17
I am using open xml sdk to export excel. I get the excel file and copying that file to another place and then I'm inserting new rows with the data. I should make that rows as read only (or I've to lock) using open xml sdk.. How to do that ? Jeeva Jsb I've referred the following link Excel File Password Protection with Open XML SDK . Here I gave you full code to open the file from directory and insert cells. Here I've inserted only one cell. You can insert as you want. Here I've inserted locked cells. Find this one, it'll very helpful to you.. Note : Here I've mentioned the code only to read

OpenXml: Convert an XElement to an OpenXmlElement

感情迁移 提交于 2019-12-05 11:08:11
How would I go about converting an XElement to an OpenXmlElement ? Either my google-fu fails or this has not been addressed. 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 = new StreamWriter(new MemoryStream())) { sw.Write(xe.ToString()); sw.Flush(); sw.BaseStream.Seek(0, SeekOrigin

How to get all merge fields of word document using open xml sdk

旧街凉风 提交于 2019-12-05 10:24:33
I am beginner to open xml sdk. I am trying to find out all merge fields of document. But I am not getting the headers and footers merge fields. Can any one suggest a working solution? I am trying some thing like this - foreach (FieldCode field in docGenerated.MainDocumentPart.RootElement.Descendants<FieldCode>()) { String fieldText = field.Text; if (fieldText.StartsWith(" MERGEFIELD")) { Int32 endMerge = fieldText.IndexOf("\\"); Int32 fieldNameLength = fieldText.Length - endMerge; String fieldName = fieldText.Substring(11, endMerge - 11); fieldName = fieldName.Trim(); } } You have to loop

Save PowerPoint 2007 as PowerPoint 2003 using Open Office SDK 2.0

懵懂的女人 提交于 2019-12-05 09:26:46
Is there anyway to use the Open Office SDK 2.0 to save a PowerPoint presention that you created using OOXML to a PowerPoint 2003 presentation? I know if you open a 2007 file and click Save As you have the option to save it as a PowerPoint 97 to 2003 document and I didn't know if I could do this grammatically using this SDK. The reason I am asking this question is because I need to give the user the option to save data on a website in either Office 2007 or 2003 format. I much rather just use the same code to produce the document instead of having to have two code paths for PowerPoint 2003 and

How to use a gradient fill (GradientFill) with ClosedXML

若如初见. 提交于 2019-12-05 06:38:33
I'm working on a C#/ASP.NET web thing and want to do an Excel export. First I found OpenXML, made some first steps, but it's really hard to use. Now, I'm using ClosedXML and it's quite a relief - so far. I came up with the problem to have a gradient fill on a table cell ... no problem with normal fills like worksheet.Cell(1,1).Style.Fill.SetBackgroundColor(XLColor.Red); or with Patterns like worksheet.Cell(1,1).Style.Fill.PatternType = XLFillPatternValues.LightHorizontal; worksheet.Cell(1,1).Style.Fill.PatternColor = XLColor.Green; worksheet.Cell(1,1).Style.Fill.PatternBackgroundColor =