当前位置:编程学习 > C#/ASP.NET >>

wordDoc.Tables.Item(1).Rows问题

 wordDoc.Tables.Item(1).Range.Font.Name = "宋体"
“Word.Table”并不包含“Item”的定义
如何解决 --------------------编程问答-------------------- wordDoc.Tables[i].item试下 --------------------编程问答--------------------  我现在也是这个问题,等待高人来解决咯、、、 --------------------编程问答-------------------- C#调用WORD时出错如下:               object missingValue = Type.Missing;                object location = strInfo.Length; //如果location超过已有字符的长度将会出错。一定要比"明细表"串多一个字符                  Word.Range rng2 = wordDoc.Range(ref location, ref location);                                wordDoc.Tables.Add(rng2, 14, 6, ref missingValue, ref missingValue);                wordDoc.Tables.Item(1).Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast;//错误在这里 “Word.Tables”并不包含“Item”的定义                wordDoc.Tables.Item(1).Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//错误在这里“Word.Tables”并不包含“Item”的定义                wordDoc.Tables.Item(1).Range.Font.Size = 10;//错误在这里“Word.Tables”并不包含“Item”的定义                wordDoc.Tables.Item(1).Range.Font.Name = "宋体";//错误在这里“Word.Tables”并不包含“Item”的定义


解决办法:1、填加引用:Microsoft Office 11.0 Object Library ;2、把Tables.Item(1)改成Tables[1]。
 
--------------------编程问答--------------------
object oFileName = @"C:\Documents and Settings\liush\My Documents\TestDoc.doc";
object oReadOnly = true;
object oMissing = System.Reflection.Missing.Value;

Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;//只是为了方便观察
oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

//MessageBox.Show(oDoc.Tables.Count.ToString());
for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
{
    Word.Table nowTable = oDoc.Tables.Item(tablePos);
    string tableMessage = string.Format("第{0}/{1}个表:\n", tablePos, oDoc.Tables.Count);

    for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
    {
for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
{
tableMessage += nowTable.Cell(rowPos, columPos).Range.Text;
tableMessage = tableMessage.Remove(tableMessage.Length - 2, 2);//remove \r\a
tableMessage += "\t";
}

tableMessage += "\n";
    }

    MessageBox.Show(tableMessage);
}

http://edu.itbulo.com/200608/104129.htm
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,