Coder Social home page Coder Social logo

open-xml-sdk's Introduction

Open XML SDK

Note

v3.0.0 refactors and addresses some technical debt while retaining source compatibility as much as possible. You should be able to update your package and recompile with limited changes. However, binary compatibility was not a goal and will break that for some changes which are documented. PRs that introduced such changes are marked with a breaking-change label and were added to a list to help migrating to v3.0.0.

Please see the v3.0.0 milestone for issues and PRs that are included. For discussions, please join us at this issue.

Important

The CI feed URL has changed as of 2 April, 2024. Please update to the new URL if using CI builds.

Downloads Build Status Backend Status

The Open XML SDK provides tools for working with Office Word, Excel, and PowerPoint documents. It supports scenarios such as:

  • High-performance generation of word-processing documents, spreadsheets, and presentations.
  • Document modification, such as adding, updating, and removing content and metadata.
  • Search and replace content using regular expressions.
  • Splitting up (shredding) a file into multiple files, and combining multiple files into a single file.
  • Updating cached data and embedded spreadsheets for charts in Word/PowerPoint.

Table of Contents

Packages

The official release NuGet packages for Open XML SDK are on NuGet.org:

Package Download Prerelease
DocumentFormat.OpenXml.Framework NuGet NuGet
DocumentFormat.OpenXml NuGet NuGet
DocumentFormat.OpenXml.Linq NuGet NuGet
DocumentFormat.OpenXml.Features NuGet NuGet

Daily Builds

The NuGet package for the latest builds of the Open XML SDK is available as a custom feed on an Azure blob. Stable releases here will be mirrored onto NuGet and will be identical. You must set up a NuGet.config file that looks similar to this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="OpenXmlCI" value="https://ooxml.blob.core.windows.net/feed/index.json" />
  </packageSources>
</configuration>

For latests changes, please see the changelog

Framework Support

The package currently supports the following targets:

  • .NET Framework 3.5, 4.0, 4.6
  • .NET Standard 2.0
  • .NET 6.0

For details on platform support, including other runtimes such as Mono and Unity, please see the docs at https://docs.microsoft.com/en-us/dotnet/standard/net-standard.

Known Issues

  • On .NET Core and .NET 5 and following, ZIP packages do not have a way to stream data. Thus, the working set can explode in certain situations. This is a known issue.
  • On .NET Framework, an IsolatedStorageException may be thrown under certain circumstances. This generally occurs when manipulating a large document in an environment with an AppDomain that does not have enough evidence. A sample with a workaround is available here.

Documentation

Please see Open XML SDK for the official documentation.

If you have how-to questions

Related tools

  • Open XML SDK 2.5 Productivity Tool: The Productivity Tool provides viewing and code generation compatible with the Open XML SDK 2.5.
  • Open XML Powertools: This provides example code and guidance for implementing a wide range of Open XML scenarios.
  • ClosedXml: This library provides a simplified object model on top of the OpenXml SDK for manipulating and creating Excel documents.
  • OfficeIMO: This library provides a simplified object model on top of the OpenXml SDK manipulating and creating Word documents.
  • Serialize.OpenXml.CodeGen: This is a tool that converts an OpenXml document into the .NET code required to create it.
  • Html2OpenXml: This is a tool that takes HTML and converts it to an OpenXml document.
  • DocxToSource: This is a tool designed to be a replacement for the old OpenXML SDK Productivity Tool.
  • OOXML Viewer: This is an extension for Visual Studio Code to View and Edit the xml parts of an Office Open XML file and to view a diff with the previous version of an OOXML part when saved from an outside program. Search "OOXML" in the VS Code extensions tab or download it from the VS Code Marketplace
  • ShapeCrawler: This library provides a simplified object model on top of the OpenXml SDK to manipulate PowerPoint documents.
  • OOXML Validator: VS Code extension to validate Office Open XML files. Search "OOXML" in the VS Code extensions tab or download it from the VS Code Marketplace

How can I contribute?

We welcome contributions! Many people all over the world have helped make this project better.

  • Contributing explains what kinds of contributions we welcome

Reporting security issues and security bugs

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) [email protected]. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

.NET Foundation

The Open XML SDK is a .NET Foundation project.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

License

The Open XML SDK is licensed under the MIT license.

open-xml-sdk's People

Contributors

aidilumarov avatar alfredhellstern avatar andrewdavidoff avatar asbjoedt avatar davidchesnut avatar dependabot[bot] avatar ericwhitedev avatar f1nzer avatar hotspurhn avatar igitur avatar josh-curry avatar jthake avatar lindexi avatar lklein53 avatar mikeebowen avatar nokafor avatar numpsy avatar o365devx avatar officecpub avatar rmboggs avatar rstm-sf avatar sorensenmatias avatar stevehansen avatar stoiveyp avatar thomasbarnekow avatar tomjebo avatar twsouthwick avatar vitaliypavlyukov avatar weswigham avatar will-gregg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

open-xml-sdk's Issues

Validator ignores elements removed from the spec

I've recently had Excel files that break the spec by including a "mergeCell" attribute in alignment elements. Such files should raise validation errors, certainly against the 2010 and 2013 formats but also against the 2007 as well. However this is currently not the case.

From [MS-OE376]:
2.1.720 Part 4 Section 3.8.1, alignment (Alignment)
a. The standard does not contain a @Mergecell attribute on the alignment element.
Excel allows @Mergecell to be written on the alignment element. @Mergecell is not used by Office and is not necessary for interoperability.
This note applies to the following products: 2007, 2007 SP1, 2007 SP2.

Breaking changes since v2.5?

We are currently using the binary release of Open XML SDK v2.5 in our organization and we want to use Open XML Power Tools. However, it seems that the power tools strictly require version 2.6 of the SDK, so we might have to upgrade it.

Are there any breaking changes that we should know of between 2.5 and 2.6? I'm afraid I can't figure out from the repo history where 2.5 ends and 2.6 starts and which are the changes.

Add support for sections in Wordprocessing namespace

I think it would be great to add the support of sections, it should be possible to:

  • identify a section as a class in the same way we can identify a Paragraph
  • get the paragraphs that compose the section
  • test if the section is a final section or not (as defined in the reference §17.6.17)
  • many other possibilities...

I'm ready to implement it if you think it's a good idea.

Opening read-only document on Mono 4.0.0 throws exception

