xpoint = xinit + xinsert
ypoint = yinit - yinsert
If x = 1 Then
If ma.Borders(xlEdgeTop).LineStyle
<> xlNone Then
ptArray(0) = xpoint
‘第一点坐标(数组下标 0 and 1)
ptArray(1) = ypoint
ptArray(2) = xpoint + xh
‘第二点坐标(数组下标 2 and 3)
ptArray(3) = ypoint
End If
Lineweight lwployobj, ma.Borders(xlEdgeTop).Weight
End If
If ma.Borders(xlEdgeBottom).LineStyle
< > xlNone Then
ptArray(0) = xpoint + xh
‘第三点坐标(数组下标 0 and 1)
ptArray(1) = ypoint - yh
ptArray(2) = xpoint
‘第四点坐标(数组下标 2 and 3)
ptArray(3) = ypoint – yh
Lineweight lwployobj,
ma.Borders(xlEdgeBottom).Weight
End If
If y = 1 Then
If ma.Borders(xlEdgeLeft).LineStyle
< > xlNone Then
ptArray(0) = xpoint
‘第四点坐标(数组下标 0 and 1)
ptArray(1) = ypoint - yh
ptArray(2) = xpoint
‘第一点坐标(数组下标 2 and 3)
ptArray(3) = ypoint
利用VBA编程实现从EXCEL表到AUTOCAD表转换
End If
Lineweight lwployobj, ma.Borders(xlEdgeLeft).Weight
End If
If ma.Borders(xlEdgeRight).LineStyle
< > xlNone Then
ptArray(0) = xpoint + xh
‘第二点坐标(数组下标 0 and 1)
ptArray(1) = ypoint
ptArray(2) = xpoint + xh
‘第三点坐标(数组下标 2 and 3)
ptArray(3) = ypoint – yh
Lineweight lwployobj,
ma.Borders(xlEdgeRight).Weight
End If
Set lwployobj = moSpace.AddLightWeightPolyline(ptArray)
‘在AutoCAD文件里画线
With lwployobj
.Layer = ‘指定lwployobj所在图层
.Color = acBlue ‘指定lwployobj的颜色
End With
Lwployobj.Update
Next y
Next x
End Sub
‘下面程序控制线条粗细
Sub Lineweight(ByVal line As Object, u As Integer)
Select Case u
Case 1
Call line.SetWidth(0, 0.1, 0.1)
Case 2
Call line.SetWidth(0, 0.3, 0.3)
Case -4138
Call line.SetWidth(0, 0.5, 0.5)
Case 4
Call line.SetWidth(0, 1, 1)
Case Else
Call line.SetWidth(0, 0.1, 0.1)
End Select
End Sub
‘下面程序完成列号转换
Function zh(pp As Integer) As String
If pp < 26 Then
zh = Chr(64 + pp)
Else
利用VBA编程实现从EXCEL表到AUTOCAD表转换
zh = Chr(64 + Int(pp / 26)) + Chr(64 + pp Mod 26)
End If
End Function
---- 3、表格文字转换
---- 表格文字转换包括表格文字本身转换和表格文字在表格中位置的转换两个部分。
---- 在AutoCAD中,文字标注的形式有多种,与Microsoft Excel 单元格区域多行文本内容相对应的是多行文本命令。AutoCAD提供的VBA添加多行文本的命令语句是:
RetVal = object.AddMText(InsertionPoint, Width, Text)
---- 通过修改RetVal的属性可以控制表格文字在表格中的位置。
---- (1).表格文字本身的转换
---- 分析AddMText命令可以得出:表格文字所在位置、文字内容宽度,文字内容,均可通过此命令来添加。然而表格文字字体,大小,下划线、上下脚标,倾斜,加粗等却不能。一般的方法是采用修改字体形文件的方法来实现,方法烦琐,不便于实现,而且仅对修改过形文件的字体有效。况且当同一文字块内的不同文字的字体,大小,下划线、上下脚标,倾斜,加粗不同时,使用修改字体形文件的方法也无法实现。本文介绍一种直接利用Mtext命令提供的方法进行转换。
---- 在AddMText命令中,影响文字内容和文字属性的参数Text。在具体文字前加上一定的控制符号可以控制文字的文字属性,具体控制符号可以参阅AutoCAD帮助文件。例如,{\F宋体;\Q18;\W1.2;ABCDEFG}把“ABCDEFG”设置成宋体、向右倾斜18度,每个字的宽度是正常宽度1.2倍。
---- 本程序具体采用的方法是:读取Microsoft Excel文件某一单元格区域里的某第j个字符属性(字体,大小,下划线、上、下脚标,倾斜,加粗),读取Microsoft Excel文件某一单元格区域里的某第j+1个字符属性,如果与第j个字符相同,则二者采用同样的控制符号;若不同,则从第j+1个字符开始,重复前面的工作。
Sub wz ( )
Char = RTrim(Left(c.Characters.Caption, 256))
If Char < > Empty Then
textStr = ""
For j = 1 To Len(Char)
If c.Characters(j, 1).Font.Underline =
xlUnderlineStyleNone Then
cpt = c.Characters(j, 1).Caption
sonstr = ForeFontStr(c, j)
tempstr = ""
Do While j + 1 < = Len(Char)
利用VBA编程实现从EXCEL表到AUTOCAD表转换
sonstr1 = ForeFontStr(c, j + 1)
If sonstr1 = sonstr Then
j = j + 1
tempstr = tempstr + c.Characters(j,
1).Caption
Else
Exit Do
End If
Loop
textStr = textStr + "{" + sonstr + cpt
+ tempstr + "}"
Else
cpt = c.Characters(j, 1).Caption
sonstr = ForeFontStr(c, j)
tempstr = ""
Do While j + 1 < = Len(Char)
sonstr1 = ForeFontStr(c, j + 1)
If sonstr1 = sonstr Then
j = j + 1
tempstr = tempstr + c.Characters(j,
1).Caption
Else
Exit Do
End If
Loop
textStr = textStr + "{\L" +
sonstr + cpt + tempstr + "\l}"
End If
Next j