-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ToFlatOpcString fails with generated document #380
Comments
I can workaround it with
but that is a dirty hack. |
In my further digging there seems to be 1 or 2 problems.
I'll keep digging but there seems to be a problem either with the SDK or the |
So |
@daniel-white thanks for reporting this and providing the extra information. I'll take a look. We did just update some of the Save functionality but not sure if that's related. @twsouthwick may know of top of head. otherwise, I'll check into it. |
Calling |
This seems similar to an open issue. I added a fix for last release to enable saving when auto-save is disabled, but this was on close. Being able to save while the stream is still open is unfortunately blocked in CoreFx. Please see #294 which is the tracking issue in this repository. If you were to switch to v2.7.2, does it work? I want to make sure it is not a regression. |
Wrong button... |
@twsouthwick not a regression with .net 4.7 or .net core 2.0 using v2.7.2. same exception. |
would another "stupid workaround" be to close the yea that works since that gets to a |
Yup. That's probably the best way to do it right now, although the stream itself will have to be recreated as it will be in a disposed state. |
It worked, so when I pass a stream off to |
It'll be disposed after closing it (which forces the save/flush). Can you post what you get working for posterity? Hopefully we'll get the fixes needed in CoreFx so we can make this easier, but for now, having possible work arounds will be helpful |
here's what i got working. im guessing a using (MemoryStream stream = new MemoryStream())
{
using (WordprocessingDocument wordprocessingDocument =
WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document))
{
MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart();
/* foreach (PackagePart packagePart in wordprocessingDocument.Package.GetParts())
{
if (packagePart.ContentType == "application/vnd.openxmlformats-package.relationships+xml")
{
using (Stream packagePartStream = packagePart.GetStream())
using (StreamWriter streamWriter = new StreamWriter(packagePartStream))
{
streamWriter.Write("<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"><Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\" Target=\"word/document.xml\"/></Relationships>");
}
}
} */
Body body = new Body(new Paragraph(new Run(new RunProperties(new Bold()),
new Text("Hello world this should be bold"))));
mainDocumentPart.Document = new Document(body);
wordprocessingDocument.Save();
}
stream.Seek(0, SeekOrigin.Begin);
using (WordprocessingDocument doc = WordprocessingDocument.Open(stream, false))
{
Console.WriteLine(doc.ToFlatOpcString());
}
} |
It'll still throw "ObjectDisposedException" during some operations. If this does work, then maybe it doesn't get disposed during the package closing (can't remember off the top of my head) |
Fair enough. On another note, the unit tests don't test this path at all, perhaps for this very reason. What's troubling is that this is failing in .NET framework in the same way the .NET Core build does. adding a call to |
We're going for behavior parity between .NET Core and .NET Framework. We could add a fix for .NET Framework only, though, and have a list of known issues for .NET Core.... |
As far as the tests are concerned, there are a lot of cases the tests don't cover unfortunately. It seems that as it was originally developed some integration tests were added for document conversion, but basic functionality don't have many unit tests. Feel free to add some, and mark as skipped with a link to the issues... building up tests is always a good thing! |
@daniel-white we do have FlatOpcTests.cs with ToFlatOpcString(). Can you add your test there instead? |
I'm going to close this one as the issue is tracking in #294. Once that is fixed, we'll want to enable these tests. |
@daniel-white I've opened a PR to enable saving with a flag on |
Description
ToFlatOpcString
throws "Root element is missing." I'm trying to put this format into a VSTO add-in. When I enumeratewordprocessingDocument.Package.GetParts()
, I get the relationship part back as an empty string (ContentType = "application/vnd.openxmlformats-package.relationships+xml"
). Shouldn'tAddMainDocumentPart
take care of this under the covers?Information
Repro
Observed
Exception:
Expected
That
ToFlatOpcString
doesn't throw and I get the resulting XML string.The text was updated successfully, but these errors were encountered: