Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.

Commit 8170920

Browse files
committed
feat: add footer
1 parent 96b587b commit 8170920

File tree

3 files changed

+332
-19
lines changed

3 files changed

+332
-19
lines changed

examples/input.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: 测试人
33
id: 1234567890
44
teacher: 张某
55
department: 某学院
6+
title: 一个看似很厉害的标题
67
c_title: 一个看似很厉害的标题
78
e_title: One NewBee name
89
filename: 这是报告的名字

md2docx/GeneratedCode.cs

Lines changed: 305 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,255 @@ public static LatentStyles GenerateLatentStyles()
781781
return latentStyles;
782782
}
783783

784-
public static void GenerateCover(ref Body docBody, Dictionary<string, string> info)
784+
public static void Generate1FooterPart(FooterPart part)
785+
{
786+
787+
Footer footer1 = new Footer() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se w16cid wp14" } };
788+
footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
789+
footer1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
790+
footer1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
791+
footer1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
792+
footer1.AddNamespaceDeclaration("cx3", "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex");
793+
footer1.AddNamespaceDeclaration("cx4", "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex");
794+
footer1.AddNamespaceDeclaration("cx5", "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex");
795+
footer1.AddNamespaceDeclaration("cx6", "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex");
796+
footer1.AddNamespaceDeclaration("cx7", "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex");
797+
footer1.AddNamespaceDeclaration("cx8", "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex");
798+
footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
799+
footer1.AddNamespaceDeclaration("aink", "http://schemas.microsoft.com/office/drawing/2016/ink");
800+
footer1.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d");
801+
footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
802+
footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
803+
footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
804+
footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
805+
footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
806+
footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
807+
footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
808+
footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
809+
footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
810+
footer1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
811+
footer1.AddNamespaceDeclaration("w16cid", "http://schemas.microsoft.com/office/word/2016/wordml/cid");
812+
footer1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
813+
footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
814+
footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
815+
footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
816+
footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");
817+
818+
SdtBlock sdtBlock1 = new SdtBlock();
819+
820+
SdtProperties sdtProperties1 = new SdtProperties();
821+
SdtId sdtId1 = new SdtId() { Val = -1144034156 };
822+
823+
SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
824+
DocPartGallery docPartGallery1 = new DocPartGallery() { Val = "Page Numbers (Bottom of Page)" };
825+
DocPartUnique docPartUnique1 = new DocPartUnique();
826+
827+
sdtContentDocPartObject1.Append(docPartGallery1);
828+
sdtContentDocPartObject1.Append(docPartUnique1);
829+
830+
sdtProperties1.Append(sdtId1);
831+
sdtProperties1.Append(sdtContentDocPartObject1);
832+
SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();
833+
834+
SdtContentBlock sdtContentBlock1 = new SdtContentBlock();
835+
836+
Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00826B60", RsidRunAdditionDefault = "00826B60", ParagraphId = "34D1FE1C", TextId = "7A33BCDB" };
837+
838+
ParagraphProperties paragraphProperties1 = new ParagraphProperties();
839+
ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId() { Val = "a5" };
840+
Justification justification1 = new Justification() { Val = JustificationValues.Center };
841+
842+
paragraphProperties1.Append(paragraphStyleId1);
843+
paragraphProperties1.Append(justification1);
844+
845+
Run run1 = new Run();
846+
FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
847+
848+
run1.Append(fieldChar1);
849+
850+
Run run2 = new Run();
851+
FieldCode fieldCode1 = new FieldCode();
852+
fieldCode1.Text = "PAGE \\* MERGEFORMAT";
853+
854+
run2.Append(fieldCode1);
855+
856+
Run run3 = new Run();
857+
FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate };
858+
859+
run3.Append(fieldChar2);
860+
861+
Run run4 = new Run();
862+
863+
RunProperties runProperties1 = new RunProperties();
864+
Languages languages1 = new Languages() { Val = "zh-CN" };
865+
866+
runProperties1.Append(languages1);
867+
Text text1 = new Text();
868+
text1.Text = "0";
869+
870+
run4.Append(runProperties1);
871+
run4.Append(text1);
872+
873+
Run run5 = new Run();
874+
FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End };
875+
876+
run5.Append(fieldChar3);
877+
878+
paragraph1.Append(paragraphProperties1);
879+
paragraph1.Append(run1);
880+
paragraph1.Append(run2);
881+
paragraph1.Append(run3);
882+
paragraph1.Append(run4);
883+
paragraph1.Append(run5);
884+
885+
BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", DisplacedByCustomXml = DisplacedByCustomXmlValues.Previous, Id = "0" };
886+
BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { DisplacedByCustomXml = DisplacedByCustomXmlValues.Previous, Id = "0" };
887+
888+
sdtContentBlock1.Append(bookmarkStart1);
889+
sdtContentBlock1.Append(bookmarkEnd1);
890+
sdtContentBlock1.Append(paragraph1);
891+
892+
sdtBlock1.Append(sdtProperties1);
893+
sdtBlock1.Append(sdtEndCharProperties1);
894+
sdtBlock1.Append(sdtContentBlock1);
895+
896+
Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00826B60", RsidRunAdditionDefault = "00826B60", ParagraphId = "2BB488F1", TextId = "77777777" };
897+
898+
ParagraphProperties paragraphProperties2 = new ParagraphProperties();
899+
ParagraphStyleId paragraphStyleId2 = new ParagraphStyleId() { Val = "a5" };
900+
901+
paragraphProperties2.Append(paragraphStyleId2);
902+
903+
paragraph2.Append(paragraphProperties2);
904+
905+
footer1.Append(sdtBlock1);
906+
footer1.Append(paragraph2);
907+
908+
part.Footer = footer1;
909+
}
910+
911+
public static void GenerateIFooterPart(FooterPart part)
912+
{
913+
Footer footer1 = new Footer() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se w16cid wp14" } };
914+
footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
915+
footer1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
916+
footer1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
917+
footer1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
918+
footer1.AddNamespaceDeclaration("cx3", "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex");
919+
footer1.AddNamespaceDeclaration("cx4", "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex");
920+
footer1.AddNamespaceDeclaration("cx5", "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex");
921+
footer1.AddNamespaceDeclaration("cx6", "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex");
922+
footer1.AddNamespaceDeclaration("cx7", "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex");
923+
footer1.AddNamespaceDeclaration("cx8", "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex");
924+
footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
925+
footer1.AddNamespaceDeclaration("aink", "http://schemas.microsoft.com/office/drawing/2016/ink");
926+
footer1.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d");
927+
footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
928+
footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
929+
footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
930+
footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
931+
footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
932+
footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
933+
footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
934+
footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
935+
footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
936+
footer1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
937+
footer1.AddNamespaceDeclaration("w16cid", "http://schemas.microsoft.com/office/word/2016/wordml/cid");
938+
footer1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
939+
footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
940+
footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
941+
footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
942+
footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");
943+
944+
SdtBlock sdtBlock1 = new SdtBlock();
945+
946+
SdtProperties sdtProperties1 = new SdtProperties();
947+
SdtId sdtId1 = new SdtId() { Val = 1445193178 };
948+
949+
SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
950+
DocPartGallery docPartGallery1 = new DocPartGallery() { Val = "Page Numbers (Bottom of Page)" };
951+
DocPartUnique docPartUnique1 = new DocPartUnique();
952+
953+
sdtContentDocPartObject1.Append(docPartGallery1);
954+
sdtContentDocPartObject1.Append(docPartUnique1);
955+
956+
sdtProperties1.Append(sdtId1);
957+
sdtProperties1.Append(sdtContentDocPartObject1);
958+
SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();
959+
960+
SdtContentBlock sdtContentBlock1 = new SdtContentBlock();
961+
962+
Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00826B60", RsidRunAdditionDefault = "00826B60", ParagraphId = "280F2866", TextId = "77777777" };
963+
964+
ParagraphProperties paragraphProperties1 = new ParagraphProperties();
965+
ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId() { Val = "a5" };
966+
Justification justification1 = new Justification() { Val = JustificationValues.Center };
967+
968+
paragraphProperties1.Append(paragraphStyleId1);
969+
paragraphProperties1.Append(justification1);
970+
971+
Run run1 = new Run();
972+
FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
973+
974+
run1.Append(fieldChar1);
975+
976+
Run run2 = new Run();
977+
FieldCode fieldCode1 = new FieldCode();
978+
fieldCode1.Text = "PAGE \\* MERGEFORMAT";
979+
980+
run2.Append(fieldCode1);
981+
982+
Run run3 = new Run();
983+
FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate };
984+
985+
run3.Append(fieldChar2);
986+
987+
Run run4 = new Run();
988+
989+
RunProperties runProperties1 = new RunProperties();
990+
Languages languages1 = new Languages() { Val = "zh-CN" };
991+
992+
runProperties1.Append(languages1);
993+
Text text1 = new Text();
994+
text1.Text = "2";
995+
996+
run4.Append(runProperties1);
997+
run4.Append(text1);
998+
999+
Run run5 = new Run();
1000+
FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End };
1001+
1002+
run5.Append(fieldChar3);
1003+
1004+
paragraph1.Append(paragraphProperties1);
1005+
paragraph1.Append(run1);
1006+
paragraph1.Append(run2);
1007+
paragraph1.Append(run3);
1008+
paragraph1.Append(run4);
1009+
paragraph1.Append(run5);
1010+
1011+
sdtContentBlock1.Append(paragraph1);
1012+
1013+
sdtBlock1.Append(sdtProperties1);
1014+
sdtBlock1.Append(sdtEndCharProperties1);
1015+
sdtBlock1.Append(sdtContentBlock1);
1016+
1017+
Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00826B60", RsidRunAdditionDefault = "00826B60", ParagraphId = "688DAA4B", TextId = "77777777" };
1018+
1019+
ParagraphProperties paragraphProperties2 = new ParagraphProperties();
1020+
ParagraphStyleId paragraphStyleId2 = new ParagraphStyleId() { Val = "a5" };
1021+
1022+
paragraphProperties2.Append(paragraphStyleId2);
1023+
1024+
paragraph2.Append(paragraphProperties2);
1025+
1026+
footer1.Append(sdtBlock1);
1027+
footer1.Append(paragraph2);
1028+
1029+
part.Footer = footer1;
1030+
}
1031+
1032+
public static void GenerateCover(ref Body docBody, Dictionary<string, string> info, bool hasHeader)
7851033
{
7861034
Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "003672AC", RsidParagraphProperties = "003672AC", RsidRunAdditionDefault = "003672AC", ParagraphId = "71725C42", TextId = "77777777" };
7871035

