急!如何把CAD中的数据导向已经存在的EXCEL文件中,并自动识别从第一行空行开始写数据
急!如何把CAD中的数据导向已经存在的EXCEL文件中,并自动识别从第一行空行开始写数据.<p>请教高手.如何把CAD中的数据导向已经存在的EXCEL文件中,并自动识别从第一行空行开始写数据.另外还要实现在用户选择线条时,提示用户输入材料的型号,写在EXCEL文件的某一列.以下是我的程序,但我不会实现这几个功能,请高手教教我,谢谢了.</p><p></p><p>Sub main()<br/> Dim line As AcadLine<br/> Dim ftype(0) As Integer<br/> Dim fdata(0) As Variant<br/> Dim xcl As excel.Application<br/> Dim xclsheet As Object<br/> Dim xclworkbook As Object<br/> Dim p1 As Variant<br/> <br/> 'qsy<br/> p1 = ThisDrawing.Utility.GetPoint<br/> <br/> <br/> <br/> Dim sset As AcadSelectionSet<br/> <br/> Set sset = ThisDrawing.SelectionSets.Add("SelectLine")<br/> <br/> ftype(0) = 0<br/> fdata(0) = "Line"<br/> <br/> sset.SelectOnScreen ftype, fdata<br/> <br/> If sset.Count > 0 Then<br/> <br/> Set xcl = New excel.Application<br/> Set xclworkbook = xcl.Workbooks.Add<br/> Set xclsheet = xcl.ActiveSheet<br/> <br/> Dim I As Integer<br/> Dim center_x As Double<br/> Dim center_y As Double<br/> Dim center_z As Double<br/> <br/> I = 0<br/> <br/> For Each line In sset<br/> xclsheet.Cells(1, 1).Value = "Line Element"<br/> xclsheet.Cells(1, 2).Value = "Center Point X"<br/> xclsheet.Cells(1, 3).Value = "Center Point Y"<br/> xclsheet.Cells(1, 4).Value = "Center Point Z"<br/> xclsheet.Cells(1, 5).Value = "Length"<br/> 'msg = MsgBox(Str(line.StartPoint(0)) & ":" & Str(line.StartPoint(1)) & ":" & Str(line.StartPoint(2)), _<br/> vbOKOnly, _<br/> "Name")<br/> I = I + 1<br/> <br/> center_x = (line.StartPoint(0) + line.EndPoint(0)) / 2 - p1(0)<br/> center_y = (line.StartPoint(1) + line.EndPoint(1)) / 2 - p1(1)<br/> center_z = (line.StartPoint(2) + line.EndPoint(2)) / 2 - p1(2)<br/> <br/> xclsheet.Cells(1 + I, 1).Value = I<br/> xclsheet.Cells(1 + I, 2).Value = center_x<br/> xclsheet.Cells(1 + I, 3).Value = center_y<br/> xclsheet.Cells(1 + I, 4).Value = center_z<br/> xclsheet.Cells(1 + I, 5).Value = line.Length<br/> Next<br/> xclworkbook.SaveAs "D:\sample3.xls"<br/> xcl.Quit<br/> End If<br/> sset.Delete<br/>End Sub</p>
页:
[1]