明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2587|回复: 4

求助!!根据excel表格中的数据画多段线问题。

[复制链接]
发表于 2011-11-7 15:37:57 | 显示全部楼层 |阅读模式
  引用excel表格中的第一列数据画多段线,具体代码如下:Public Sub licheng()


Dim excelApp As Excel.Application
    Dim excelSheet As Excel.Worksheet
    Dim strFile As String
    strFile = ThisDrawing.Application.VBE.ActiveVBProject.fileName
    Set excelApp = CreateObject("Excel.Application")
    excelApp.Visible = True
    excelApp.Workbooks.Open Left$(strFile, Len(strFile) - Len("ex01.dvb")) & "\Excel\demo.xls"
    Set excelSheet = excelApp.ActiveWorkbook.Sheets("Sheet1")

  
  Dim i As Integer, j As Integer, k As Integer
For j = 1 To 9
  For i = 1 To 9

  Dim mspace As New clsModelSpace
  Dim lichengzx As AcadLWPolyline

  Dim lichengzxpoints(1 To 20) As Double
  Dim b As Single, a As Single
  b = excelSheet.Cells(1, 1).Value - 910
  a = excelSheet.Cells(j, 1).Value - b
  
lichengzxpoints(i * 2 - 1) = a
  lichengzxpoints(i * 2) = 245
    Next i
   Next j

  
    Set lichengzx = mspace.AddLWPolyline(lichengzxpoints, True, 0)
   
    ZoomAll
   
    ' 退出Excel应用程序
    excelApp.Quit
End Sub
图框有固定的点位,里程标注线想弄成固定点位,起始点为(910,245),按我的想法,应该lichengzxpoints(1)=910,lichengzxpoints(2)=245,以此类推,但是运行程序后出现起始点(0,0)点,终点为(1620,245)的斜线,不知道哪里出错了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2011-11-7 23:04:30 | 显示全部楼层
Dim mspace As New clsModelSpace
  Dim lichengzx As AcadLWPolyline

  Dim lichengzxpoints(1 To 20) As Double
  Dim b As Single, a As Single
应放在循环体之前

 楼主| 发表于 2011-11-8 09:22:32 | 显示全部楼层
yshf 发表于 2011-11-7 23:04
Dim mspace As New clsModelSpace
  Dim lichengzx As AcadLWPolyline

谢谢,不过我放到循环体前面了,但是程序运行后还是老样子,是什么情况呢?
发表于 2011-11-8 21:58:06 | 显示全部楼层
本帖最后由 yshf 于 2011-11-8 22:01 编辑

那九行到底是多少点的数据,按你的二层循环,得到的数据如下:
i=1  j=1  lichengzxpoints(1)=910
i=1  j=1  lichengzxpoints(2)=245
i=2  j=1  lichengzxpoints(3)=910
i=2  j=1  lichengzxpoints(4)=245
i=3  j=1  lichengzxpoints(5)=910
i=3  j=1  lichengzxpoints(6)=245
i=4  j=1  lichengzxpoints(7)=910
i=4  j=1  lichengzxpoints(8)=245
i=5  j=1  lichengzxpoints(9)=910
i=5  j=1  lichengzxpoints(10)=245
i=6  j=1  lichengzxpoints(11)=910
i=6  j=1  lichengzxpoints(12)=245
i=7  j=1  lichengzxpoints(13)=910
i=7  j=1  lichengzxpoints(14)=245
i=8  j=1  lichengzxpoints(15)=910
i=8  j=1  lichengzxpoints(16)=245
i=9  j=1  lichengzxpoints(17)=910
i=9  j=1  lichengzxpoints(18)=245

