我正在尝试在 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 的初学者,我不明白为什么会出现问题以及为什么输出没有详细说明更精确的位置(默认情况下是调试版本)。