2

我正在尝试在 OSX 下使用 Mono运行DocX 。我正在使用最近的版本,版本 3.2.1。使用 xbuild 构建成功,但 Hello World 示例在运行时失败。

基本上,填充文档功能(摘录如下):

public static DocX Create(string filename) {
            switch (rel.RelationshipType)
            {
                case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes":
                    document.endnotesPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.RelativeOrAbsolute));
                    using (TextReader tr = new StreamReader(document.endnotesPart.GetStream()))
                        document.endnotes = XDocument.Load(tr);
                    break;

                case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes":
                    document.footnotesPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.RelativeOrAbsolute));
                    using (TextReader tr = new StreamReader(document.footnotesPart.GetStream()))
                        document.footnotes = XDocument.Load(tr);
                    break;

                case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
                    document.stylesPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.RelativeOrAbsolute));
                    using (TextReader tr = new StreamReader(document.stylesPart.GetStream()))
                        document.styles = XDocument.Load(tr);
                    break;

                case "http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects":
                    document.stylesWithEffectsPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.RelativeOrAbsolute));
                    using (TextReader tr = new StreamReader(document.stylesWithEffectsPart.GetStream()))
                        document.stylesWithEffects = XDocument.Load(tr);
                    break;

                case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable":
                    document.fontTablePart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.RelativeOrAbsolute));
                    using (TextReader tr = new StreamReader(document.fontTablePart.GetStream()))
                        document.fontTable = XDocument.Load(tr);
                    break;

                case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering":
                    document.numberingPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.RelativeOrAbsolute));
                    using (TextReader tr = new StreamReader(document.numberingPart.GetStream()))
                        document.numbering = XDocument.Load(tr);
                    break;

                default:
                    break;
            }

失败:

Unhandled Exception:
  System.ArgumentException: partUri
  Parameter name: Absolute URIs are not supported
at System.IO.Packaging.Check.PartUri (System.Uri partUri) [0x00000] in <filename unknown>:0 
at System.IO.Packaging.Package.GetPart (System.Uri partUri) [0x00000] in <filename unknown>:0 
at Novacode.DocX.PopulateDocument (Novacode.DocX document, System.IO.Packaging.Package package) [0x00000] in <filename unknown>:0 
at Novacode.DocX.PostLoad (System.IO.Packaging.Package& package) [0x00000] in <filename unknown>:0 
at Novacode.DocX.Load (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
at Novacode.DocX.Create (System.String filename) [0x00000] in <filename unknown>:0 

其中 Novacode 是命名空间。

作为 CS/Mono 的初学者,我不明白为什么会出现问题以及为什么输出没有详细说明更精确的位置(默认情况下是调试版本)。

4

2 回答 2

0

尝试使用UriKind.Relative而不是UriKind.RelativeOrAbsolute.

于 2013-09-23T22:56:09.840 回答
0

我已经提交了一个补丁来修复这个异常,补丁号是 revobtz 的 16266。此补丁包含使 Docx 可移植到单声道的修复程序。修复异常:mono os x 在创建文档时不支持绝对路径。使用 VS 在 windows 上测试,并使用 xamarin 测试 mac os x。

更新

下载最新版本的DocX,bug已经修复。

于 2014-04-20T22:41:31.090 回答