i=1  j=2  lichengzxpoints(1)=920
i=1  j=2  lichengzxpoints(2)=245
i=2  j=2  lichengzxpoints(3)=920
i=2  j=2  lichengzxpoints(4)=245
i=3  j=2  lichengzxpoints(5)=920
i=3  j=2  lichengzxpoints(6)=245
i=4  j=2  lichengzxpoints(7)=920
i=4  j=2  lichengzxpoints(8)=245
i=5  j=2  lichengzxpoints(9)=920
i=5  j=2  lichengzxpoints(10)=245
i=6  j=2  lichengzxpoints(11)=920
i=6  j=2  lichengzxpoints(12)=245
i=7  j=2  lichengzxpoints(13)=920
i=7  j=2  lichengzxpoints(14)=245
i=8  j=2  lichengzxpoints(15)=920
i=8  j=2  lichengzxpoints(16)=245
i=9  j=2  lichengzxpoints(17)=920
i=9  j=2  lichengzxpoints(18)=245

i=1  j=3  lichengzxpoints(1)=925
i=1  j=3  lichengzxpoints(2)=245
i=2  j=3  lichengzxpoints(3)=925
i=2  j=3  lichengzxpoints(4)=245
i=3  j=3  lichengzxpoints(5)=925
i=3  j=3  lichengzxpoints(6)=245
i=4  j=3  lichengzxpoints(7)=925
i=4  j=3  lichengzxpoints(8)=245
i=5  j=3  lichengzxpoints(9)=925
i=5  j=3  lichengzxpoints(10)=245
i=6  j=3  lichengzxpoints(11)=925
i=6  j=3  lichengzxpoints(12)=245
i=7  j=3  lichengzxpoints(13)=925
i=7  j=3  lichengzxpoints(14)=245
i=8  j=3  lichengzxpoints(15)=925
i=8  j=3  lichengzxpoints(16)=245
i=9  j=3  lichengzxpoints(17)=925
i=9  j=3  lichengzxpoints(18)=245

i=1  j=4  lichengzxpoints(1)=1031
i=1  j=4  lichengzxpoints(2)=245
i=2  j=4  lichengzxpoints(3)=1031
i=2  j=4  lichengzxpoints(4)=245
i=3  j=4  lichengzxpoints(5)=1031
i=3  j=4  lichengzxpoints(6)=245
i=4  j=4  lichengzxpoints(7)=1031
i=4  j=4  lichengzxpoints(8)=245
i=5  j=4  lichengzxpoints(9)=1031
i=5  j=4  lichengzxpoints(10)=245
i=6  j=4  lichengzxpoints(11)=1031
i=6  j=4  lichengzxpoints(12)=245
i=7  j=4  lichengzxpoints(13)=1031
i=7  j=4  lichengzxpoints(14)=245
i=8  j=4  lichengzxpoints(15)=1031
i=8  j=4  lichengzxpoints(16)=245
i=9  j=4  lichengzxpoints(17)=1031
i=9  j=4  lichengzxpoints(18)=245

i=1  j=5  lichengzxpoints(1)=1120
i=1  j=5  lichengzxpoints(2)=245
i=2  j=5  lichengzxpoints(3)=1120
i=2  j=5  lichengzxpoints(4)=245
i=3  j=5  lichengzxpoints(5)=1120
i=3  j=5  lichengzxpoints(6)=245
i=4  j=5  lichengzxpoints(7)=1120
i=4  j=5  lichengzxpoints(8)=245
i=5  j=5  lichengzxpoints(9)=1120
i=5  j=5  lichengzxpoints(10)=245
i=6  j=5  lichengzxpoints(11)=1120
i=6  j=5  lichengzxpoints(12)=245
i=7  j=5  lichengzxpoints(13)=1120
i=7  j=5  lichengzxpoints(14)=245
i=8  j=5  lichengzxpoints(15)=1120
i=8  j=5  lichengzxpoints(16)=245
i=9  j=5  lichengzxpoints(17)=1120
i=9  j=5  lichengzxpoints(18)=245

