wenwengg 发表于 2007-10-30 13:01:00
<p>Public xlApp As Excel.Application<br/>Public xlWork As Excel.Workbook<br/>Public xlSheet As Excel.Worksheet</p><p>Function OpenExcel() As Boolean<br/> On Error Resume Next<br/> If xlApp Is Nothing Then<br/> Set xlApp = GetObject(, "Excel.Application")<br/> End If<br/> If xlApp Is Nothing Then<br/>' Set xlApp = GetObject(, "Excel.Application")<br/>' If Err.Number <> 0 Then<br/> On Error GoTo OpenExcelFaild<br/> Set xlApp = CreateObject("Excel.Application")<br/> End If<br/> OpenExcel = True<br/> Exit Function<br/>OpenExcelFaild:<br/> OpenExcel = False<br/>End Function</p><p><br/>Private Sub cmdPickup_Click()<br/> On Error Resume Next<br/> ThisDrawing.SelectionSets.Item("sHLine").Delete<br/> ThisDrawing.SelectionSets.Item("sVLine").Delete<br/> ThisDrawing.SelectionSets.Item("ss").Delete<br/> On Error GoTo 0<br/> Dim pt(0 To 2) As Double, pt1(0 To 2) As Double<br/> Dim seldata(0) As Variant, selcode(0) As Integer<br/> Dim gpdata As Variant, gpcode As Variant<br/> Dim ret As Variant<br/> Dim sel As AcadSelectionSet<br/> Dim shl As AcadSelectionSet, svl As AcadSelectionSet<br/> Dim i As Long, j As Long<br/> Dim obj As AcadEntity, objLine As AcadLine<br/> Dim minpt As Variant, maxpt As Variant<br/> Dim addobj(0) As AcadEntity<br/> Dim x As Double, y As Double, x0 As Double<br/> Dim x1 As Double, y1 As Double<br/> Dim n1 As Long, n2 As Long<br/> Dim s As String, np As Long, nf As Long<br/> With ThisDrawing<br/> Me.Hide<br/> ret = .Utility.GetPoint(, "指定左上角:")<br/> SetRet ret, pt<br/> ret = .Utility.GetCorner(pt, "指定对角点:")<br/> SetRet ret, pt1<br/> Set sel = .SelectionSets.Add("ss")<br/> selcode(0) = 0: gpcode = selcode<br/> seldata(0) = "Line": gpdata = seldata<br/> sel.Select acSelectionSetCrossing, pt, pt1, gpcode, gpdata<br/> lv.ListItems.Clear<br/> lv.ColumnHeaders.Clear<br/> Set shl = .SelectionSets.Add("sHLine")<br/> Set svl = .SelectionSets.Add("sVLine")<br/> For Each obj In sel<br/> obj.GetBoundingBox minpt, maxpt<br/> Set addobj(0) = obj<br/> If Abs(minpt(0) - maxpt(0)) > Abs(minpt(1) - maxpt(1)) Then<br/> shl.AddItems addobj<br/> Else<br/> svl.AddItems addobj<br/> End If<br/> Next<br/> Sort shl, 0<br/> Sort svl, 1<br/> n1 = shl.count<br/> n2 = svl.count<br/> lb.Caption = "选择了" & vbCrLf & n1 & "行水平线" & vbCrLf & n2 & "行垂直线"<br/> If n1 > 0 And n2 > 0 Then<br/> For i = 1 To n2<br/> lv.ColumnHeaders.Add , , "col" & i<br/> Next<br/> lv.ColumnHeaders.Item(1).Text = "No."<br/> lv.ColumnHeaders.Item(1).Width = 30<br/> Set obj = svl.Item(0)<br/> obj.GetBoundingBox minpt, maxpt<br/> x0 = minpt(0)<br/> If x0 > pt(0) Then<br/> lv.ColumnHeaders.Add , , "col" & lv.ColumnHeaders.count + 1<br/> np = 1<br/> x0 = pt(0)<br/> End If<br/> Set obj = svl.Item(n2 - 1)<br/> obj.GetBoundingBox minpt, maxpt<br/> x = minpt(0)<br/> If x < pt1(0) Then<br/> lv.ColumnHeaders.Add , , "col" & lv.ColumnHeaders.count + 1<br/> nf = 1<br/> End If<br/> x = x0<br/> Set obj = shl.Item(0)<br/> obj.GetBoundingBox minpt, maxpt<br/> y = minpt(1)<br/> For i = 1 To n1 - 1<br/> lv.ListItems.Add , , i<br/> Set obj = shl.Item(i)<br/> obj.GetBoundingBox minpt, maxpt<br/> y1 = minpt(1)<br/> If np = 1 Then<br/> Set obj = svl.Item(0)<br/> obj.GetBoundingBox minpt, maxpt<br/> x1 = minpt(0)<br/> s = GetText(x, y, x1, y1)<br/> lv.ListItems(i).SubItems(1) = s<br/> x = x1<br/> End If<br/> For j = 1 To n2 - 1<br/> Set obj = svl.Item(j)<br/> obj.GetBoundingBox minpt, maxpt<br/> x1 = minpt(0)<br/> s = GetText(x, y, x1, y1)<br/> lv.ListItems(i).SubItems(j + np) = s<br/> x = x1<br/> Next<br/> If nf = 1 Then<br/> x1 = pt1(0)<br/> s = GetText(x, y, x1, y1)<br/> lv.ListItems(i).SubItems(j + np) = s<br/> End If<br/> Debug.Print<br/> x = x0<br/> y = y1<br/> Next<br/> End If<br/> <br/> .SelectionSets.Item("sHLine").Delete<br/> .SelectionSets.Item("sVLine").Delete<br/> .SelectionSets.Item("ss").Delete<br/> Me.Show<br/> <br/> End With<br/>End Sub<br/></p>wenwengg 发表于 2007-10-30 13:04:00
wenwengg 发表于 2007-10-30 13:05:00
已经取消了密码jubuhui 发表于 2007-11-9 15:06:00
很好,有点遗憾的是代码是vb编写,而不是vc,只好动手转成vcstyle6301 发表于 2007-11-14 14:29:00
<p><font color="#ff0066">请大家看一下贴子:《<strong>怎么样才能通过VBA程序将这些统计数据写入DBF文件中。(已建有相同字段的D:\CYC\DeckP.dbf文件)</strong>》</font></p><p><font color="#ff0066">帮忙解决一下燃眉之急,谢谢!</font></p>surveyhpu 发表于 2007-11-22 11:34:00
<p>很不错,只是有点遗憾,在单元格边线错开时,提取出来的文本就重复读取。</p>兰州人 发表于 2007-12-25 14:40:00
<p>专门研究此帖子。</p>745016342 发表于 2008-3-15 14:34:00
hhhhhhhhhtaizih 发表于 2008-4-26 13:50:00
好东西 ,学习 向楼主的无私致敬haifeng168 发表于 2008-6-17 07:57:00
<p>改进一下那就更好了,呵呵</p>