이 서식 에러를 제공합니다 워드 문서 및 일반 텍스트 콘텐츠 컨트롤이라고 response1를 얻을 :OpenXML을 Word 문서에 InfoPath는 서식있는 텍스트 상자
using (WordprocessingDocument myDoc =
WordprocessingDocument.Open(ms, true))
{
MainDocumentPart mainPart = myDoc.MainDocumentPart;
List<OpenXmlElement> sdtList = InfoPathToWord.GetContentControl(mainPart.Document, "response1");
InfoPathToWord.AddRichText(0, response1, ref mainPart, ref sdtList);
}
코드는 다음과 같습니다되는 InfoPathToWord.AddRichText를 호출
public static void AddRichText(int id, string rtfValue,
ref MainDocumentPart mainPart, ref List<OpenXmlElement> sdtList)
{
if (sdtList.Count != 0)
{
id++;
string altChunkId = "AltChunkId" + id;
AlternativeFormatImportPart chunk =
mainPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.Xhtml, altChunkId);
using (MemoryStream ms = new MemoryStream(System.Text.Encoding.Default.GetBytes(rtfValue)))
{
chunk.FeedData(ms);
ms.Close();
}
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
InfoPathToWord.ReplaceContentControl(sdtList, altChunk);
}
}
,451,515,
그리고 마지막으로 altChunk는 "response1"
public static void ReplaceContentControl(
List<OpenXmlElement> sdtList, OpenXmlElement element)
{
if (sdtList.Count != 0)
{
foreach (OpenXmlElement sdt in sdtList)
{
OpenXmlElement parent = sdt.Parent;
parent.InsertAfter(element, sdt);
sdt.Remove();
}
}
}
문제를 대체는 텍스트를 대체하지만 형식이 정확하지와 쇼이다 "?" 문자를 표시합니다. 인코딩으로 인해 발생하는 것인지 확실하지 않으므로 System.Text.Encoding.UTF8.GetBytes(rtfValue), System.Text.Encoding.ASCII.GetBytes(rtfValue)
도 시도했지만 도움이되지는 않습니다.
누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까?
미리 감사드립니다.
메 이브