Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 MS Word、OpenXML、页面设置、方向和4_方向边距_C# 4.0_Ms Word_Openxml - Fatal编程技术网

C# 4.0 MS Word、OpenXML、页面设置、方向和4_方向边距

C# 4.0 MS Word、OpenXML、页面设置、方向和4_方向边距,c#-4.0,ms-word,openxml,C# 4.0,Ms Word,Openxml,我用OpenXML制作了这个文档。。我正在学习OpenXML。哦这太难了 MainDocumentPart m = wd.AddMainDocumentPart(); m.Document = new Document(); Body b1 = new Body(); int myCount = 5; for (int z = 1; z <= myCount; z++) { Paragraph p1 = new Paragraph(); Run r1 = new Run()

我用OpenXML制作了这个文档。。我正在学习OpenXML。哦这太难了

MainDocumentPart m = wd.AddMainDocumentPart();
m.Document = new Document();
Body b1 = new Body();
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);
但是,当我转到OpenXML领域时,情况就完全不同了

能给我一些提示吗

关于

您需要使用,以及这样的类:

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);
}
使用(WordprocessingDocument wd=WordprocessingDocument.Create(文件名,WordprocessingDocumentType.Document))
{
MainDocumentPart m=wd.AddMainDocumentPart();
m、 文件=新文件();
主体b1=新主体();
//支持方向和边距的新代码
SectionProperties sectProp=新的SectionProperties();
PageSize PageSize=new PageSize(){Width=16838U,Height=11906U,Orient=PageOrientionValues.横向};
PageMargin PageMargin=new PageMargin(){Top=720,Right=720U,Bottom=720,Left=720U};
sectProp.Append(页面大小);
sectProp.Append(页边距);
b1.追加(sectProp);
//结束新代码
int myCount=5;

对于(intz=1;z有效..是的..很好,真的很好.再次感谢@Jason我很高兴能帮上忙.啊..能再给我一点提示吗?啊.类似于“.ParagraphFormat.LineSpacingRule=wdlinespace”或“.ParagraphFormat.LineSpacing=10”“…我正在打字…抱歉…抱歉@Jason,我很困惑。我很乐意帮忙,但我不确定你在问什么?”?
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);
}