@@ -1848,7 +2096,22 @@ public static void GenerateCover(ref Body docBody, Dictionary<string, string> in
18482096

18492097
ParagraphProperties paragraphProperties27 = new ParagraphProperties();
18502098
Justification justification15 = new Justification() { Val = JustificationValues.Center };
1851-
2099+
SectionProperties sectionProperties1 = new SectionProperties();
2100+
if (hasHeader)
2101+
{
2102+
HeaderReference headerReference1 = new HeaderReference() { Type = HeaderFooterValues.Default, Id = "rId3" };
2103+
sectionProperties1.Append(headerReference1);
2104+
}
2105+
PageSize pageSize1 = new PageSize() { Width = 11906U, Height = 16838U };
2106+
PageMargin pageMargin1 = new PageMargin() { Top = 1418, Right = 1134U, Bottom = 1418, Left = 1701U, Header = 851U, Footer = 992U, Gutter = 0U };
2107+
Columns columns1 = new Columns() { Space = "425" };
2108+
DocGrid docGrid1 = new DocGrid() { Type = DocGridValues.Lines, LinePitch = 312 };
2109+
sectionProperties1.Append(pageSize1);
2110+
sectionProperties1.Append(pageMargin1);
2111+
sectionProperties1.Append(columns1);
2112+
sectionProperties1.Append(docGrid1);
2113+
2114+
paragraphProperties27.Append(sectionProperties1);
18522115
paragraphProperties27.Append(justification15);
18532116

18542117
Run run20 = new Run();
@@ -1891,7 +2154,7 @@ public static void GenerateCover(ref Body docBody, Dictionary<string, string> in
18912154
docBody.Append(paragraph27);
18922155
}
18932156

1894-
public static void GenerateTOC(ref Body docBody)
2157+
public static void GenerateTOC(ref Body docBody, bool hasHeader, bool hasFooter)
18952158
{
18962159
Paragraph para = new Paragraph
18972160
{
@@ -1974,8 +2237,10 @@ public static void GenerateTOC(ref Body docBody)
19742237
runProperties5.Append(bold2);
19752238
runProperties5.Append(boldComplexScript2);
19762239
runProperties5.Append(noProof1);
1977-
Text text3 = new Text();
1978-
text3.Text = "请手动点击<更新目录>按钮更新目录";
2240+
Text text3 = new Text
2241+
{
2242+
Text = "请手动点击<更新目录>按钮更新目录"
2243+
};
19792244

19802245
run4.Append(runProperties5);
19812246
run4.Append(text3);
@@ -1989,8 +2254,41 @@ public static void GenerateTOC(ref Body docBody)
19892254
sdtBlock1.Append(sdtProperties1);
19902255
sdtBlock1.Append(sdtEndCharProperties1);
19912256
sdtBlock1.Append(sdtContentBlock1);
1992-
2257+
19932258
docBody.Append(sdtBlock1);
2259+
2260+
para = new Paragraph();
2261+
2262+
ParagraphProperties paragraphProperties = new ParagraphProperties();
2263+
2264+
SectionProperties sectionProperties = new SectionProperties() { RsidR = "00160BE2", RsidSect = "00826B60" };
2265+
if (hasHeader)
2266+
{
2267+
HeaderReference headerReference1 = new HeaderReference() { Type = HeaderFooterValues.Default, Id = "rId3" };
2268+
sectionProperties.Append(headerReference1);
2269+
}
2270+
if (hasFooter)
2271+
{
2272+
FooterReference footerReference4 = new FooterReference() { Type = HeaderFooterValues.Default, Id = "rId5" };
2273+
sectionProperties.Append(footerReference4);
2274+
}
2275+
PageSize pageSize2 = new PageSize() { Width = 11906U, Height = 16838U };
2276+
PageMargin pageMargin2 = new PageMargin() { Top = 1440, Right = 1800U, Bottom = 1440, Left = 1800U, Header = 851U, Footer = 992U, Gutter = 0U };
2277+
PageNumberType pageNumberType1 = new PageNumberType() { Format = NumberFormatValues.UpperRoman, Start = 1 };
2278+
Columns columns2 = new Columns() { Space = "425" };
2279+
DocGrid docGrid2 = new DocGrid() { Type = DocGridValues.Lines, LinePitch = 312 };
2280+
sectionProperties.Append(pageSize2);
2281+
sectionProperties.Append(pageMargin2);
2282+
sectionProperties.Append(pageNumberType1);
2283+
sectionProperties.Append(columns2);
2284+
sectionProperties.Append(docGrid2);
2285+
2286+
paragraphProperties.Append(sectionProperties);
2287+
2288+
Run run14 = new Run();
2289+
para.Append(paragraphProperties);
2290+
para.Append(run14);
2291+
docBody.Append(para);
19942292
}
19952293

19962294
public static void GenerateFontTablePartContent(FontTablePart fontTablePart1)
@@ -2351,7 +2649,7 @@ public static void GenerateHeaderPartContent(HeaderPart headerPart, string title
23512649
runProperties2.Append(fontSize7);
23522650
runProperties2.Append(fontSizeComplexScript7);
23532651
Text text1 = new Text() { Space = SpaceProcessingModeValues.Preserve };
2354-
text1.Text = " ";
2652+
text1.Text = " ";
23552653

23562654
run2.Append(runProperties2);
23572655
run2.Append(text1);

0 commit comments

Comments
 (0)