我想在.docx文件中創建AddAlternativeFormatImportPart以便通過AltChunk在文檔中引用它。問題是下面的代碼導致docx文件被Word讀取爲損壞,無法打開。使用OpenXml調用AddAlternativeFormatImportPart後損壞的文檔
string html = "some html code."
string altChunkId = "html234";
var document = WordprocessingDocument.Open(inMemoryPackage, true);
var mainPart = document.MainDocumentPart.Document;
var mainDocumentPart = document.MainDocumentPart;
AlternativeFormatImportPart chunk = mainDocumentPart.AddAlternativeFormatImportPart
(AlternativeFormatImportPartType.Xhtml, altChunkId);
Stream contentStream = chunk.GetStream(FileMode.Open,FileAccess.ReadWrite);
StreamWriter contentWriter = new StreamWriter(contentStream);
contentWriter.Write(html);
contentWriter.Flush();
{
...
}
mainPart.Save();
:您的回答非常有用。您可以給我一個提示,以解決我的問題...而不是將html數據提供給word文檔,我想獲取相應html數據的OOXML格式化字符串。無需更新單詞document.i只需要ooxml格式化的字符串... – Saravanan 2013-03-20 11:08:53