I'm currently trying to use the Open XML SDK on the latest Mono release, i.e., 4.0.0. When creating a read-only instance of WordprocessingDocument, using WordprocessingDocument.Open(fileName, false), the following exception is thrown:

[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Operation not valid when package is read-only
  at System.IO.Packaging.Package.CheckIsReadOnly () [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.PackagePart.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id, Boolean loading) [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.PackagePart.LoadRelationships (System.Collections.Generic.Dictionary`2 relationships, System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.PackagePart.get_Relationships () [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.PackagePart.GetRelationships () [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.PackagePartRelationshipPropertyCollection..ctor (System.IO.Packaging.PackagePart packagePart) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart parent, System.Uri uriTarget, System.String id, System.Collections.Generic.Dictionary`2 loadedParts) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () [0x00000] in <filename unknown>:0 

This seems to be a bug in Mono (see http://lists.ximian.com/pipermail/mono-bugs/2011-February/109577.html). However, the question is whether there is a workaround on the level of the Open XML SDK.

Hyperlinks in word documents cause exception on mono

When I try to apply the simple paragraph adding test to a word docx file in mono http://msdn.microsoft.com/en-us/library/ee945362(v=office.11).aspx
I get the following exception (it works fine on windows with the current .NET runtime)

Unhandled Exception:
DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: Invalid Hyperlink: Malformed URI is embedded as a hyperlink in the document.
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () [0x00000] in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore (System.IO.Stream stream, Boolean readWriteMode) [0x00000] in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open (System.IO.Stream stream, Boolean isEditable, DocumentFormat.OpenXml.Packaging.OpenSettings openSettings) [0x00000] in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open (System.IO.Stream stream, Boolean isEditable) [0x00000] in <filename unknown>:0
  at DocumentModifier.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: Invalid
 Hyperlink: Malformed URI is embedded as a hyperlink in the document.
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () [0x00000] in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore (System.IO.Stream stream, Boolean read
WriteMode) [0x00000] in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open (System.IO.Stream stream, Boolean isEditable, DocumentFormat.OpenXml.Packaging.OpenSettings openSettings) [0x00000] in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open (System.IO.Stream stream, Boolean isEditable) [0x00000] in <filename unknown>:0
  at DocumentModifier.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

Not calculating

I have a spreadsheet with two tabs, named x and y. Using this SDK I can change the value of A1 in the tab x, and then read the value of A1 in the tab y. A1 in the tab y is set to =$x.A1, so changing A1 in the tab x should cause A1 in the tab y to change. But for some reason, A1 in the tab y remains set to whatever it was set to before I ran my code.

If I open the Excel spreadsheet after running my code, I see that A1 on tab x was changed by my code, but A2 on tab y has not been updated to reflect the change that my code made. Everything is just left in an inconsistent state. And if I manually change A1 on tab x, Excel will update A1 on tab y, so I know that my Excel file is working just fine.

The issue here is that the Open XML SDK isn't calculating A1 on tab y. How can I get the SDK to actually calculate the value of cells?

Ignoring the namespace leads to validation errors.

This affects the productivity tool. When the option Ignore XML Namespace is set, the productivity tool embeds the namespace in lots of tags even if it's already defined. This in turn leads the validator to declare these tags invalid because of the namespace declaration.

<styleSheet mc:Ignorable="x14ac" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
 <numFmts count="2">
  <numFmt formatCode="mm/dd/yyyy" numFmtId="164"/>
  <numFmt formatCode="#,##0.00;\-#,##0.00" numFmtId="165"/>


 </numFmts>
 <fonts x14ac:knownFonts="1" count="3">
  <font>
   <sz val="11" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <color rgb="FF000000" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <name val="Calibri" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <family val="2" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <charset val="1" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
  </font>
  <font>
   <b xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <sz val="8" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <color rgb="FF000000" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <name val="Arial" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <family val="2" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <charset val="1" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
  </font>
  <font>
   <sz val="8" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <color rgb="FF000000" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <name val="Arial" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <family val="2" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
   <charset val="1" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
  </font>
 </fonts>

This leads to error messages like The element has unexpected child element 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'

Test cases failing under circumstances to be determined

Depending on where tests are run (e.g., AppVeyor or certain other machines vs. my machine), either all tests pass or just a few tests fail.

This is the result I'm getting when running the tests in System.IO.Packaging.Tests.dll, using the build.open-xml-sdk.cmd build script:

xUnit.net console test runner (64-bit .NET 4.0.30319.34209)
Copyright (C) 2015 Outercurve Foundation.

Discovering: System.IO.Packaging.Tests
Discovered:  System.IO.Packaging.Tests
Starting:    System.IO.Packaging.Tests
   System.IO.Packaging.Tests.Tests.T170_InvalidRelationshipId [FAIL]
      Assert.Throws() Failure
      Expected: typeof(System.Xml.XmlException)
      Actual:   typeof(System.ArgumentNullException): Value cannot be null.
      Parameter name: format
      Stack Trace:
            at System.String.Format(String format, Object arg0)
         System.IO.Packaging\InternalRelationshipCollection.cs(188,0): at System.IO.Packaging.InternalRelationshipCollection.ThrowIfInvalidXsdId(String id)
         System.IO.Packaging\Package.cs(618,0): at System.IO.Packaging.Package.DeleteRelationship(String id)
Finished:    System.IO.Packaging.Tests

=== TEST EXECUTION SUMMARY ===
   System.IO.Packaging.Tests  Total: 122, Errors: 0, Failed: 1, Skipped: 0, Time: 2,307s

That same build script also runs the tests contained in the DocumentFormat.OpenXml.Tests.dll:

xUnit.net console test runner (64-bit .NET 4.0.30319.34209)
Copyright (C) 2015 Outercurve Foundation.

Discovering: DocumentFormat.OpenXml.Tests
Discovered:  DocumentFormat.OpenXml.Tests
Starting:    DocumentFormat.OpenXml.Tests
   DocumentFormat.OpenXml.Tests.XlsxTests01.X001_XlsxValidation [FAIL]
      Assert.Equal() Failure
      Expected: 2
      Actual:   20
      Stack Trace:
         DocumentFormat.OpenXml.Tests\TestXlsx01.cs(203,0): at DocumentFormat.OpenXml.Tests.XlsxTests01.XlsxValidationHelper(String docName, Int32 expectedErrorCount)
   DocumentFormat.OpenXml.Tests.XlsxTests01.X006_Xlsx_DeleteAdd_CoreExtendedProperties [FAIL]
      Assert.Equal() Failure
      Expected: 1
      Actual:   7
      Stack Trace:
         DocumentFormat.OpenXml.Tests\TestXlsx01.cs(82,0): at DocumentFormat.OpenXml.Tests.XlsxTests01.X006_Xlsx_DeleteAdd_CoreExtendedProperties()
   DocumentFormat.OpenXml.Tests.XlsxTests01.X007_SpreadsheetDocument_Open [FAIL]
      Assert.Equal() Failure
      Expected: 1
      Actual:   7
      Stack Trace:
         DocumentFormat.OpenXml.Tests\TestXlsx01.cs(53,0): at DocumentFormat.OpenXml.Tests.XlsxTests01.X007_SpreadsheetDocument_Open()
   DocumentFormat.OpenXml.Tests.XlsxTests01.X004_SpreadsheetDocument_Open [FAIL]
      Assert.Equal() Failure
      Expected: 1
      Actual:   7
      Stack Trace:
         DocumentFormat.OpenXml.Tests\TestXlsx01.cs(119,0): at DocumentFormat.OpenXml.Tests.XlsxTests01.X004_SpreadsheetDocument_Open()
   DocumentFormat.OpenXml.Tests.XlsxTests01.X008_XlsxCreation_Package_Settings [FAIL]
      Assert.Equal() Failure
      Expected: 1
      Actual:   7
      Stack Trace:
         DocumentFormat.OpenXml.Tests\TestXlsx01.cs(35,0): at DocumentFormat.OpenXml.Tests.XlsxTests01.X008_XlsxCreation_Package_Settings()
   DocumentFormat.OpenXml.Tests.XlsxTests01.X005_XlsxCreation_Package_Settings [FAIL]
      Assert.Equal() Failure
      Expected: 1
      Actual:   7
      Stack Trace:
         DocumentFormat.OpenXml.Tests\TestXlsx01.cs(101,0): at DocumentFormat.OpenXml.Tests.XlsxTests01.X005_XlsxCreation_Package_Settings()
Finished:    DocumentFormat.OpenXml.Tests

=== TEST EXECUTION SUMMARY ===
   DocumentFormat.OpenXml.Tests  Total: 82, Errors: 0, Failed: 6, Skipped: 0, Time: 23,101s

Thus, while all these tests pass on other machines, the above tests consistently fail on my machine.

In another situation that we are currently discussing in #48, validation of a workbook on my machine shows two validation errors while no errors are shown when @ron1010 performs the same validation.

@EricWhiteDev, we should look into this. Not sure whether that is related to differences in localization, for example. If you remember there's one fix I've done to the HtmlConverter in OxPt, explicitly using the neutral culture for converting numbers to strings (with decimal points rather than commas customary in certain countries).

Receive exception when accessing SharedStringTablePart from multiple threads simultaneously

I get this exception even when I open the file using read only attributes. So why couldn't multiple threads that have a read only view of the file open be able to read the SharedStringTable Part?

// Open System.IO.Packaging.Package.
            Package spreadsheetPackage = Package.Open(in_ss, FileMode.Open, FileAccess.Read);

            // Open a SpreadsheetDocument based on a package.
            SpreadsheetDocument document = SpreadsheetDocument.Open(spreadsheetPackage);
            workbookPart = document.WorkbookPart;

            SharedStringTablePart shareStringPart = null;
            if (workbookPart.GetPartsCountOfType<SharedStringTablePart>() > 0)
            {
                shareStringPart = workbookPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
            }

text = shareStringPart.SharedStringTable.ElementAt(
                            Convert.ToInt32(cell.CellValue.Text)).InnerText;

System.IO.InvalidDataException was unhandled by user code
HResult=-2146233087
Message=A local file header is corrupt.
Source=System.IO.Compression
StackTrace:
at System.IO.Compression.ZipArchiveEntry.ThrowIfNotOpenable(Boolean needToUncompress, Boolean needToLoadIntoMemory)
at System.IO.Compression.ZipArchiveEntry.OpenInReadMode(Boolean checkOpenable)
at System.IO.Compression.ZipArchiveEntry.Open()
at System.IO.Packaging.ZipStreamManager.Open(ZipArchiveEntry zipArchiveEntry, FileMode streamFileMode, FileAccess streamFileAccess)
at System.IO.Packaging.ZipPackagePart.GetStreamCore(FileMode streamFileMode, FileAccess streamFileAccess)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.GetStream(FileMode mode, FileAccess access)
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.LoadDomTreeT
at DocumentFormat.OpenXml.Packaging.SharedStringTablePart.get_SharedStringTable()
at SRPPEVL.Program.ReadExcelCell(Cell cell, SharedStringTablePart shareStringPart) in c:\users\ramiller\documents\visual studio 2015\Projects\SRPPEVL\SRPPEVL\Program.cs:line 117

Validation

First of all: for me the most important things is that Office itself can open the files; even if files are 100% valid to the specs, if Word cannot open them, my users complain. If it's not valid, but Word is fine with it, so are my users (and so am I :)).

Therefore, in my case the validation logic should only judge things as an error if Word cannot handle it as well. Otherwise it should treat the issue as a warning.

My issues:

  1. Validation complains a lot about attributes on tables. Word does not.
  2. Validation does NOT complain about a table cell without contents. Word does!
  3. Validation does NOT complain about a faulty footer (which contains a textbox), Word does!
  4. The constructor of the validator requires me to specify against which fileformat (2007/2010/2013) to validate. How can I determine the file format of an existing document? If that's possible, why doesn't the default constructor of the validator do so, instead of defaulting to 2007?

For nr 3 I have two sample files. The first is the 'broken' one where validation does not complain. The second one is the same file, but now corrected by Word 2013.
https://dl.dropboxusercontent.com/u/2496004/OoxmlSdk/BrokenFooter.docx
https://dl.dropboxusercontent.com/u/2496004/OoxmlSdk/BrokenFooter%20-%20Fixed%20By%20Word.docx

Personally I cannot see what exactly Word fixed for the footer. The XML is just slightly different. Although I use the OOXML SDK for file manipulation, I process the XML contents using xslt and then write back the resulting XML. Can this be the cause? (I doubt it, since process all document parts this way)

Regards,
Robert te Kaat | www.docati.com

ZipArchive.CreateEntry not found.

I'm working on a simple app to merge presentations based on the PresentationBuilder example in Open-Xml-PowerTools . I have it working fine in Windows but when I push it to my Linux box, compile it in Mono it throws a "System.MissingMethodException: Method 'ZipArchive.CreateEntry' not found." error. Any idea what is going on?

Unhandled Exception:
System.MissingMethodException: Method 'ZipArchive.CreateEntry' not found.
  at System.IO.Packaging.ZipPackage.Dispose (Boolean disposing) <0x415c39c0 + 0x00043> in <filename unknown>:0
  at System.IO.Packaging.Package.System.IDisposable.Dispose () <0x415c2780 + 0x001bb> in <filename unknown>:0
  at OpenXmlPowerTools.OpenXmlPowerToolsDocument.GetDocumentType (System.Byte[] bytes) <0x41590d60 + 0x00518> in <filename unknown>:0
  at OpenXmlPowerTools.OpenXmlPowerToolsDocument.GetDocumentType () <0x41590d30 + 0x0001b> in <filename unknown>:0
  at OpenXmlPowerTools.PmlDocument..ctor (System.String fileName) <0x41590b80 + 0x0002c> in <filename unknown>:0
  at MergePresentatons01.MergePresentatons01.Main (System.String[] args) <0x4158cd70 + 0x006c0> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method 'ZipArchive.CreateEntry' not found.
  at System.IO.Packaging.ZipPackage.Dispose (Boolean disposing) <0x415c39c0 + 0x00043> in <filename unknown>:0
  at System.IO.Packaging.Package.System.IDisposable.Dispose () <0x415c2780 + 0x001bb> in <filename unknown>:0
  at OpenXmlPowerTools.OpenXmlPowerToolsDocument.GetDocumentType (System.Byte[] bytes) <0x41590d60 + 0x00518> in <filename unknown>:0
  at OpenXmlPowerTools.OpenXmlPowerToolsDocument.GetDocumentType () <0x41590d30 + 0x0001b> in <filename unknown>:0
  at OpenXmlPowerTools.PmlDocument..ctor (System.String fileName) <0x41590b80 + 0x0002c> in <filename unknown>:0
  at MergePresentatons01.MergePresentatons01.Main (System.String[] args) <0x4158cd70 + 0x006c0> in <filename unknown>:0

Missing .sln / .csproj

Thanks for open sourcing the SDK.
The first thing I noticed is that the source consists only of .cs files and the makefile - which is great because I can build it via Powershell, but it is a bit uncommon without the typical .sln/.csproj file, so it is hard to open and edit it in VS.

Do I miss something or is this "by design"?

ExtendedFilePropertiesPart.Properties.Pages.Text returns incorrect value

I am using the following code to open WordprocessingDocument from MemoryStream and then get the page size of the document, but it always returns the value 1, which is incorrect as the document contains 11 pages.

using (WordprocessingDocument myDoc = WordprocessingDocument.Open(reportDocumentStream, false))
{
    pages = int.Parse(myDoc.ExtendedFilePropertiesPart.Properties.Pages.Text);
}

Generated xml namespace for xmlMaps.xml

Hi,

I try to add an XmlMapping part in an Excel file butI've got an issue.

I use CustomXmlMappingsPart and MapInfo Objects and the generated file is fine. But when I open Excel file the XML Mapping window is empty.

I compare a file created with Excel and mine created by code and the difference is in xmlMaps.xml file.

The file created by Excel starts with this lines :
<MapInfo xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" SelectionNamespaces=""> <Schema ID="Schema1">

and the file created by code :
<?xml version="1.0" encoding="utf-8"?> <x:MapInfo SelectionNamespaces="" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <x:Schema ID="Schema1">

The main difference is the namespace prefix.

If I remove this prefix and repackages Excel file, it works.

Why this prefix is used and how to remove it ?

Thanks,

Validator incorrectly reports MaxExclusive contraint errors

Not sure whether this is part of the project or not. The validator in the Productivity Tool routinely reports pageMargin attributes as errors "t has an invalid value of '0.75'. The MaxExclusive constraint failed. The value must be less than 49"

Is this just a Code-Drop?

I'm just wondering what is the current roadmap of this GitHub Repo here? Is this just a "code-drop" and you guys have your own version + tests or should this be more like a real OSS project?

Now I can build this stuff, but I can't open the sln file and there are no tests.

Of course I could fork it etc, but if you have a OpenXML SDK 3.0 in the pipeline and push this to GitHub this would be obsolete.

Maybe you could share some insights - thanks!

Open XML SDK Documentation and Samples

work with open xml sdk not easy and not enough documentation in internet.
we needs more documentation and samples for new features and advanced capabilities.

Makefile-Linux-Mono is missing

Makefile-Linux-Mono is missing from the repository. In order to build on mono, I had to find a copy in the revision history, paste it into a text file manually, and then use it to build.

Use Open-XML-SDK in Windows Phone 8 project

hi!.,

it would be possible to use Open-XML-SDK in WindowsPhone8??.
I can reference DocumentFormat.OpenXml.dll but WP8 doesn't support the WindowsBase.dll reference.,

Thanks in advance!.

WordprocessingML PageMargin attributes' type not compliant

I noticed that we use Int32 and UInt32 to store page margin values (left, top, right, bottom). However, the spec (§22.9.2.14 ST_TwipsMeasure) specifies that the type of the value depends on the value itself. It can be an integer or a decimal value with a unit specifier.
The result is there are some documents that can't be properly red, like those generated by Google Docs, because it uses decimal values for page margins.

Add snk file to System.IO.Packaging,DocumentFormat.OpenXml and PowerTools .Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

Hi,

I have add latest OpenXml SDK (2.6) and PowerTools 4.0 in my project.I have added snk file to my project.I got Unable to emit assembly error.So i try to add snk file for System.IO.Packaging,DocumentFormat.OpenXml and PowerTools . For System.IO.Packaging there is no problem.But For DocumentFormat.OpenXml,After adding snk file i got below error.

Friend assembly reference 'SdbBuilder' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

Friend assembly reference 'ofapiTest' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

File name is (ofapi.cs)

How to solve above error.

How to add snk file to all 3 projects.I need dll with stong named type project.
Please help me to resolve the issue.

AddPart() throws Exception on Mono 4.0.0

In one of my pull requests, I developed a Clone() method that clones OpenXmlPackage instances. For that purpose, it adds OpenXmlPart instances to the clone, using AddPart(T, string).

While this has worked nicely in production on Windows 7, doing the same using Mono 4.0.0 on Mac OS X Yosemite throws an exception:

[ERROR] FATAL UNHANDLED EXCEPTION: System.Xml.XmlException: Document element did not appear.  Line 1, position 1.
  at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0 
  at Mono.Xml.EntityResolvingXmlReader.Read () [0x00000] in <filename unknown>:0 
  at Mono.Xml.DTDValidatingReader.ReadContent () [0x00000] in <filename unknown>:0 
  at Mono.Xml.DTDValidatingReader.Read () [0x00000] in <filename unknown>:0 
  at Mono.Xml.Schema.XsdValidatingReader.Read () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlValidatingReader.Read () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.Load (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.Load (System.IO.Stream inStream) [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.Package.LoadRelationships () [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.Package.get_Relationships () [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.Package.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id, Boolean loading) [0x00000] in <filename unknown>:0 
  at System.IO.Packaging.Package.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AttachChild (DocumentFormat.OpenXml.Packaging.OpenXmlPart part, System.String rId) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddSubPartFromOtherPackage (DocumentFormat.OpenXml.Packaging.OpenXmlPart part, IDictionary`2 partDictionary, IDictionary`2 dataPartsDictionary, Boolean keepIdAndUri, System.String rId) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddSubPartFromOtherPackage (DocumentFormat.OpenXml.Packaging.OpenXmlPart part, Boolean keepIdAndUri, System.String rId) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddSubPart (DocumentFormat.OpenXml.Packaging.OpenXmlPart part, System.String rId) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.SetSubPart (DocumentFormat.OpenXml.Packaging.OpenXmlPart part, System.String rId) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddPartFrom (DocumentFormat.OpenXml.Packaging.OpenXmlPart subPart, System.String rId) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddPart[OpenXmlPart] (DocumentFormat.OpenXml.Packaging.OpenXmlPart part, System.String id) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Clone (System.IO.Stream stream, Boolean isEditable, DocumentFormat.OpenXml.Packaging.OpenSettings openSettings) [0x00000] in <filename unknown>:0 
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Clone () [0x00000] in <filename unknown>:0 

As with the other issue related to opening a read-only WordprocessingDocument instance, this might be a Mono bug (and the exception message might not even be helpful). It also involves System.IO.Packaging.Package.get_Relationships and related methods.

The same questions arise: To what extent has the Open XML SDK been tested on Mono? Is there any workaround on the level of the Open XML SDK?

Request to change .xlsx file content to match standard Excel

This is a request to change the Microsoft Open XML SDK to product .xlsx files that match Excel for Android, the OneDrive version of Excel, and Excel for Windows (Excel 2010 is the version that I tested).

Microsoft Excel for Android, the OneDrive version of Excel, and Excel for Windows (Excel 2010) all produce .xlsx files that contain a docProps folder and a _rels/.rels file whose xml content does not include a leading slash before the xl/workbook.xml reference.

The SDK, however, produces .xlsx files that do not contain the docProps folder and the _rels/.rels file includes a leading slash before the xl/workbook.xml reference (i.e., "/xl/workbook.xml").

This discrepancy with the SDK results appears to cause other utilities, such as Google Sheets, to view files produced using the SDK as outdated.

Build using Powershell-Script fails

Building using the Powershell-script BldSdk.ps1 fails on my system with Nmake error u1095 (expanded command line too long).
System: Windows Server 2008 R2, Visual Studio Express 2012 for Windows Desktop

Cannot read content-types.xml with a qualified namespace

The productivity tool cannot read files if the a qualified namespace as opposed the default namespace is used. The XML itself is valid with the default namespace just being a special case. Unfortunately, this error means you use the tool with any files where this has been done. The error message is "Cannot open the file: the required Types-Element could not be found".

<?xml version="1.0"?>
<ns0:Types xmlns:ns0="http://schemas.openxmlformats.org/package/2006/content-types">
  <ns0:Override ContentType="application/vnd.openxmlformats-officedocument.theme+xml" PartName="/xl/theme/theme1.xml"/>
  <ns0:Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" PartName="/xl/styles.xml"/>
  <ns0:Default ContentType="application/vnd.openxmlformats-package.relationships+xml" Extension="rels"/>
  <ns0:Default ContentType="application/xml" Extension="xml"/>
  <ns0:Default ContentType="image/png" Extension="png"/>
  <ns0:Default ContentType="application/vnd.openxmlformats-officedocument.vmlDrawing" Extension="vml"/>
  <ns0:Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" PartName="/xl/workbook.xml"/>
  <ns0:Override ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" PartName="/docProps/app.xml"/>
  <ns0:Override ContentType="application/vnd.openxmlformats-package.core-properties+xml" PartName="/docProps/core.xml"/>
  <ns0:Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml" PartName="/xl/sharedStrings.xml"/>
  <ns0:Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet1.xml"/>
</ns0:Types>

Validator reports constraint exceeded for gradientFill stop

The validator reports an error for the following style definition:

  <x:fill>
    <x:gradientFill type="linear" degree="90">
      <x:stop position="0">
        <x:color theme="0" />
      </x:stop>
      <x:stop position="1">
        <x:color theme="4" />
      </x:stop>
      <x:stop position="2">
        <x:color rgb="00FF0000" />
      </x:stop>
    </x:gradientFill>
  </x:fill>

I can't find the matching constraint. This is specification for a gradientFill:

<xsd:complexType name="CT_GradientFill">
    <xsd:sequence>
       <xsd:element name="stop" type="CT_GradientStop" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="type" type="ST_GradientType" use="optional" default="linear"/>
    <xsd:attribute name="degree" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="left" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="right" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="top" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="bottom" type="xsd:double" use="optional" default="0"/>
</xsd:complexType>
<xsd:complexType name="CT_GradientStop">
    <xsd:sequence>
       <xsd:element name="color" type="CT_Color" minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
    <xsd:attribute name="position" type="xsd:double" use="required"/>
</xsd:complexType>

If I understand this correctly then there can be an unlimited number of stops. Any limits could be imposed using the maxOccurs attribute of the fill.

[OSX/MONO] 'The entry is already currently open for writing' errors when running tests

When trying to run the unit test of OSX/Mono 4.3.3, I get some test failures along the lines of

DocumentFormat.OpenXml.Tests.OpenXmlPackageTest.PackageValidateTest [FAIL]
      System.IO.IOException : The entry is already currently open for writing.
      Stack Trace:
           at System.IO.Compression.ZipArchiveEntry.Open () <0x11475a8f0 + 0x00155> in <filename unknown>:0 
           at System.IO.Packaging.ZipStreamManager.Open (System.IO.Compression.ZipArchiveEntry zipArchiveEntry, FileMode streamFileMode, FileAccess streamFileAccess) <0x11475a660 + 0x00113> in <filename unknown>:0 
           at System.IO.Packaging.ZipPackagePart.GetStreamCore (FileMode streamFileMode, FileAccess streamFileAccess) <0x11475a430 + 0x00057> in <filename unknown>:0

Which look to be down to calling zipStreamManager.Open twice in ZipPackagePart.GetStreamCore() (https://github.com/OfficeDev/Open-XML-SDK/blob/vNext/System.IO.Packaging/ZipPackagePart.cs#L50).

Not sure if there is a Mono issue here with something not being closed, but besides that, is it actually necessary to open the stream twice here?

Repeated Header and footer count

Acutally i need to get the characters count in docx(including header and footer).
but open xml sdk is not giving header and footer part count.
now i have read the header and footer text. but I would like to know the number of time the header and footer text used in docx. so that i can multiply and get the correct count of header and footer text

Operation is not supported.

Hi,

Below is the inner exception, seems Mono's DeflateStream not support something.

  at System.IO.Compression.DeflateStream.get_Length () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr5/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.5/mcs/class/System/System.IO.Compression/DeflateStream.cs:297 
  at System.IO.Packaging.ZipWrappingStream.get_Length () [0x0004e] in <filename unknown>:0 
  at OpenXmlPowerTools.PtOpenXmlExtensions.GetXDocument (DocumentFormat.OpenXml.Packaging.OpenXmlPart part) [0x0001f] in /Users/Edison/Developer/Source/dotnet/open-xml-powertools/OpenXmlPowerTools/PtOpenXmlUtil.cs:54 

Cheers,

Edison

Building under Linux

Hi, having trouble with building the SDK on Linux. This is what I get:

./src/Framework/PartContainer.cs(2455,1): warning CS1587: XML comment is not placed on a valid language element
./src/ofapi/Validation/DocumentValidator.cs(131,15): warning CS1587: XML comment is not placed on a valid language element
./src/ofapi/Validation/SchemaValidation/BinDataTypes.cs(14,9): warning CS1587: XML comment is not placed on a valid language element
./src/ofapi/Validation/SchemaValidation/ParticleValidator.cs(860,1): warning CS1587: XML comment is not placed on a valid language element
./src/Framework/OpenXmlBasePart.cs(456,47): error CS0103: The name DtdProcessing' does not exist in the current context ./src/Framework/OpenXmlBasePart.cs(456,31): error CS1061: TypeSystem.Xml.XmlReaderSettings' does not contain a definition for DtdProcessing' and no extension methodDtdProcessing' of type System.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?) /usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error) ./src/Framework/OpenXmlElement.cs(2069,78): error CS0103: The nameDtdProcessing' does not exist in the current context
./src/Framework/OpenXmlElement.cs(2069,62): error CS1061: Type System.Xml.XmlReaderSettings' does not contain a definition forDtdProcessing' and no extension method DtdProcessing' of typeSystem.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?)
/usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error)
./src/Framework/OpenXmlElement.cs(2087,78): error CS0103: The name DtdProcessing' does not exist in the current context ./src/Framework/OpenXmlElement.cs(2087,62): error CS1061: TypeSystem.Xml.XmlReaderSettings' does not contain a definition for DtdProcessing' and no extension methodDtdProcessing' of type System.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?) /usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error) ./src/Framework/OpenXmlElementContext.cs(174,47): error CS0103: The nameDtdProcessing' does not exist in the current context
./src/Framework/OpenXmlElementContext.cs(174,31): error CS1061: Type System.Xml.XmlReaderSettings' does not contain a definition forDtdProcessing' and no extension method DtdProcessing' of typeSystem.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?)
/usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error)
./src/Framework/OpenXmlNonElementNode.cs(75,42): error CS0103: The name DtdProcessing' does not exist in the current context ./src/Framework/OpenXmlNonElementNode.cs(75,26): error CS1061: TypeSystem.Xml.XmlReaderSettings' does not contain a definition for DtdProcessing' and no extension methodDtdProcessing' of type System.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?) /usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error) ./src/Framework/OpenXmlNonElementNode.cs(149,54): error CS0103: The nameDtdProcessing' does not exist in the current context
./src/Framework/OpenXmlNonElementNode.cs(149,38): error CS1061: Type System.Xml.XmlReaderSettings' does not contain a definition forDtdProcessing' and no extension method DtdProcessing' of typeSystem.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?)
/usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error)
./src/Framework/OpenXmlPartRootElement.cs(134,74): error CS0103: The name DtdProcessing' does not exist in the current context ./src/Framework/OpenXmlPartRootElement.cs(134,58): error CS1061: TypeSystem.Xml.XmlReaderSettings' does not contain a definition for DtdProcessing' and no extension methodDtdProcessing' of type System.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?) /usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error) ./src/Framework/OpenXmlReader.cs(1640,63): error CS0103: The nameDtdProcessing' does not exist in the current context
./src/Framework/OpenXmlReader.cs(1640,47): error CS1061: Type System.Xml.XmlReaderSettings' does not contain a definition forDtdProcessing' and no extension method DtdProcessing' of typeSystem.Xml.XmlReaderSettings' could be found (are you missing a using directive or an assembly reference?)
/usr/lib/mono/2.0/System.Xml.dll (Location of the symbol related to previous error)
./src/ofapi/Validation/SchemaValidation/SimpleTypes.cs(233,13): warning CS0162: Unreachable code detected
Compilation failed: 16 error(s), 5 warnings
make: *** [build/OpenXmlSdkLib/OpenXMLLib.dll] Error 1
donofer@vpn:/git/Open-XML-SDK$ mono -V
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-8)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
donofer@vpn:
/git/Open-XML-SDK$ uname -a
Linux vpn 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2 x86_64 GNU/Linux
donofer@vpn:~/git/Open-XML-SDK$

