docx 파일을 병합하려고하는데이 파일은 C#을 통해 openxml 및 wordml을 사용하여 만들어졌습니다. 이 파일들은 heading 태그가 heading 1, heading 2 등이이 태그들과 함께 사용됩니다. 이러한 파일이 개별적으로 만들어지면 제목 1과 제목 2로 태그 지정된 텍스트를 클릭하거나 선택하면 제목 1, 제목 2 등이 강조 표시되고 탐색 팬은 제목 1, 제목 2 태그 그러나 이러한 텍스트를 클릭하거나 선택할 때 해당 문서를 병합 한 후에는 제목 1과 제목 2가 강조 표시되지 않습니다. 스타일 리본에. 이 병합 코드는 여기에 있습니다.제목 1, 머리글 2는 docx 파일을 병합 한 후 문서의 스타일 리본에서 강조 표시되지 않습니다.
MemoryStream ms = new MemoryStream();
using (WordprocessingDocument myDoc =
WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = myDoc.AddMainDocumentPart();
mainPart.Document = new Document { Body = new Body() };
int counter = 1;
foreach (var sectionOutput in sectionOutputs)
{
foreach (var outputFile in sectionOutput.Files)
{
Paragraph sectionBreakPara = null;
if (!sectionOutput.SectionType.Equals(sectionOutputs[sectionOutputs.Count - 1].SectionType))
{
if (outputFile == sectionOutput.Files.Last())
//check whether this is the last file in this section
{
using (
WordprocessingDocument pkgSourceDoc =
WordprocessingDocument.Open(outputFile.OutputStream, true))
{
var sourceBody = pkgSourceDoc.MainDocumentPart.Document.Body;
SectionProperties docSectionBreak =
sourceBody.Descendants<SectionProperties>().LastOrDefault();
if (docSectionBreak != null)
{
var clonedSectionBreak = (SectionProperties)docSectionBreak.CloneNode(true);
clonedSectionBreak.RemoveAllChildren<FooterReference>();
clonedSectionBreak.RemoveAllChildren<HeaderReference>();
sectionBreakPara = new Paragraph();
ParagraphProperties sectionParaProp = new ParagraphProperties();
sectionParaProp.AppendChild(clonedSectionBreak);
sectionBreakPara.AppendChild(sectionParaProp);
}
}
}
}
string altChunkId = string.Format("altchunkId{0}", counter);
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML, altChunkId);
outputFile.OutputStream.Seek(0, SeekOrigin.Begin);
chunk.FeedData(outputFile.OutputStream);
AltChunk altChunk = new AltChunk(new AltChunkProperties(new MatchSource { Val = new OnOffValue(true) })) { Id = altChunkId };
mainPart.Document.Body.AppendChild(altChunk);
if (sectionBreakPara != null)
{
mainPart.Document
.Body
.AppendChild(sectionBreakPara);
}
counter++;
}
}
mainPart.Document.Save();
}
return ms;
두 개의 다른 소스 파일에 대해 제목 1의 스타일이 다른가요? – Steve
두 개의 서로 다른 원본 파일에서 제목 1의 스타일이 다르지 않습니다. – user3812657