home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "ImportFromExcelspreadSheet"
- '******************************************************************'
- '* *'
- '* TurboCAD for Windows *'
- '* Copyright (c) 1993 - 2001 *'
- '* International Microcomputer Software, Inc. *'
- '* (IMSI) *'
- '* All rights reserved. *'
- '* *'
- '******************************************************************'
-
- Global appWorld As Excel.Application
- Global wbWorld As Excel.Workbook
- Global Path As String
- Global W As Excel.Worksheet
- Global XCur As Double
- Global YCur As Double
- Global ZCur As Double
- Global ActDr As Drawing
- Global Grs As Graphics
- Global Gr As Graphic
-
- Sub Run_Import()
- MsgBox "Remember you should define correct path to the sample excel file !"
- ' define path to TurboCADv6.xls sample excel file
- Path = "d:\Temp\TurboCADv6.xls"
- Set ActDr = ActiveDrawing
- Set Grs = ActDr.Graphics
- Call Setup
- Call Import
- Call CleanUp
- ActDr.Views(0).Refresh
- Set Grs = Nothing
- Set ActDr = Nothing
- End Sub
- Private Sub Setup()
- ' IMPORTANT: If your machine does not have Excel 97 installed,
- ' you must change the reference to the Excel 95 Object Library.
- ' Then, in the Declarations section above, change the variable
- ' declaration "wbWorld as Workbook" to "shtWorld As Worksheet."
- ' Then change all references to "wbWorld" to "shtWorld."
-
- On Error Resume Next 'ignore errors
- Set appWorld = CreateObject("Excel.Application") 'run it
- Err.Clear ' Clear Err object in case error occurred.
- On Error GoTo 0 'Resume normal error processing
- Set wbWorld = appWorld.Workbooks.Open(Path)
- Set W = wbWorld.Worksheets("Coordinates")
- End Sub
-
- ' Set the objects to Nothing.
- Private Sub CleanUp()
- ' This should force an unload of Microsoft Excel,
- ' providing no other applications or users have it loaded.
- wbWorld.Close False
- appWorld.Quit
- Set appWorld = Nothing
- Set wbWorld = Nothing
- End Sub
-
- Private Sub Import()
- Dim rngFeatureList As Excel.Range
- Dim intFirstBlankCell As Integer
- Dim loop1 As Integer
- Dim intColumOfFeature As Integer
-
- ' we use column 1 (x coordinates) to define how many records (x, y, z ) we have in SpreadSheet
- intColumOfFeature = 1
- ' Assign the column to an object.
- Set rngRankedList = W.Columns(intColumOfFeature)
-
- ' See if it's an empty list.
- If (rngRankedList.Cells(1, 1) = "") Then
- intFirstBlankCell = 0
- Else
- ' Search the row for the first blank cell.
- intFirstBlankCell = rngRankedList.Find("").Row
- End If
-
- ' row1 we have reserved for column header (X, Y, Z)
- 'load first item to define start point
- XCur = W.Cells(2, 1)
- YCur = W.Cells(2, 2)
- ZCur = W.Cells(2, 3)
-
- Set Gr = Grs.AddLineMultiline(XCur, YCur, ZCur)
- ' you can add curve instead multiline or other graphic you would like
- ' Set Gr = Grs.AddCurveBezier(XCur, YCur, ZCur)
-
- For loop1 = 3 To intFirstBlankCell - 1
- XCur = W.Cells(loop1, 1)
- YCur = W.Cells(loop1, 2)
- ZCur = W.Cells(loop1, 3)
- Gr.Vertices.Add XCur, YCur, ZCur
- Next
- ' if you would like to have closed multiline decoment next string
- ' Gr.Close
-
- End Sub
-