C# word的一些操作问题

lyyttcc202 2010-08-20 09:20:49
//创建word文档
Word.ApplicationClass WordApp = new Word.ApplicationClass();
Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordDoc.Paragraphs.First.Range.Text = "aaa";
//文档中创建表格
Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 7 , 5 , ref Nothing, ref Nothing);

我创建了一个word,添加了一个标题,标题名称为“aaa”,还创建了一个表格,为什么标题出现在表格的下面,而不是位于正上方,我的代码有什么问题吗,初学C#,求大家帮忙,谢谢了!!
...全文
150 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-08-20
  • 打赏
  • 举报
回复
using Word = Microsoft.Office.Interop.Word;
object routeDocument = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word._Document Doc = app.Documents.Open(ref sFile, ref optional, ref docreadonly, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref visible, ref optional, ref optional, ref optional, ref optional);
Name书签名称
if (Doc.Bookmarks.Exists("a"))
{
object WdLine = Word.WdUnits.wdLine;
object oEndOfDoc = "a";
Word.Range oRng = Doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Word.Table tb = Doc.Tables.Add(oRng, 1, 2, ref nothing, ref nothing);
tb.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;
tb.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
tb.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
}
lyyttcc202 2010-08-20
  • 打赏
  • 举报
回复
没看懂什么意思啊,可以解释下吗
wuyq11 2010-08-20
  • 打赏
  • 举报
回复
WORD中插入 书签
if (Doc.Bookmarks.Exists("Name"))
{
object b1 = "Name";
Word.Bookmark bk1 = Doc.Bookmarks.get_Item(ref b1);
bk1.Range.Text ="";
}
lyyttcc202 2010-08-20
  • 打赏
  • 举报
回复
具体怎么操作呢,怎么添加书签??
wuyq11 2010-08-20
  • 打赏
  • 举报
回复
在WORD中添加书签
通过书签位置添加标题和table

110,534

社区成员

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

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

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