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

Commit 96b587b

Browse files
committed
feat: add header
1 parent 74ec556 commit 96b587b

File tree

2 files changed

+276
-9
lines changed

2 files changed

+276
-9
lines changed

md2docx/GeneratedCode.cs

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using A = DocumentFormat.OpenXml.Drawing;
77
using Wp = DocumentFormat.OpenXml.Drawing.Wordprocessing;
88
using Pic = DocumentFormat.OpenXml.Drawing.Pictures;
9+
using A14 = DocumentFormat.OpenXml.Office2010.Drawing;
10+
911
namespace md2docx
1012
{
1113
/// <summary>
@@ -2146,5 +2148,256 @@ public static Run GenerateImageReference(int id, long width, long height)
21462148

21472149
return run1;
21482150
}
2151+
2152+
public static void GenerateHeaderPartContent(HeaderPart headerPart, string title)
2153+
{
2154+
Header header = new Header() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se w16cid wp14" } };
2155+
header.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
2156+
header.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
2157+
header.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
2158+
header.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
2159+
header.AddNamespaceDeclaration("cx3", "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex");
2160+
header.AddNamespaceDeclaration("cx4", "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex");
2161+
header.AddNamespaceDeclaration("cx5", "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex");
2162+
header.AddNamespaceDeclaration("cx6", "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex");
2163+
header.AddNamespaceDeclaration("cx7", "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex");
2164+
header.AddNamespaceDeclaration("cx8", "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex");
2165+
header.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
2166+
header.AddNamespaceDeclaration("aink", "http://schemas.microsoft.com/office/drawing/2016/ink");
2167+
header.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d");
2168+
header.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
2169+
header.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
2170+
header.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
2171+
header.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
2172+
header.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
2173+
header.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
2174+
header.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
2175+
header.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
2176+
header.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
2177+
header.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
2178+
header.AddNamespaceDeclaration("w16cid", "http://schemas.microsoft.com/office/word/2016/wordml/cid");
2179+
header.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
2180+
header.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
2181+
header.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
2182+
header.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
2183+
header.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");
2184+
2185+
Paragraph paragraph1 = new Paragraph() { RsidParagraphMarkRevision = "000724D3", RsidParagraphAddition = "000724D3", RsidParagraphProperties = "000724D3", RsidRunAdditionDefault = "000724D3", ParagraphId = "1A187061", TextId = "33744066" };
2186+
2187+
ParagraphProperties paragraphProperties1 = new ParagraphProperties();
2188+
2189+
ParagraphBorders paragraphBorders2 = new ParagraphBorders();
2190+
BottomBorder bottomBorder2 = new BottomBorder() { Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)6U, Space = (UInt32Value)0U };
2191+
2192+
paragraphBorders2.Append(bottomBorder2);
2193+
2194+
Tabs tabs3 = new Tabs();
2195+
TabStop tabStop5 = new TabStop() { Val = TabStopValues.Left, Position = 1485 };
2196+
TabStop tabStop6 = new TabStop() { Val = TabStopValues.Center, Position = 4153 };
2197+
TabStop tabStop7 = new TabStop() { Val = TabStopValues.Right, Position = 8306 };
2198+
2199+
tabs3.Append(tabStop5);
2200+
tabs3.Append(tabStop6);
2201+
tabs3.Append(tabStop7);
2202+
SnapToGrid snapToGrid3 = new SnapToGrid() { Val = false };
2203+
Justification justification4 = new Justification() { Val = JustificationValues.Distribute };
2204+
2205+
ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
2206+
RunFonts runFonts2 = new RunFonts() { Ascii = "黑体", EastAsia = "黑体" };
2207+
FontSize fontSize5 = new FontSize() { Val = "18" };
2208+
FontSizeComplexScript fontSizeComplexScript5 = new FontSizeComplexScript() { Val = "18" };
2209+
2210+
paragraphMarkRunProperties1.Append(runFonts2);
2211+
paragraphMarkRunProperties1.Append(fontSize5);
2212+
paragraphMarkRunProperties1.Append(fontSizeComplexScript5);
2213+
2214+
paragraphProperties1.Append(paragraphBorders2);
2215+
paragraphProperties1.Append(tabs3);
2216+
paragraphProperties1.Append(snapToGrid3);
2217+
paragraphProperties1.Append(justification4);
2218+
paragraphProperties1.Append(paragraphMarkRunProperties1);
2219+
2220+
Run run1 = new Run();
2221+
2222+
RunProperties runProperties1 = new RunProperties();
2223+
RunFonts runFonts3 = new RunFonts() { Ascii = "华文楷体", HighAnsi = "华文楷体", EastAsia = "华文楷体" };
2224+
Bold bold1 = new Bold();
2225+
BoldComplexScript boldComplexScript1 = new BoldComplexScript();
2226+
NoProof noProof1 = new NoProof();
2227+
Kern kern2 = new Kern() { Val = (UInt32Value)0U };
2228+
FontSize fontSize6 = new FontSize() { Val = "72" };
2229+
FontSizeComplexScript fontSizeComplexScript6 = new FontSizeComplexScript() { Val = "72" };
2230+
2231+
runProperties1.Append(runFonts3);
2232+
runProperties1.Append(bold1);
2233+
runProperties1.Append(boldComplexScript1);
2234+
runProperties1.Append(noProof1);
2235+
runProperties1.Append(kern2);
2236+
runProperties1.Append(fontSize6);
2237+
runProperties1.Append(fontSizeComplexScript6);
2238+
2239+
Drawing drawing1 = new Drawing();
2240+
2241+
Wp.Inline inline1 = new Wp.Inline() { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)0U, DistanceFromRight = (UInt32Value)0U, AnchorId = "64BA7B75", EditId = "611F1D7B" };
2242+
Wp.Extent extent1 = new Wp.Extent() { Cx = 1095375L, Cy = 285750L };
2243+
Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 9525L, BottomEdge = 0L };
2244+
Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)141U, Name = "图片 141", Description = "毕业设计(论文)图标" };
2245+
2246+
Wp.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 = new Wp.NonVisualGraphicFrameDrawingProperties();
2247+
2248+
A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks() { NoChangeAspect = true };
2249+
graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
2250+
2251+
nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1);
2252+
2253+
A.Graphic graphic1 = new A.Graphic();
2254+
graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
2255+
2256+
A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };
2257+
2258+
Pic.Picture picture1 = new Pic.Picture();
2259+
picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");
2260+
2261+
Pic.NonVisualPictureProperties nonVisualPictureProperties1 = new Pic.NonVisualPictureProperties();
2262+
Pic.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Pic.NonVisualDrawingProperties() { Id = (UInt32Value)0U, Name = "Picture 10", Description = "毕业设计(论文)图标" };
2263+
2264+
Pic.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new Pic.NonVisualPictureDrawingProperties();
2265+
A.PictureLocks pictureLocks1 = new A.PictureLocks() { NoChangeAspect = true, NoChangeArrowheads = true };
2266+
2267+
nonVisualPictureDrawingProperties1.Append(pictureLocks1);
2268+
2269+
nonVisualPictureProperties1.Append(nonVisualDrawingProperties1);
2270+
nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);
2271+
2272+
Pic.BlipFill blipFill1 = new Pic.BlipFill();
2273+
2274+
A.Blip blip1 = new A.Blip() { Embed = "rId4" };
2275+
2276+
A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();
2277+
2278+
A.BlipExtension blipExtension1 = new A.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };
2279+
2280+
A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi() { Val = false };
2281+
useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
2282+
2283+
blipExtension1.Append(useLocalDpi1);
2284+
2285+
blipExtensionList1.Append(blipExtension1);
2286+
2287+
blip1.Append(blipExtensionList1);
2288+
A.SourceRectangle sourceRectangle1 = new A.SourceRectangle();
2289+
2290+
A.Stretch stretch1 = new A.Stretch();
2291+
A.FillRectangle fillRectangle1 = new A.FillRectangle();
2292+
2293+
stretch1.Append(fillRectangle1);
2294+
2295+
blipFill1.Append(blip1);
2296+
blipFill1.Append(sourceRectangle1);
2297+
blipFill1.Append(stretch1);
2298+
2299+
Pic.ShapeProperties shapeProperties1 = new Pic.ShapeProperties() { BlackWhiteMode = A.BlackWhiteModeValues.Auto };
2300+
2301+
A.Transform2D transform2D1 = new A.Transform2D();
2302+
A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L };
2303+
A.Extents extents1 = new A.Extents() { Cx = 1095375L, Cy = 285750L };
2304+
2305+
transform2D1.Append(offset1);
2306+
transform2D1.Append(extents1);
2307+
2308+
A.PresetGeometry presetGeometry1 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
2309+
A.AdjustValueList adjustValueList1 = new A.AdjustValueList();
2310+
2311+
presetGeometry1.Append(adjustValueList1);
2312+
A.NoFill noFill1 = new A.NoFill();
2313+
2314+
A.Outline outline4 = new A.Outline();
2315+
A.NoFill noFill2 = new A.NoFill();
2316+
2317+
outline4.Append(noFill2);
2318+
2319+
shapeProperties1.Append(transform2D1);
2320+
shapeProperties1.Append(presetGeometry1);
2321+
shapeProperties1.Append(noFill1);
2322+
shapeProperties1.Append(outline4);
2323+
2324+
picture1.Append(nonVisualPictureProperties1);
2325+
picture1.Append(blipFill1);
2326+
picture1.Append(shapeProperties1);
2327+
2328+
graphicData1.Append(picture1);
2329+
2330+
graphic1.Append(graphicData1);
2331+
2332+
inline1.Append(extent1);
2333+
inline1.Append(effectExtent1);
2334+
inline1.Append(docProperties1);
2335+
inline1.Append(nonVisualGraphicFrameDrawingProperties1);
2336+
inline1.Append(graphic1);
2337+
2338+
drawing1.Append(inline1);
2339+
2340+
run1.Append(runProperties1);
2341+
run1.Append(drawing1);
2342+
2343+
Run run2 = new Run();
2344+
2345+
RunProperties runProperties2 = new RunProperties();
2346+
RunFonts runFonts4 = new RunFonts() { Ascii = "黑体", HighAnsi = "Times", EastAsia = "黑体" };
2347+
FontSize fontSize7 = new FontSize() { Val = "18" };
2348+
FontSizeComplexScript fontSizeComplexScript7 = new FontSizeComplexScript() { Val = "18" };
2349+
2350+
runProperties2.Append(runFonts4);
2351+
runProperties2.Append(fontSize7);
2352+
runProperties2.Append(fontSizeComplexScript7);
2353+
Text text1 = new Text() { Space = SpaceProcessingModeValues.Preserve };
2354+
text1.Text = " ";
2355+
2356+
run2.Append(runProperties2);
2357+
run2.Append(text1);
2358+
2359+
Run run3 = new Run() { RsidRunProperties = "00812D6B" };
2360+
2361+
RunProperties runProperties3 = new RunProperties();
2362+
RunFonts runFonts5 = new RunFonts() { Hint = FontTypeHintValues.EastAsia, Ascii = "黑体", HighAnsi = "Times", EastAsia = "黑体" };
2363+
FontSize fontSize8 = new FontSize() { Val = "18" };
2364+
FontSizeComplexScript fontSizeComplexScript8 = new FontSizeComplexScript() { Val = "18" };
2365+
2366+
runProperties3.Append(runFonts5);
2367+
runProperties3.Append(fontSize8);
2368+
runProperties3.Append(fontSizeComplexScript8);
2369+
Text text2 = new Text();
2370+
text2.Text = title;
2371+
2372+
run3.Append(runProperties3);
2373+
run3.Append(text2);
2374+
2375+
Run run4 = new Run() { RsidRunProperties = "006039A8" };
2376+
2377+
RunProperties runProperties4 = new RunProperties();
2378+
RunFonts runFonts6 = new RunFonts() { Hint = FontTypeHintValues.EastAsia, Ascii = "黑体", EastAsia = "黑体" };
2379+
FontSize fontSize9 = new FontSize() { Val = "18" };
2380+
FontSizeComplexScript fontSizeComplexScript9 = new FontSizeComplexScript() { Val = "18" };
2381+
2382+
runProperties4.Append(runFonts6);
2383+
runProperties4.Append(fontSize9);
2384+
runProperties4.Append(fontSizeComplexScript9);
2385+
Text text3 = new Text() { Space = SpaceProcessingModeValues.Preserve };
2386+
text3.Text = " ";
2387+
2388+
run4.Append(runProperties4);
2389+
run4.Append(text3);
2390+
2391+
paragraph1.Append(paragraphProperties1);
2392+
paragraph1.Append(run1);
2393+
paragraph1.Append(run2);
2394+
paragraph1.Append(run3);
2395+
paragraph1.Append(run4);
2396+
2397+
header.Append(paragraph1);
2398+
2399+
headerPart.Header = header;
2400+
2401+
}
21492402
}
21502403
}

md2docx/md2docx.cs

Lines changed: 23 additions & 9 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)