2026-05-20 21:39:12 +08:00

60 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#r "nuget: DocumentFormat.OpenXml, 3.2.0"
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
string outputPath = @"C:\Users\Administrator\Desktop\xxx\宫崎骏介绍.docx";
using var doc = WordprocessingDocument.Create(outputPath, WordprocessingDocumentType.Document);
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document(new Body());
var body = mainPart.Document.Body;
// Title
var titlePara = new Paragraph(
new ParagraphProperties(
new Justification { Val = JustificationValues.Center },
new SpacingBetweenLines { After = "400" }
),
new Run(
new RunProperties(
new Bold(),
new FontSize { Val = "36" },
new FontSizeComplexScript { Val = "36" }
),
new Text("宫崎骏")
)
);
body.Append(titlePara);
// Content - approximately 200 Chinese characters
string content = "宫崎骏Hayao Miyazaki日本著名动画导演、漫画家1941年出生于东京。他被誉为“日本动画之父”其作品以精美的画面、深邃的想象力和对人与自然关系的思考而闻名于世。代表作包括《千与千寻》《龙猫》《天空之城》《幽灵公主》《哈尔的移动城堡》等多次获得日本电影金像奖最佳影片及国际动画奖项。他的动画充满童真与诗意传递和平、环保与爱的主题影响了全球无数观众。";
var contentPara = new Paragraph(
new ParagraphProperties(
new Justification { Val = JustificationValues.Both },
new SpacingBetweenLines { After = "200", Line = "360", LineRule = LineSpacingRuleValues.Auto }
),
new Run(
new RunProperties(
new FontSize { Val = "24" },
new FontSizeComplexScript { Val = "24" },
new RunFonts { Ascii = "SimSun", HighAnsi = "SimSun", EastAsia = "SimSun" }
),
new Text(content)
)
);
body.Append(contentPara);
// Section properties (A4)
body.Append(new SectionProperties(
new PageSize { Width = 11906, Height = 16838 },
new PageMargin { Top = 1440, Right = 1440, Bottom = 1440, Left = 1440 }
));
mainPart.Document.Save();
Console.WriteLine($"Document created: {outputPath}");
Console.WriteLine($"Character count: {content.Length}");