Any ideas?

Incorrect Charactes count

Both the below
ExtendedFilePropertiesPart.Properties.Characters.InnerText and
ExtendedFilePropertiesPart.Properties.Characterswithspace.InnerText and
returns wrong values

Sample app generates corrupt .docx with bad date-time in the docProps/core.xml on mono (on .NET the same code generates a validating doc, but with wrong timestamps)

Running any sample app (eg http://msdn.microsoft.com/en-us/library/ee945362(v=office.11).aspx )
in mono-3.4 yields a corrupt document that word refuses to open.
Doing a diff with a document generated by the same code in windows yields a difference:

(newlines added for readability)
Failing mono-3.4 version of docProps/core.xml

<?xml version="1.0" encoding="UTF-8"?><coreProperties xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties">
<dcterms:created>4/20/2014 6:54:00 PM</dcterms:created>
<dc:creator>Timmy Johnson</dc:creator>
<lastModifiedBy>Timmy Johnson</lastModifiedBy>
<revision>4</revision>
<dcterms:modified xsi:type="dcterms:W3CDTF">4/22/2014 4:53:00 PM</dcterms:modified></coreProperties>

Working .NET 4.5 version of docProps/core.xml

<?xml version="1.0" encoding="UTF-8"?><coreProperties xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties">
<dcterms:created xsi:type="dcterms:W3CDTF">2014-04-21T01:54:00.00Z</dcterms:created>
<dc:creator>Timmy Johnson</dc:creator>
<lastModifiedBy>Timmy Johnson</lastModifiedBy>
<revision>4</revision>
<dcterms:modified xsi:type="dcterms:W3CDTF">2014-04-21T01:54:00.00Z</dcterms:modified></coreProperties>

Specifically the timestamp xsi:type is not properly added to dcterms:created
and the date time is not a proper W3CDTF format in mono, instead being a different date format.

Markup Compatibility Extensibility (MCE) doesn't work properly in 2.5

If you set FileFormatVersion.Office2010, then it correctly picks the 'Choice' element of an AlternateContent block for an inline text box. If you set FileFormatVersion.Office2013, then it incorrectly picks the Fallback element of an AC block.

openSettings = new OpenSettings();
openSettings.MarkupCompatibilityProcessSettings =
    new MarkupCompatibilityProcessSettings(
        MarkupCompatibilityProcessMode.ProcessAllParts,
        FileFormatVersions.Office2010);
using (var wDoc = WordprocessingDocument.Open(outFile.FullName, true, openSettings))

We should investigate other AlternateContent blocks, and see if this same behavior is there. I suspect that it is. I believe that the fix is where we change the code to take the Choice block if the setting version is equal to or greater than the implementation version for the Choice block. Right now it appears that it takes the choice only if the version specified for MarkupCompatibilityProcessSettings is equal to the implementation version for the Choice block.

We should consider carefully how to fix this – we should have at least a point release (v2.6) to fix these types of bugs, because they could possibly cause different behavior in existing programs.

.NET Core Support

I just tried the .NET Portability Analyzer on the current and the vNext branch and it seems there are only a few code parts that needs to be changed to run it on .NET Core:

image

Have you any plans to support it?

Is your System.IO.Packaging the same code as in the CoreFX (which would run under .NET Core) repository or is this something "OpenXml" specific? https://github.com/dotnet/corefx/tree/master/src/System.IO.Packaging

Malformed mailto Hyperlink causes Exception on .NET 4.5+

Hi,

This issue is similar to #7 but for recent versions of the .NET framework.

If you create a blank document and set some text to the following field code (note the extra space):
{ HYPERLINK "mailto:email@address%20.com" }

Running the following on .NET 4.0 will work fine:
var wpdoc = WordprocessingDocument.Open(@"TestDoc.docx", false)
Running the same line on .NET 4.5+ will throw the following exception:

DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: Invalid Hyperlink: Malformed URI is embedded as a hyperlink in the document.
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load() in OpenXmlPackage.cs: line 490
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode) in OpenXmlPackage.cs: line 402
   at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(String path, Boolean isEditable, OpenSettings openSettings) in PackageDocument.cs: line 297
   at  DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(String path, Boolean isEditable) in PackageDocument.cs: line 256

