I believe you are looking for Inorder Tree Traversal? Unless I've misunderstood something.
http://www.cplusplus.com/forum/beginner/131457/
void Tree:: Inorder(Node* Root)
{
if(Root != NULL)
{
Inorder(Root->Left());
cout << Root->Key() << endl;
Inorder(Root->Right());
}
}
This little function uses recursive calls to print out all the nodes of a tree in the order they appear starting at 'root'. I think with this starting point you should be able to figure it all out fairly easily. If not, please let me know (or if this isn't even what you're looking for). It's a c++ example, but it should still help you out.
EDIT: to keep track of traversal depth (Traversing a tree of objects in c#):
printRoot(Node node)
{
printNode(node, 0);
}
printNode(Node node, int level)
{
printTitle(node.title)
foreach (Node child in node.children)
{
printNode(child, level + 1); //<-- recursive
}
}
EDIT 2: Since you're still unsure of how to use this i'll write the code out.
public void InorderTraversal(TreeNode root){
InorderTraversal(root, 0);
}
public void InorderTraversal(TreeNode root, int level){
//this is where you write to excel. You can also use 'level' to decide if you insert in column 1, 2, or 3 just by using a simple if statement like this:
if(level == 0)
sw.WriteLine(node, level.ToString());
foreach (TreeNode child in root.children){ //depending on how your tree is implemented this is probably either going to be root.children or root.next
InorderTraversal(child, level + 1);
}
}
To use this in your code:
void main(void){
InorderTraversal(treeView1.Nodes);
}