'Imports System.Collections.Generic
'Imports System.Text
'Imports System.IO
'Imports office = Microsoft.Office.Core
'Imports word = Microsoft.Office.Interop.Word
Module Module1 Sub Main(ByVal args As String()) '这里的参数args是字符串数组,传递的是\bin\Debug\中的文本文件,可以传递多个文件
Dim theApplication As New Microsoft.Office.Interop.Word.Application '添加引用COM的“Microsoft Word 12.0 Object Library”
theApplication.Visible = True
Dim theDocument As Microsoft.Office.Interop.Word.Document
theDocument = theApplication.Documents.Add()
Dim reader As System.IO.TextReader '添加引用COM的“Microsoft Visual Basic for Applications Extensibility 5.3”
reader = New System.IO.StreamReader("woshi.txt") '原语句是reader = New System.IO.StreamReader(args(0))
'C:\Users\user\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\woshi.txt Dim separators() As String
separators() = "||"
Dim rowCount As Integer =
Dim columnCount As Integer = Dim rowList As New System.Collections.Generic.List(Of String)
Dim row As String = reader.ReadLine() While row IsNot Nothing
rowCount +=
rowList.Add(row) If rowCount = Then
Dim splitHeaderRow As String() = row.Split(separators, StringSplitOptions.None) columnCount = splitHeaderRow.Length -
End If row = reader.ReadLine()
End While Dim range As Microsoft.Office.Interop.Word.Range = theDocument.Range()
Dim table As Microsoft.Office.Interop.Word.Table = range.Tables.Add(range, rowCount, columnCount) Dim columnindex As Integer =
Dim rowindex As Integer = For Each r As String In rowList
Dim splitrow As String() = r.Split(separators, StringSplitOptions.None) For columnindex = To columnCount
Dim cell As Microsoft.Office.Interop.Word.Cell = table.Cell(rowindex, columnindex)
cell.Range.Text = splitrow(columnindex)
Next
rowindex +=
Next table.Rows().Range.Bold =
table.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent) System.Console.WriteLine("Table complete.")
System.Console.ReadLine() theApplication.Quit(False) End Sub End Module

控制台程序读取WIKI形式的TXT文件并一表格的形式显示在Word中的更多相关文章

  1. C# 读取大文件 (可以读取3GB大小的txt文件)

    原文:C# 读取大文件 (可以读取3GB大小的txt文件) 在处理大数据时,有可能 会碰到 超过3GB大小的文件,如果通过 记事本 或 NotePad++去打开它,会报错,读不到任何文件. 如果你只是 ...

  2. 控制台程序读取Excel设置角色权限

    摘要: 本人微信公众号:微软动态CRM专家罗勇 ,回复283或者20181118可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me ...

  3. Net Core 控制台程序使用Nlog 输出到log文件

    using CoreImportDataApp.Common; using Microsoft.Extensions.Configuration; using Microsoft.Extensions ...

  4. C语言重定向输入:txt文件内容是中文,重定向输入显示乱码的原因

    一.txt文件中的内容是中文,重定向输入显示乱码原因: 是因为文本文件的编码和和编译器的不一致导致的.我文本文件用的编码是UTF-8,而编译器是ANSI,不匹配,所以输出乱码.文本另存为时把编码改为A ...

  5. C#控制台程序读取项目中文件路径

    //使用appdomain获取当前应用程序集的执行目录 string dir = AppDomain.CurrentDomain.BaseDirectory; //使用path获取当前应用程序集的执行 ...

  6. springboot 控制台程序读取配置文件(原创)

    首先新建一个springboot项目,此处省略. 1.新建一个application.properties person.name=kevin person.age=6 person.sex=male ...

  7. C# 调用控制台程序,并获取输出写入文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  8. windows下控制台程序更改图标和加载资源文件

    1.在空项目的Resouce FIles中右击创建一个新的.rc文件. 2.选中这个.rc文件右击在界面中选择导入icon 3.选中icon,将icon的ID更改为IDC_MAINFRAME. 4.重 ...

  9. 利用Python读取文件名并生成txt文件——以图片文件为例

    效果如下: 代码: import os class ReadImageName(): def __init__(self): self.path = '.' def readname(self): f ...

随机推荐

  1. c# datagridview绑定数据源(BindingList<class>)中的现象 待查

    现象1: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...

  2. [Database]各数据库连接配置:Oracle:thin 数据库连接/MySQL 连接配置

    MySQL:          String Driver="com.mysql.jdbc.Driver";    //驱动程序      String URL="jdb ...

  3. English trip M1 - AC9 Nosey people 爱管闲事的人 Teacher:Solo

    In this lesson you will learn to talk about what happened. 在本课中,您将学习如何谈论发生的事情. 课上内容(Lesson) # four “ ...

  4. android主流开源库

    网络框架:Volley 和 Async Volley特点:能使网络通信更快,更简单.更健壮 Get,Post网络请求及网络图像的高效率 Async:高效的网络数据请求, 解析成json 持久化cook ...

  5. Git创建新项目

    1. git init 2. git remote add origin 3. git pull origin --allow-unrelated-histories 4. git push orig ...

  6. javaweb项目静态资源被拦截的解决方法

    <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/*< ...

  7. python-跨域问题

    跨域:因为浏览器的同源策略,在你请求返回的时候会进行拦截 jsonp 只能发 get 请求 cors 可以发任何请求 ,在响应时加个响应头就行 同源策略对ajax阻拦 同源策略对src或href属性的 ...

  8. Linux下使用mail发送邮件

    邮件常常是Linux下监控报警手段之一.Linux下的mail命令可以方便,快速的完成发送邮件.下面以CentOS为例 1.安装 [root@vm8028 ~]# mail -bash: mail: ...

  9. Boosting

    Boosting is a greedy alogrithm. The alogrithm works by applying the weak learner sequentially to wei ...

  10. webmagic 日志使用及maven项目中排除日志依赖

    我用的Spring Boot maven构建的工程,默认引入了 <dependency> <groupId>org.springframework.boot</group ...