i=1  j=6  lichengzxpoints(1)=1328
i=1  j=6  lichengzxpoints(2)=245
i=2  j=6  lichengzxpoints(3)=1328
i=2  j=6  lichengzxpoints(4)=245
i=3  j=6  lichengzxpoints(5)=1328
i=3  j=6  lichengzxpoints(6)=245
i=4  j=6  lichengzxpoints(7)=1328
i=4  j=6  lichengzxpoints(8)=245
i=5  j=6  lichengzxpoints(9)=1328
i=5  j=6  lichengzxpoints(10)=245
i=6  j=6  lichengzxpoints(11)=1328
i=6  j=6  lichengzxpoints(12)=245
i=7  j=6  lichengzxpoints(13)=1328
i=7  j=6  lichengzxpoints(14)=245
i=8  j=6  lichengzxpoints(15)=1328
i=8  j=6  lichengzxpoints(16)=245
i=9  j=6  lichengzxpoints(17)=1328
i=9  j=6  lichengzxpoints(18)=245

i=1  j=7  lichengzxpoints(1)=1443
i=1  j=7  lichengzxpoints(2)=245
i=2  j=7  lichengzxpoints(3)=1443
i=2  j=7  lichengzxpoints(4)=245
i=3  j=7  lichengzxpoints(5)=1443
i=3  j=7  lichengzxpoints(6)=245
i=4  j=7  lichengzxpoints(7)=1443
i=4  j=7  lichengzxpoints(8)=245
i=5  j=7  lichengzxpoints(9)=1443
i=5  j=7  lichengzxpoints(10)=245
i=6  j=7  lichengzxpoints(11)=1443
i=6  j=7  lichengzxpoints(12)=245
i=7  j=7  lichengzxpoints(13)=1443
i=7  j=7  lichengzxpoints(14)=245
i=8  j=7  lichengzxpoints(15)=1443
i=8  j=7  lichengzxpoints(16)=245
i=9  j=7  lichengzxpoints(17)=1443
i=9  j=7  lichengzxpoints(18)=245

i=1  j=8  lichengzxpoints(1)=1522
i=1  j=8  lichengzxpoints(2)=245
i=2  j=8  lichengzxpoints(3)=1522
i=2  j=8  lichengzxpoints(4)=245
i=3  j=8  lichengzxpoints(5)=1522
i=3  j=8  lichengzxpoints(6)=245
i=4  j=8  lichengzxpoints(7)=1522
i=4  j=8  lichengzxpoints(8)=245
i=5  j=8  lichengzxpoints(9)=1522
i=5  j=8  lichengzxpoints(10)=245
i=6  j=8  lichengzxpoints(11)=1522
i=6  j=8  lichengzxpoints(12)=245
i=7  j=8  lichengzxpoints(13)=1522
i=7  j=8  lichengzxpoints(14)=245
i=8  j=8  lichengzxpoints(15)=1522
i=8  j=8  lichengzxpoints(16)=245
i=9  j=8  lichengzxpoints(17)=1522
i=9  j=8  lichengzxpoints(18)=245

i=1  j=9  lichengzxpoints(1)=1620
i=1  j=9  lichengzxpoints(2)=245
i=2  j=9  lichengzxpoints(3)=1620
i=2  j=9  lichengzxpoints(4)=245
i=3  j=9  lichengzxpoints(5)=1620
i=3  j=9  lichengzxpoints(6)=245
i=4  j=9  lichengzxpoints(7)=1620
i=4  j=9  lichengzxpoints(8)=245
i=5  j=9  lichengzxpoints(9)=1620
i=5  j=9  lichengzxpoints(10)=245
i=6  j=9  lichengzxpoints(11)=1620
i=6  j=9  lichengzxpoints(12)=245
i=7  j=9  lichengzxpoints(13)=1620
i=7  j=9  lichengzxpoints(14)=245
i=8  j=9  lichengzxpoints(15)=1620
i=8  j=9  lichengzxpoints(16)=245
i=9  j=9  lichengzxpoints(17)=1620
i=9  j=9  lichengzxpoints(18)=245
错在什么地方,你应该明白了。
 楼主| 发表于 2011-11-10 09:54:35 | 显示全部楼层
yshf 发表于 2011-11-8 21:58
那九行到底是多少点的数据,按你的二层循环,得到的数据如下:
i=1  j=1  lichengzxpoints(1)=910
i=1  j ...

非常感谢,问题已得到解决。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 18:47 , Processed in 0.182616 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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