如何一键打印多个文本文件的内容
How to print the content of multiple text files with one click
有没有办法一键打印多个文本文件中的文本?我目前使用的代码如下所示。
Dim FilePath = New DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Employee Record\" & TextBox1.Text))
Dim FileNameRTO As String = Path.Combine(FilePath.FullName, TextBox2.Text + ".RTO")
Dim ObjectReaderRTO As New System.IO.StreamReader(FileNameRTO)
RichTextBox1.Text = ObjectReaderRTO.ReadToEnd
ObjectReaderRTO.Close()
当前代码在桌面目录“员工记录”中搜索 sub-directory,其标题在 TextBox1.Text 中指定。
然后代码在 sub-directory 中搜索标题在 TextBox2.Text 中指定的文本文件(文件扩展名 RTO)。
假设sub-directory中有多个RTO文本文件,如何将所有文本一键打印到一份报告中?这可能吗?我正在使用 Visual Basic 2010。提前谢谢你。
您已经为文件夹创建了一个 DirectoryInfo 对象。您可以使用 GetFiles 方法获取所有扩展名为 .RTO 的文件,并将它们附加到 RichTextBox,如下所示:
Dim FilePath As DirectoryInfo = New DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Employee Record\" & TextBox1.Text))
RichTextBox1.Clear 'omit this line if you want to keep the current contents
For Each FileRTO As FileInfo In FilePath.GetFiles("*.RTO", SearchOption.TopDirectoryOnly)
RichTextBox1.AppendText(File.ReadAllText(FileRTO.FullName))
Next
有没有办法一键打印多个文本文件中的文本?我目前使用的代码如下所示。
Dim FilePath = New DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Employee Record\" & TextBox1.Text))
Dim FileNameRTO As String = Path.Combine(FilePath.FullName, TextBox2.Text + ".RTO")
Dim ObjectReaderRTO As New System.IO.StreamReader(FileNameRTO)
RichTextBox1.Text = ObjectReaderRTO.ReadToEnd
ObjectReaderRTO.Close()
当前代码在桌面目录“员工记录”中搜索 sub-directory,其标题在 TextBox1.Text 中指定。
然后代码在 sub-directory 中搜索标题在 TextBox2.Text 中指定的文本文件(文件扩展名 RTO)。
假设sub-directory中有多个RTO文本文件,如何将所有文本一键打印到一份报告中?这可能吗?我正在使用 Visual Basic 2010。提前谢谢你。
您已经为文件夹创建了一个 DirectoryInfo 对象。您可以使用 GetFiles 方法获取所有扩展名为 .RTO 的文件,并将它们附加到 RichTextBox,如下所示:
Dim FilePath As DirectoryInfo = New DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Employee Record\" & TextBox1.Text))
RichTextBox1.Clear 'omit this line if you want to keep the current contents
For Each FileRTO As FileInfo In FilePath.GetFiles("*.RTO", SearchOption.TopDirectoryOnly)
RichTextBox1.AppendText(File.ReadAllText(FileRTO.FullName))
Next