你需要使用
SectionProperties
,
PageSize
和
PageMargin
using (WordprocessingDocument wd = WordprocessingDocument.Create(filename, WordprocessingDocumentType.Document))
{
MainDocumentPart m = wd.AddMainDocumentPart();
m.Document = new Document();
Body b1 = new Body();
//new code to support orientation and margins
SectionProperties sectProp = new SectionProperties();
PageSize pageSize = new PageSize() { Width = 16838U, Height = 11906U, Orient = PageOrientationValues.Landscape };
PageMargin pageMargin = new PageMargin() { Top = 720, Right = 720U, Bottom = 720, Left = 720U };
sectProp.Append(pageSize);
sectProp.Append(pageMargin);
b1.Append(sectProp);
//end new code
int myCount = 5;
for (int z = 1; z <= myCount; z++)
{
Paragraph p1 = new Paragraph();
Run r1 = new Run();
Text t1 = new Text(
"The Quick Brown Fox Jumps Over The Lazy Dog " + z);
r1.Append(t1);
p1.Append(r1);
b1.Append(p1);
}
m.Document.Append(b1);
}