C#分多次写入word

lbhqu 2013-09-03 10:42:44
我在winform里对word进行操作,首先创建一个新的word文档,再多次把一些内容写入到这个word里,每一次写入都在前一次写的文字的末尾进行追加,既不分段,也不分行(不用另起一段或一行再写入)。有哪位大神知道怎么写?敬请提供一些具体的C#代码。。。不甚感谢!
...全文
207 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2013-09-04
  • 打赏
  • 举报
回复
Application word = new Application(); Document doc = word.Documents.Open("file.doc"); doc.Range().Text += "add to range"; doc.Close();
jshi123 2013-09-04
  • 打赏
  • 举报
回复
右对齐:range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight; 左齐:WdParagraphAlignment.wdAlignParagraphLeft; 居中:WdParagraphAlignment.wdAlignParagraphCenter; 缩进:range.ParagraphFormat.IndentCharWidth(2); 操作看msdn啊:http://msdn.microsoft.com/en-us/library/Microsoft.Office.Interop.Word(v=office.11).aspx
lbhqu 2013-09-04
  • 打赏
  • 举报
回复
因为最终要进行排版,让它像一个正式的文章一样,所以第一行居中对齐,字体为红色,第二行两边对齐,并起行空两格,字体为黑色,等等。。。
lbhqu 2013-09-04
  • 打赏
  • 举报
回复
引用 3 楼 jshi123 的回复:
var range = doc.Range(); range.Collapse(WdCollapseDirection.wdCollapseEnd); range.Text = "add to range";
这个是对的,但是没办法对我输入的文字进行排版啊,比如文字对齐方式对左对齐右对齐等等
jshi123 2013-09-04
  • 打赏
  • 举报
回复
var range = doc.Range(); range.Collapse(WdCollapseDirection.wdCollapseEnd); range.Text = "add to range";
人生导师 2013-09-04
  • 打赏
  • 举报
回复
这个多测试就好了,主要是熟悉Word 对象模型了,具体也可以参考下面介绍: http://www.cnblogs.com/codingsilence/archive/2008/09/21/2146815.html http://www.cnblogs.com/zhili/archive/2013/03/18/OfficeAutomation.html
灬浪子灬 2013-09-04
  • 打赏
  • 举报
回复
在word中加标签
Andy__Huang 2013-09-04
  • 打赏
  • 举报
回复
我是用第三方控件写入word文件的, 第三方控件是:GemBox.Document document = DocumentModel.Load(tempFile, DocxLoadOptions.DocxDefault); document.MailMerge.Execute(new { ProfileNo = profileModel.ProfileNo }); foreach (Section sourceSection in sourceDocument.Sections) { Section destinationSection = document.Import(sourceSection, true, false); document.Sections.Add(destinationSection); } 有点和微软提供的不太一样,仅供参考

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