获取MS word表rowspan和colspan [英] Get MS word Table rowspan and colspan
问题描述
大家好
我的单词doc中有一张表。我需要从vba代码中获取此表中单元格的rowspan和colspan值。因为我想在html doc中转换它。
如果表格很简单,即没有rowspan和colspan那么我没有问题。我使用此代码:
hi all
i have a table in my word doc. i need to get the rowspan and colspan values of cells in this table from the vba code. becouse i want to convert it in a html doc.
if table is simple i.e. there is no rowspan and colspan then i have no problem. i use this code :
Function replace_tables()
' convert simple tables (no merged cells!)
Dim oRow As Row
Dim oCell As Cell
Dim sCellText As String
Dim tTable As Table
Dim noRows, noCells As Long
'StatusBar = "Convert tables..."
For Each tTable In ActiveDocument.Tables
For Each oRow In tTable.Rows
For Each oCell In oRow.Cells
sCellText = oCell.Range
sCellText = Left$(sCellText, Len(sCellText) - 2)
If Len(sCellText) = 0 Then sCellText = " "
sCellText = "<td>" & sCellText & "</td>"
oCell.Range = sCellText
Next oCell
sCellText = oRow.Cells(1).Range
sCellText = Left$(sCellText, Len(sCellText) - 2)
sCellText = "<tr>" & vbCr & sCellText
oRow.Cells(1).Range = sCellText
sCellText = oRow.Cells(oRow.Cells.Count).Range
sCellText = Left$(sCellText, Len(sCellText) - 2)
sCellText = sCellText & vbCr & "</tr>"
oRow.Cells(oRow.Cells.Count).Range = sCellText
Next oRow
sCellText = tTable.Rows(1).Cells(1).Range
sCellText = Left$(sCellText, Len(sCellText) - 2)
sCellText = "<table>" & vbCr & sCellText
tTable.Rows(1).Cells(1).Range = sCellText
noRows = tTable.Rows.Count
noCells = tTable.Rows(noRows).Cells.Count
sCellText = tTable.Rows(noRows).Cells(noCells).Range
sCellText = Left$(sCellText, Len(sCellText) - 2)
sCellText = sCellText & vbCr & "</table>"
tTable.Rows(noRows).Cells(noCells).Range = sCellText
tTable.ConvertToText Separator:=wdSeparateByParagraphs
Next tTable
End Function
但我想要写一个已经合并了单元格的表的代码。
有人可以帮我解决这个问题..我正在网上搜索我昨晚的问题。所以请避免在解决方案中粘贴任何链接,因为我已经看过他们中的大部分。
but i want to write a code for table which has merged cells in it.
can somebody help me regarding this.. i am searching over the internet for my problem from last night.so please avoid pasting any link in solution, because i had already seen most of them.
推荐答案
(sCellText,Len(sCellText) - 2 )
如果 Len(sCellText)= 0 那么 sCellText =
sCellText = < td>& sCellText& < / td>
oCell.Range = sCellText
Next oCell
sCellText = oRow.Cells( 1 )。范围
sCellText = Left
(sCellText, Len(sCellText) - 2) If Len(sCellText) = 0 Then sCellText = " " sCellText = "<td>" & sCellText & "</td>" oCell.Range = sCellText Next oCell sCellText = oRow.Cells(1).Range sCellText = Left
(sCellText,Len(sCellText) - 2 )
sCellText = < tr>& vbCr& sCellText
oRow.Cells( 1 )。Range = sCellText
sCellText = oRow.Cells(oRow.Cells.Count).Range
sCellText =左
(sCellText, Len(sCellText) - 2) sCellText = "<tr>" & vbCr & sCellText oRow.Cells(1).Range = sCellText sCellText = oRow.Cells(oRow.Cells.Count).Range sCellText = Left
(sCellText,Len(sCellText) - 2 )
sCellText = sCellText& vbCr& < / tr>
oRow.Cells(oRow.Cells.Count)。范围= sCellText
下一步 oRow
sCellText = tTable.Rows( 1 )。单元格( 1 )。范围
sCellText =左
(sCellText, Len(sCellText) - 2) sCellText = sCellText & vbCr & "</tr>" oRow.Cells(oRow.Cells.Count).Range = sCellText Next oRow sCellText = tTable.Rows(1).Cells(1).Range sCellText = Left
这篇关于获取MS word表rowspan和colspan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!