Posted By

qrist0ph on 06/21/08


Tagged

excel vbs


Versions (?)

Excel Adjazenz Matrix nach GraphViz


 / Published in: Visual Basic
 

  1. Attribute VB_Name = "adjazenzMatrixToGraphviz"
  2. Sub adjazenzMatrixToGraphviz()
  3. i = 0
  4. Dim z As Range
  5. Dim graph As String
  6. s = "digraph G{"
  7. nodeNameRow = Selection.Row
  8. nodeNameCol = Selection.Column
  9. For Each zelle In Selection
  10. 'falls nicht in der bezeichnungs spalte oder zeile
  11. If ((Not zelle.Row = nodeNameRow) And (Not zelle.Column = nodeNameCol)) Then
  12. If (Not zelle.Value = "") Then
  13. s = s & """" & Cells(zelle.Row, nodeNameCol) & """ -> """ & Cells(nodeNameRow, zelle.Column) & """ [label=""" & zelle.Value & """];" & vbCrLf
  14. End If
  15. End If
  16. Next
  17. s = s & "}"
  18. writeLine (s)
  19. WriteToATextFile (s)
  20. End Sub
  21.  
  22. Sub writeLine(s As String)
  23. Debug.Print s
  24. End Sub
  25.  
  26. Sub WriteToATextFile(s As String)
  27. MyFile = ActiveWorkbook.Path & "\graph.dot"
  28. 'set and open file for output
  29. fnum = FreeFile()
  30. Open MyFile For Output As fnum
  31. 'write project info and then a blank line. Note the comma is required
  32. Print #fnum, s
  33. Close #fnum
  34. End Sub

Report this snippet  

You need to login to post a comment.