저는 OpenXMl sdk를 사용하여 C#을 통해 단어 문서를 만듭니다. 나는 모든 HTML 페이지를 워드 문서로 변환하고 있지만 변환 중에는 이미지에 대한 절대 주소를 부여하고 변환 한 후에는 내 시스템에 완벽하게 들어 있지만이 문서를 다른 시스템으로 가져 오려고 할 때 이미지가 나타나지 않습니다. 그곳에.Open XML을 통해 Word 문서를 만든 후 이미지가 나타나지 않습니다.
모든 이미지가 있지만 이름이 다른 미디어 디렉토리를 확인했습니다.
내 문서가 변환되었지만이 mathod를 사용 중입니다.
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(documentPath, true))
{
XNamespace w =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main";
XNamespace r =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships";
string altChunkId = "AltChunkId1";
MainDocumentPart mainPart = myDoc.MainDocumentPart;
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart("application/xhtml+xml", altChunkId);
using (Stream chunkStream = chunk.GetStream(FileMode.Create, FileAccess.Write))
using (StreamWriter stringStream = new StreamWriter(chunkStream))
stringStream.Write(html);
XElement altChunk = new XElement(w + "altChunk",
new XAttribute(r + "id", altChunkId)
);
XDocument mainDocumentXDoc = GetXDocument(myDoc);
mainDocumentXDoc.Root
.Element(w + "body")
.Elements(w + "p")
.Last()
.AddAfterSelf(altChunk);
SaveXDocument(myDoc, mainDocumentXDoc);
}
private static XDocument GetXDocument(WordprocessingDocument myDoc)
{
// Load the main document part into an XDocument
XDocument mainDocumentXDoc;
using (Stream str = myDoc.MainDocumentPart.GetStream())
using (XmlReader xr = XmlReader.Create(str))
mainDocumentXDoc = XDocument.Load(xr);
return mainDocumentXDoc;
}
private static void SaveXDocument(WordprocessingDocument myDoc,
XDocument mainDocumentXDoc)
{
// Serialize the XDocument back into the part
using (Stream str = myDoc.MainDocumentPart.GetStream(
FileMode.Create, FileAccess.Write))
using (XmlWriter xw = XmlWriter.Create(str))
mainDocumentXDoc.Save(xw);
}
이는 콘텐츠 및 절대 경로에 도시 된 afchunk.dat 파일을 생성한다.
기본적으로 나는 .html을 .docx 파일로 변환하려는 모든 코딩을 통해 파일을 만들고 싶지 않습니다.
그래서 아무도 HTML에서 오류가 발생하지 않고 어떻게 변환 할 수 있는지 말해 줄 수 있습니다.