The inner-exception being this:

   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString, UriKind uriKind)
   at MS.Internal.IO.Packaging.InternalRelationshipCollection.ProcessRelationshipAttributes(XmlCompatibilityReader reader)
   at MS.Internal.IO.Packaging.InternalRelationshipCollection.ParseRelationshipPart(PackagePart part)
   at MS.Internal.IO.Packaging.InternalRelationshipCollection..ctor(Package package, PackagePart part)
   at System.IO.Packaging.PackagePart.EnsureRelationships()
   at System.IO.Packaging.PackagePart.GetRelationshipsHelper(String filterString)
   at System.IO.Packaging.PackagePart.GetRelationships()
   at DocumentFormat.OpenXml.Packaging.PackagePartRelationshipPropertyCollection..ctor(PackagePart packagePart)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load(OpenXmlPackage openXmlPackage, OpenXmlPart parent, Uri uriTarget, String id, Dictionary`2 loadedParts)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships(OpenXmlPackage openXmlPackage, OpenXmlPart sourcePart, RelationshipCollection relationshipCollection, Dictionary`2 loadedParts)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load()

I assume this is due to the following change introduced in .Net 4.5 (https://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx):
An invalid mailto: URL throws an exception in the Uri class constructor.

Word seems to be perfectly happy with the malformed mailto hyperlink so I assume this would count as a valid document.
I am therefore not sure how this could be fixed elegantly.

Thanks,

DocumentFormat.OpenXml.Spreadsheet.Map boolean conversion

Hi,

I try to use DocumentFormat.OpenXml.Spreadsheet.Map in CustomXmlMappingsPart but generated attributes values for booleans is not interpreted by Excel.

With OpenXml SDK :
<Map ID="1" Name="Root_Map" RootElement="Root" SchemaID="Schema1" ShowImportExportValidationErrors="1" AutoFit="1" Append="0" PreserveSortAFLayout="1" PreserveFormat="1" />

With Excel :
<Map ID="1" Name="Root_Map" RootElement="Root" SchemaID="Schema1" ShowImportExportValidationErrors="true" AutoFit="true" Append="false" PreserveSortAFLayout="true" PreserveFormat="true" />

Why this difference ?

Thanks

[OSX] test failures due to hard coded path separators?

I just tried to run some document handling code that i'm trying to port from Windows to OS X/Mono using the latest SDK/system.io.packaging, and some some errors that seem to be down to zip handling.
I thought i'd give the units test a go to see what those do, and got rather a lot of failures.

However, looking at the output, a load of those look as though they could be down to hard coded path separators in the tests.

e,g,

DocumentFormat.OpenXml.Tests.DocumentTraverseTest.TraverseWordDocument [FAIL]
System.IO.DirectoryNotFoundException : Directory '/Users/rwebb/Documents/gitrepos/Open-XML-SDK/TestDataStorage/v2FxTestFiles/wordprocessing\paragraph' not found.

I'm guessing that the paths in /DocumentFormat.OpenXml.Tests/OpenXmlDomTest/OpenXmlCompositeElementTestClass.cs should be using the system path separator char instead of hardcoding things like @"presentation\smallset" ?

Can't correlate github howto with files in release

Github says : "In your program that uses the Open XML SDK, add references to the newly built libraries in build/OpenXmlSdkLib/Debug"
Don't see that. After running the build cmd, I have dll files in:

Open-XML-SDK\DocumentFormat.OpenXml\bin\release

and

Open-XML-SDK\DocumentFormat.OpenXml.WB\bin\release

and no explanation as to what "WB" means

MathML objects manipulation

Hello there,

I am currently trying to convert an html file containing mathml to docx, using a library called JavaDocx. I am having issues though because the converted mathml, which originally is inlined with the html, in the docx document gets placed into a paragraph of its own.

Therefore, I was looking for a library allowing me to place a mathml object wherever in the page (without the surrounding paragraph). Could your library be of any help in this regard?

Thanks
Matteo

t1 Theme color is not present under ClrScheme

In ClrSchemeMapping , it is defined as
t1 (Text 1 ThemeColor Mapping)
Specifies the theme color in the document's theme part which shall be used in place of this color when it is referenced by document content.
If this attribute is omitted, then the t1 theme color shall be used.
[Example: Consider a WordprocessingML document that must have references to the theme color t1 mapped to the theme color lt1 as defined in the document's theme part.
This requirement would be specified using the following WordprocessingML in the
document settings:
<w:clrSchemeMapping w:t1="light1" />
The t1 attribute has a value of light1, specifying that uses of the theme color value t1must be mapped to the theme color lt1. end example]
The possible values for this attribute are defined by the ST_WmlColorSchemeIndex
simple type (§17.18.103).

It is said that if this mapping is not present, we can use the default as t1 theme color.
But when I look into the ClrScheme, there is no theme color which is defined by the name “t1”.
Following are the possible element names for the ClrScheme
Sequence Index Element (Color) Name
0 dk1 (Dark 1)
1 lt1 (Light 1)
2 dk2 (Dark 2)
3 lt2 (Light 2)
4 accent1 (Accent 1)
5 accent2 (Accent 2)
6 accent3 (Accent 3)
7 accent4 (Accent 4)
8 accent5 (Accent 5)
9 accent6 (Accent 6)
10 hlink (Hyperlink)
11 folHlink (Followed Hyperlink)

So I wanted to understand is it a miss in the spec or am I understanding it wrongly.

Error Validating Open XML document with signed version of Open XML SDK

Is it possible to sign the Open XML SDK?

I am having trouble with Validating an Open XML Document with a signed version of the Open XML Sdk. I need to sign my code which in turn requires DLLs it uses to be signed. I added the SNK files to the Open XML SDK projects and added "PublicKey" to ofapi.cs. I can open documents and manipulate them, but when i go the validate them, i get the exception below.

image

Has anyone else had issues with this?

Ron.

DocumentBuilder merging styles from MS Word documents created with different language settings.

When attempted to merge a document created in a Dutch office version with a document created in a English office version the resulting document ends up with default styles from both documents inside styles.xml.

For example

<w:style w:styleId="Normal" w:default="1" w:type="paragraph">
<w:style w:styleId="Standaard" w:default="1" w:type="paragraph">

This opens perfectly fine in MS Word 2010 and MS Word 2013. It seems only the Word Online Editor doesn't accept it (preview still looks fine)

This happens because the styleId names are not matching (because Microsoft decided to localize them i guess...)

Can't open file: Absolute URIs are not supported

I'm running OpenXMLSDK(2.5.0) on Mac OS 10.11.2 (EI Capitan) with Mono 4.2.1 .
When I'm trying to open a Docx file, I got this exception:
targetUri Parameter name: Absolute URIs are not supported

My code is below:

public static void Main (string[] args)
{
    Console.WriteLine ("Hello World!");
    using (WordprocessingDocument doc = WordprocessingDocument.Open ("/tmp/test_open.docx", true)) 
    {
          MainDocumentPart mainPart = doc.MainDocumentPart;
    }
}

Error stack:

Unhandled Exception:
System.ArgumentException: targetUri
Parameter name: Absolute URIs are not supported
  at System.IO.Packaging.PackUriHelper.ResolvePartUri (System.Uri sourcePartUri, System.Uri targetUri) <0x32b0440 + 0x00187> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) <0x32b3208 + 0x0021b> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart parent, System.Uri uriTarget, System.String id, System.Collections.Generic.Dictionary`2 loadedParts) <0x32b4678 + 0x001eb> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) <0x32b3208 + 0x00447> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () <0x784b88 + 0x003eb> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: targetUri
Parameter name: Absolute URIs are not supported
  at System.IO.Packaging.PackUriHelper.ResolvePartUri (System.Uri sourcePartUri, System.Uri targetUri) <0x32b0440 + 0x00187> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) <0x32b3208 + 0x0021b> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart parent, System.Uri uriTarget, System.String id, System.Collections.Generic.Dictionary`2 loadedParts) <0x32b4678 + 0x001eb> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) <0x32b3208 + 0x00447> in <filename unknown>:0
  at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () <0x784b88 + 0x003eb> in <filename unknown>:0

Does anyone know what is the problem here? Thank you.

Validator fails to notice changes to first file when comparing files

I often use the validator to compare generated files versus ones created by Excel and tweak code as a result. If I then use the validator to compare the same files in the same order it does not seem to notice if the first file has changed.

A refresh option would be best, of course.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.