明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 950|回复: 0

急!如何把CAD中的数据导向已经存在的EXCEL文件中,并自动识别从第一行空行开始写数据

[复制链接]
发表于 2008-9-9 20:26:00 | 显示全部楼层 |阅读模式
急!如何把CAD中的数据导向已经存在的EXCEL文件中,并自动识别从第一行空行开始写数据.[br]

请教高手.如何把CAD中的数据导向已经存在的EXCEL文件中,并自动识别从第一行空行开始写数据.另外还要实现在用户选择线条时,提示用户输入材料的型号,写在EXCEL文件的某一列.以下是我的程序,但我不会实现这几个功能,请高手教教我,谢谢了.

Sub main()
    Dim line As AcadLine
    Dim ftype(0) As Integer
    Dim fdata(0) As Variant
    Dim xcl As excel.Application
    Dim xclsheet As Object
    Dim xclworkbook As Object
    Dim p1 As Variant
   
    'qsy
    p1 = ThisDrawing.Utility.GetPoint
   
   
   
    Dim sset As AcadSelectionSet
   
    Set sset = ThisDrawing.SelectionSets.Add("SelectLine")
   
    ftype(0) = 0
    fdata(0) = "Line"
   
    sset.SelectOnScreen ftype, fdata
   
    If sset.Count > 0 Then
       
        Set xcl = New excel.Application
        Set xclworkbook = xcl.Workbooks.Add
        Set xclsheet = xcl.ActiveSheet
       
        Dim I As Integer
        Dim center_x As Double
        Dim center_y As Double
        Dim center_z As Double
       
        I = 0
       
        For Each line In sset
            xclsheet.Cells(1, 1).Value = "Line Element"
            xclsheet.Cells(1, 2).Value = "Center Point X"
            xclsheet.Cells(1, 3).Value = "Center Point Y"
            xclsheet.Cells(1, 4).Value = "Center Point Z"
            xclsheet.Cells(1, 5).Value = "Length"
            'msg = MsgBox(Str(line.StartPoint(0)) & ":" & Str(line.StartPoint(1)) & ":" & Str(line.StartPoint(2)), _
                         vbOKOnly, _
                         "Name")
            I = I + 1
           
            center_x = (line.StartPoint(0) + line.EndPoint(0)) / 2 - p1(0)
            center_y = (line.StartPoint(1) + line.EndPoint(1)) / 2 - p1(1)
            center_z = (line.StartPoint(2) + line.EndPoint(2)) / 2 - p1(2)
            
            xclsheet.Cells(1 + I, 1).Value = I
            xclsheet.Cells(1 + I, 2).Value = center_x
            xclsheet.Cells(1 + I, 3).Value = center_y
            xclsheet.Cells(1 + I, 4).Value = center_z
            xclsheet.Cells(1 + I, 5).Value = line.Length
        Next
        xclworkbook.SaveAs "D:\sample3.xls"
        xcl.Quit
    End If
    sset.Delete
End Sub

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 07:31 , Processed in 0.142940 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表