C# 报错 This method or property is not available because this command is not avaibleTable newTable = wordDoc.Tables.Add(range,rows,columns,ref miss,ref miss);错误代码如上,求大侠指教啊如果是什么代码多时,为什么同学的机子
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/27 00:01:48
![C# 报错 This method or property is not available because this command is not avaibleTable newTable = wordDoc.Tables.Add(range,rows,columns,ref miss,ref miss);错误代码如上,求大侠指教啊如果是什么代码多时,为什么同学的机子](/uploads/image/z/14052584-56-4.jpg?t=C%23+%E6%8A%A5%E9%94%99+This+method+or+property+is+not+available+because+this+command+is+not+avaibleTable+newTable+%3D+wordDoc.Tables.Add%28range%2Crows%2Ccolumns%2Cref+miss%2Cref+miss%29%3B%E9%94%99%E8%AF%AF%E4%BB%A3%E7%A0%81%E5%A6%82%E4%B8%8A%2C%E6%B1%82%E5%A4%A7%E4%BE%A0%E6%8C%87%E6%95%99%E5%95%8A%E5%A6%82%E6%9E%9C%E6%98%AF%E4%BB%80%E4%B9%88%E4%BB%A3%E7%A0%81%E5%A4%9A%E6%97%B6%2C%E4%B8%BA%E4%BB%80%E4%B9%88%E5%90%8C%E5%AD%A6%E7%9A%84%E6%9C%BA%E5%AD%90)
C# 报错 This method or property is not available because this command is not avaibleTable newTable = wordDoc.Tables.Add(range,rows,columns,ref miss,ref miss);错误代码如上,求大侠指教啊如果是什么代码多时,为什么同学的机子
C# 报错 This method or property is not available because this command is not avaible
Table newTable = wordDoc.Tables.Add(range,rows,columns,ref miss,ref miss);
错误代码如上,求大侠指教啊
如果是什么代码多时,为什么同学的机子可以运行.求正确的才C#操作word代码,插入表格方法
C# 报错 This method or property is not available because this command is not avaibleTable newTable = wordDoc.Tables.Add(range,rows,columns,ref miss,ref miss);错误代码如上,求大侠指教啊如果是什么代码多时,为什么同学的机子
版本问题,是不是你们俩 一个是 office2010 另一个是 2003或者2007?
给你个2010调用的例子.研究下吧
//Be sure to add this reference:
//Project>Add Reference>.NET tab>Microsoft.Office.Interop.Word
//open Word App
Microsoft.Office.Interop.Word.Application msWord = new Microsoft.Office.Interop.Word.Application();
//make it visible or it'll stay running in the background
msWord.Visible = true;
//open a new document based on the Word template.
//You shouldn't open the template directly using msWord.Documents.Open(path) unless you want to edit the template itself.
Microsoft.Office.Interop.Word.Document wordDoc = msWord.Documents.Add(@"c:\MyTemplate.dotx");
//find the bookmark
string bookmarkName = "BookmarkToFind";
if (wordDoc.Bookmarks.Exists(bookmarkName))
{
Microsoft.Office.Interop.Word.Bookmark bk = wordDoc.Bookmarks[bookmarkName];
//set the document's range to immediately after the bookmark.
//If you want to add the table *into* the bookmark, it needs to be done differently.
//This page has a good explanation of the differences between adding to the bookmark's range vs adding after the bookmark's range.
//http://gregmaxey.mvps.org/word_tip_pages/insert_text_at_or_in_bookmark.html
//It's a little more hassle because you have to re-add the bookmark after inserting into it,
//so inserting after the bookmark is usually fine less you're going to be inserting text programmatically at the same bookmark a second time.
Microsoft.Office.Interop.Word.Range rng = wordDoc.Range(bk.Range.End, bk.Range.End);
//create a table with 8 rows and 5 columns into the range.
Microsoft.Office.Interop.Word.Table tbl = wordDoc.Tables.Add(rng, 8, 5);
//set the table's borders.
tbl.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
tbl.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
//merge the cells in the first row down to 2 columns (Word's cells start at 1, not at 0).
tbl.Cell(1, 1).Merge(tbl.Cell(1, 3));
//distribute the columns evenly
tbl.Rows[1].Select();
msWord.Selection.Cells.DistributeWidth();
//rows 2-5 already have 5 columns so don't touch them.
//merge rows 6-8 into single-columns rows.
for (int x = 6; x < 9; x++)
{
tbl.Cell(x,1).Merge(tbl.Cell(x,5));
}
//put the cursor in the table's first cell.
rng=wordDoc.Range(tbl.Cell(1,1).Range.Start, tbl.Cell(1,1).Range.Start);
rng.Select();