Hallo liebe Forum Nutzer,
ich habe mit ein Tool erstellt womit ich mir ein beliebiges Verzeichnis mit unterverzeichnissen und Inhalt in einen Treeview anzeigen lassen kann.
Der Treewiev export geht einen Umweg, da ich es nicht anders hinbekomme. Ich exportiere erst den Treewiev in HTML und dann lese ich die HTML aus und
speicher es in *docx. Soweit funktioniert es, aber ich bekomme es nicht hin, das die Umlaute richtig dargestellt werden, und die schrift in *docx Arial ist sowie die Ordner alle FETT geschrieben sind.
Hatte einiges Probiert in UFT8 zu schreiben, aber egal was ich mache nix funzt.
Hat jemand von euch villeicht ein Lösungsvorschlag?
Spoiler anzeigen
CodeTags korrigiert
Thema verschoben; Das Thema wird automatisch dort erstellt, wo man sich befindet, wenn man auf [* Neues Thema] klickt. ~VaporiZed
ich habe mit ein Tool erstellt womit ich mir ein beliebiges Verzeichnis mit unterverzeichnissen und Inhalt in einen Treeview anzeigen lassen kann.
Der Treewiev export geht einen Umweg, da ich es nicht anders hinbekomme. Ich exportiere erst den Treewiev in HTML und dann lese ich die HTML aus und
speicher es in *docx. Soweit funktioniert es, aber ich bekomme es nicht hin, das die Umlaute richtig dargestellt werden, und die schrift in *docx Arial ist sowie die Ordner alle FETT geschrieben sind.
Hatte einiges Probiert in UFT8 zu schreiben, aber egal was ich mache nix funzt.
Hat jemand von euch villeicht ein Lösungsvorschlag?
VB.NET-Quellcode
- Option Explicit On
- Imports System.IO
- Imports System.Net
- Imports System.Text
- Imports System.Web
- Public Class Form1
- Dim Speichername As String
- Dim Pfad As String
- Dim Test As String
- Dim x As Integer
- Dim DerPfad As String
- Dim subOrdner As Integer
- Dim encoding As Encoding = Encoding.UTF8
- Dim writer As New StreamWriter("D:\Export.html", False, encoding)
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Try
- Cursor = Cursors.Hand
- AllesExpandierenToolStripMenuItem.Enabled = False
- AlleOrdnerSchließenToolStripMenuItem.Enabled = False
- ExportZuWordToolStripMenuItem.Enabled = False
- x = 0
- subOrdner = 0
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub FillTreeNode(ByVal dNode As TreeNode)
- Try
- Dim d As New DirectoryInfo(dNode.FullPath)
- For Each di As DirectoryInfo In d.GetDirectories
- Dim nNode As New TreeNode(di.Name)
- dNode.Nodes.Add(nNode)
- FillTreeNode(nNode)
- Next
- For Each fi As FileInfo In d.GetFiles
- Dim fNode As New TreeNode(fi.Name)
- dNode.Nodes.Add(fNode)
- Test = Test & dNode.ToString
- Next
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub ÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ÖffnenToolStripMenuItem.Click
- Try
- If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
- Cursor = Cursors.WaitCursor
- Dim nNode As New TreeNode(System.IO.Path.GetFullPath(FolderBrowserDialog1.SelectedPath))
- Pfad = FolderBrowserDialog1.SelectedPath.ToString
- TreeView1.Nodes.Add(nNode)
- Me.FillTreeNode(nNode)
- AllesExpandierenToolStripMenuItem.Enabled = True
- ExportZuWordToolStripMenuItem.Enabled = True
- Cursor = Cursors.Hand
- Else
- Exit Sub
- End If
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub BlattLeerenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BlattLeerenToolStripMenuItem.Click
- TreeView1.Nodes.Clear()
- End Sub
- Private Sub AllesExpandierenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AllesExpandierenToolStripMenuItem.Click
- Try
- Cursor = Cursors.WaitCursor
- TreeView1.ExpandAll()
- AllesExpandierenToolStripMenuItem.Enabled = False
- AlleOrdnerSchließenToolStripMenuItem.Enabled = True
- Cursor = Cursors.Hand
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub AlleOrdnerSchließenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AlleOrdnerSchließenToolStripMenuItem.Click
- Try
- Cursor = Cursors.WaitCursor
- TreeView1.CollapseAll()
- AllesExpandierenToolStripMenuItem.Enabled = True
- AlleOrdnerSchließenToolStripMenuItem.Enabled = False
- Cursor = Cursors.Hand
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub ExportZuWordToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExportZuWordToolStripMenuItem.Click
- Try
- Cursor = Cursors.WaitCursor
- 'Request a file name to save to
- Dim sfd As New SaveFileDialog()
- Dim saveFileName As String = String.Empty
- With sfd
- .FileName = "Export"
- .Title = "Export to *.docx File"
- .Filter = "Word document (*.docx)|*.html"
- .OverwritePrompt = True
- If .ShowDialog = Windows.Forms.DialogResult.OK Then
- saveFileName = .FileName
- Else
- Cursor = Cursors.Hand
- Exit Sub
- End If
- Speichername = saveFileName.ToString
- End With
- sfd.Dispose()
- If saveFileName.Length > 0 Then
- 'Used to store the nodes contents
- Dim treeContents As New System.Text.StringBuilder
- 'Start the HTML file
- treeContents.AppendLine("<html>")
- treeContents.AppendLine("<html>")
- treeContents.AppendLine("<head><title>Tree View Export</title></head>")
- treeContents.AppendLine("<body>")
- 'Enumerate through each root node.
- Dim treeEnumerator As IEnumerator = TreeView1.Nodes.GetEnumerator
- 'Export the tree view to the treeContents string builder
- Do Until treeEnumerator.MoveNext = False
- 'Pass the current root node to the OutputTreeNodesToString routine.
- OutputTreeNodesToHTMLString(DirectCast(treeEnumerator.Current, TreeNode), 0, treeContents)
- Loop
- 'Finish the HTML file
- treeContents.AppendLine("</body>")
- treeContents.AppendLine("</html>")
- 'Write the contents of the treeContents string builder to a new file
- Dim sw As New System.IO.StreamWriter(saveFileName)
- sw.Write(treeContents.ToString)
- sw.Dispose()
- End If
- Me.WebBrowser1.Navigate(Speichername)
- Application.DoEvents()
- Dim wc As New WebClient()
- Dim appWord As Object
- Dim doc As Object
- appWord = CreateObject("Word.Application")
- appWord.Visible = True
- doc = appWord.Documents.Add
- With doc
- .Range.Text = WebBrowser1.Document.Body.InnerText
- End With
- 'speichern
- Dim Speichername2 As String
- Speichername2 = (Speichername.Substring(0, Speichername.Length - 5))
- Speichername2 = Speichername2 & ".docx"
- doc.SaveAs(Speichername2)
- doc = Nothing
- 'html löschen, Word beenden
- My.Computer.FileSystem.DeleteFile(Speichername)
- appWord.Quit()
- Cursor = Cursors.Hand
- MessageBox.Show("Export nach " & Speichername2 & " abgeschlossen.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- Private Sub OutputTreeNodesToHTMLString(ByVal currentNode As TreeNode, ByVal nodeDepth As Int32, ByRef treeContentsStringBuilder As System.Text.StringBuilder)
- Try
- If currentNode IsNot Nothing Then
- 'Retrieve an enumerator for the current node.
- Dim nodeEnumerator As IEnumerator = currentNode.Nodes.GetEnumerator
- 'Write the current node to the string builder using no breaking spaces ( ) based on the nodeDepth value.
- For i As Int32 = 0 To nodeDepth
- treeContentsStringBuilder.Append(" ")
- Next
- treeContentsStringBuilder.Append(New String(ControlChars.VerticalTab, nodeDepth) & currentNode.Text & "<br />")
- 'If the currentNode has child nodes, increment the nodeDepth before recalling this routine.
- If currentNode.Nodes.Count > 0 Then nodeDepth += 1
- Do Until nodeEnumerator.MoveNext = False
- OutputTreeNodesToHTMLString(DirectCast(nodeEnumerator.Current, TreeNode), nodeDepth, treeContentsStringBuilder)
- Loop
- End If
- Catch ex As Exception
- MessageBox.Show("Fehler: " & ex.ToString, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- End Class
CodeTags korrigiert
Thema verschoben; Das Thema wird automatisch dort erstellt, wo man sich befindet, wenn man auf [* Neues Thema] klickt. ~VaporiZed
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „VaporiZed“ ()