不能用tables属性集合判断啊。 我要拓扑结构一样就行了,cell(单元格)大小是否相同都可以不考虑。 我现在用的是对比Character(字符)的形式比较的, 因为有格的地方char是chr(13)也就是空格, 所以大概能比较出来,有没有更好的方法?? 我的方法是:(VBScript)Sub a() Dim a As Table Dim b As Table Dim strA As String Dim strB As String Dim x As Boolean Set a = ActiveDocument.Tables(1) Set b = ActiveDocument.Tables(2) Dim l As Long x = True Dim c As Cell For Each c In a.Range.Cells c.Range.Text = "1" Next c For Each c In b.Range.Cells c.Range.Text = "1" Next c For l = 1 To a.Range.Characters.Count On Error Resume Next If (a.Range.Characters(l).Text <> b.Range.Characters(l).Text) Then x = False Exit For End If On Error GoTo 0 Next l If x Then MsgBox "same" Else MsgBox "不same" End Sub
你怎么也不应该用CELLS集会啊。 要拓扑相同,你应该这样: private function CompTab() as boolean dim i as integer,dim j as integer dim n as integer,dim k as integer '==如果行数都不同,一定不同 if table1.rows.count <> table2.rows.count then comtab=false exit function end if '==如果列数都不同,一定不同 if table1.Columns.count <> table2.Columns.count then comtab=false exit function end if'==再比较 for i=0 to table1.rows.count-1 for j=0 to table1.rows(i).cells.count-1 if table1.rows(i).cells(j).width=table2.rows(i).cells(j) then '==这是完全相同的情况 else '==如果宽不一样,你要考虑表格“错位”的情况 '==这种情况下,你要对第二个表的同列不同行的CELL进行比较 '==总之是一堆for 和 if啦。 end if next next快,分来。
不是让你挨个WIDTH去比,真是有够....的。 好吧,我把中间的代码补齐: dim i as integer,j as integer dim n as integer,k as integer '==判断是不是错位了 for i=0 to table1.columns.count-2 for j=0 to table1.columns(i).cells.count-1 if table1.columns(i).cells(j).width<> table1.columns(i).cells(j).width then '==同列不同行的宽度不同,就是意味着错位 ..... next next
使用 Add 方法可以在指定范围内新增一表格。下例在活动文档的起始处添加一 3 x 4 表格。Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:=4是不是可以通过比较TABLES属性来判断!
Tables 属性
返回一个 Tables 集合,该集合代表指定的单元格、文档、区域、所选内容或表格中的所有表格。只读。有关返回集合中单个成员的内容,请参阅返回集合中的对象。
我要拓扑结构一样就行了,cell(单元格)大小是否相同都可以不考虑。
我现在用的是对比Character(字符)的形式比较的,
因为有格的地方char是chr(13)也就是空格,
所以大概能比较出来,有没有更好的方法??
我的方法是:(VBScript)Sub a()
Dim a As Table
Dim b As Table
Dim strA As String
Dim strB As String
Dim x As Boolean
Set a = ActiveDocument.Tables(1)
Set b = ActiveDocument.Tables(2)
Dim l As Long
x = True
Dim c As Cell
For Each c In a.Range.Cells
c.Range.Text = "1"
Next c
For Each c In b.Range.Cells
c.Range.Text = "1"
Next c
For l = 1 To a.Range.Characters.Count
On Error Resume Next
If (a.Range.Characters(l).Text <> b.Range.Characters(l).Text) Then
x = False
Exit For
End If
On Error GoTo 0
Next l
If x Then MsgBox "same" Else MsgBox "不same"
End Sub
要拓扑相同,你应该这样:
private function CompTab() as boolean
dim i as integer,dim j as integer
dim n as integer,dim k as integer
'==如果行数都不同,一定不同
if table1.rows.count <> table2.rows.count then
comtab=false
exit function
end if
'==如果列数都不同,一定不同
if table1.Columns.count <> table2.Columns.count then
comtab=false
exit function
end if'==再比较
for i=0 to table1.rows.count-1
for j=0 to table1.rows(i).cells.count-1
if table1.rows(i).cells(j).width=table2.rows(i).cells(j) then
'==这是完全相同的情况
else
'==如果宽不一样,你要考虑表格“错位”的情况
'==这种情况下,你要对第二个表的同列不同行的CELL进行比较
'==总之是一堆for 和 if啦。
end if
next
next快,分来。
所以用widht对比需要判断的可能性太多。
我用的代码虽然不正规但是能比出来啊。
我看了省里一个局域网考试系统(天知道谁做的)里面题库只给出了一个
几行几列的二值集和行数列树。
比如题:
row3colume510010
11100
01100类似于这样的,
所以我想一定有什么可以对比每一行的竖直线的,
省里的那个程序对比不了横线~表格的线有没有属性???
好吧,我把中间的代码补齐: dim i as integer,j as integer
dim n as integer,k as integer
'==判断是不是错位了
for i=0 to table1.columns.count-2
for j=0 to table1.columns(i).cells.count-1
if table1.columns(i).cells(j).width<> table1.columns(i).cells(j).width then
'==同列不同行的宽度不同,就是意味着错位
.....
next
next
一旦错位,你的所谓“拓扑相同”就又会出问题,不信你就画两个表格看看。至于你说的题目是有一个前提的:数据结构是树,可以自己设计,现在你必须
使用MS设计的结构,就这样。
其实什么拓扑数据结构什么的我都不会啊。
我在沈阳师范你想想一个师范学校会好哪里去。
我只是不习惯上课啊~
呵呵,谢谢你帮忙啊!
我给学校做的Office上机考试的东西,
他们不给我钱~呵呵。