Skip to content
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

This document is missing a relationship #863

Open
wtujvk opened this issue Jan 26, 2021 · 7 comments
Open

This document is missing a relationship #863

wtujvk opened this issue Jan 26, 2021 · 7 comments

Comments

@wtujvk
Copy link

wtujvk commented Jan 26, 2021

Description
This document is missing a relationship,say "数据包中不存在指定部件", how to skip error or provide callback function ?
Please provide a simple description of the issue encountered.

Information

  • .NET Target: (net461)
  • DocumentFormat.OpenXml Version: (2.11.3)

Repro
#858

// Please add a self-contained, minimum viable repro of the issue.
// If you require external resources, please provide a gist or GitHub repro
// An Xunit style test is preferred, but a console application would work too.

When I unzip the docx file, on the path " word_rels\document.xml.rels", I found "Target="../NULL"/"
Are there any where to skip error relationship or delete error relationship ?
I use RemoveMalformedHyperlinksRelationshipErrorHandler to solve, but It not work.
image

Observed

Please add your observed behavior here

Expected

Please add your expected behavior here.
Skip error or fix document.

Or use code do like this:

https://docs.microsoft.com/en-us/office/troubleshoot/word/image-part-relationship-rld8-not-found-error-microsoft-word

@wtujvk
Copy link
Author

wtujvk commented Jan 27, 2021

one solution is use nuget packages and save as a new file.

using Spire.Doc;
using System.IO;

using (Document document = new Document(filePath))
var newFilePath = "newfile.docx";
document.SaveToFile(newFilePath, FileFormat.Docx);
return newFilePath;

The new file becom
image

The error image is lose, but the docx can open by "WordprocessingDocument.Open".
image

@twsouthwick
Copy link
Member

Can you include a snippet of how you tried to use the RemoveMalformedHyperlinksRelationshipErrorHandler? Also, you're saying you used 2.11.3 but also tried the RemoveMalformedHyperlinksRelationshipErrorHandler? That infrastructure was introduced with 2.12.0

@wtujvk
Copy link
Author

wtujvk commented Jan 28, 2021

Oh, the question occur in Version: (2.11.3), but when I update to 2.12.1,use code

var openSettings = new OpenSettings()
{
  RelationshipErrorHandlerFactory = p => new RemoveMalformedHyperlinksRelationshipErrorHandler(p)
};
using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true, openSettings)){}

In this class ‘RemoveMalformedHyperlinksRelationshipErrorHandler‘, I can override and return a new uri to Ignore some mistakes by partUri or url.

The RemoveMalformedHyperlinksRelationshipErrorHandler from
https://github.com/OfficeDev/Open-XML-SDK/blob/master/test/DocumentFormat.OpenXml.Tests/OpenXmlDomTest/DocumentOpenTests.cs

@twsouthwick
Copy link
Member

twsouthwick commented Jan 28, 2021

Yes, but I'm still confused as to what you are looking for. That RemoveMalformedHyperlinksRelationshipErrorHandler you're using is a test one, and by no means is it expected to be used as-is in production. It's more of an example.

It seems like you are asking for a way to handle cases like this with the RelationshipErrorHandler. That's valid, I'm just somewhat confused by what you are asking for here as things are spread across multiple comments and issues. I'd need that repro case that the issue template asks you to provide and a clear understanding of what you are trying to do.

@wtujvk
Copy link
Author

wtujvk commented Jan 29, 2021

I think the reason is that package ' System.IO.Packaging.Package'.
I need to find a way to abandon the invalid part, not abandon the docx file. I need to render a docx document, but when I cannot open the document (use WordprocessingDocument.Open), I can do nothing. Show the effective parts as possible,so
we know there is an error in the document, and can do something. In the scene, we open a document and show it on Web by HTML. Is there another way to open document what not use 'WordprocessingDocument.Open' ?

我认为可能是'System.IO.Packaging.Package'包的问题。
尽可能的打开文档忽略错误的部分,而不是打不开。用户上传一个word文档,然后在Web网站以HTML形式展示。有错误的地方忽略或者使用占位符替代,这样就可以指定文档哪里有问题,或者尝试修复文档。
或者有其他方式打开文档吗 ?

@twsouthwick
Copy link
Member

We can probably make the RelationshipErrorHandler handle this kind of thing, but it doesn't appear to out of the box.

I'm fairly busy right now and can't investigate the design of this. I'll have some time in about a month. In the meantime, feel free to propose an API and I'm happy to review it.

@lindexi
Copy link
Contributor

lindexi commented May 25, 2022

See #247 dotnet/runtime#26084 #715

@wtujvk

Can it fix this?

See my Chinese blogs too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants