如何使用C#操作Word的文字格式居中或左右对齐
2个回答
展开全部
oPara1.Range.Text="我需要居中"; //插入文本
oPara1.Range.ParagraphFormat.Alignment =Word.WdParagraphAlignment.wdAlignParagraphCenter; //我的意图是让这段文字居中,但这样做是不行的
把这两句调换顺序试试……
如果不行的话,我的写法是这样的:
Object Nothing = System.Reflection.Missing.Value;
worddoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
worddoc.Paragraphs.Last.Range.Text = "我需要居中";
worddoc.Paragraphs.Add(ref Nothing);
worddoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
worddoc.Paragraphs.Last.Range.Text = "我需要右对齐";
oPara1.Range.ParagraphFormat.Alignment =Word.WdParagraphAlignment.wdAlignParagraphCenter; //我的意图是让这段文字居中,但这样做是不行的
把这两句调换顺序试试……
如果不行的话,我的写法是这样的:
Object Nothing = System.Reflection.Missing.Value;
worddoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
worddoc.Paragraphs.Last.Range.Text = "我需要居中";
worddoc.Paragraphs.Add(ref Nothing);
worddoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
worddoc.Paragraphs.Last.Range.Text = "我需要右对齐";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |