[VB6 ] 求救! 將TreeView的樹狀結構輸出至Excel
想請問各位高手
我想要從將treeview的樹狀結構(包含階層關係及節點文字)輸出至excel
假設樹狀結構的父階層可以分成A及B兩種
那我使用的方式為
Dim n As Integer
For n = 1 To TreeView1.Nodes.Count
'如果父階層為A
If InStr(TreeView1.Nodes(n).Text, "A") > 0 Then
xlApp.Worksheets(1).Cells(n, 1).Value = TreeView1.Nodes(n).Text
'如果父階層為B
ElseIf InStr(TreeView1.Nodes(n).Text, "B") > 0 The
xlApp.Worksheets(1).Cells(n, 1).Value = TreeView1.Nodes(n).Text
'如果子節點的父階層為A
ElseIf InStr(TreeView1.Nodes(n).Parent, "A") > 0 Then
xlApp.Worksheets(1).Cells(n, 2).Value = TreeView1.Nodes(n).Text
'如果子節點的父階層為B
ElseIf InStr(TreeView1.Nodes(n).Parent, "B") > 0 Then
xlApp.Worksheets(1).Cells(n, 2).Value = TreeView1.Nodes(n).Text
Next
輸出至Excel的階層如下
A
A1
B
B1
但現在問題來了,如果我欲在treeview的節點A下新增A2,A1會跑到B的節點下,
而不會在A的節點下,如下
A
A1
B
B1
A2
有高手可以解決此問題嗎?
或是有甚麼更好的方法可以把treeview的樹狀結構讀到excel裡,謝謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.229.7
→
02/21 08:36, , 1F
02/21 08:36, 1F
→
02/21 08:36, , 2F
02/21 08:36, 2F
→
02/21 08:49, , 3F
02/21 08:49, 3F
→
02/21 08:50, , 4F
02/21 08:50, 4F
→
02/21 08:50, , 5F
02/21 08:50, 5F
→
02/21 09:29, , 6F
02/21 09:29, 6F
→
02/21 09:30, , 7F
02/21 09:30, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):