'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. jquey 小记

    1. $.each(array, [callback]) 遍历[常用] 解释: 不同于例遍jQuery对象的$().each()方法,此方法可用于例遍任何对象. 回调函数拥有两个参数: 第一个为对象的 ...

  2. Feign二:复写Feign的默认配置

    Feign二:复写Feign的默认配置 1.在启动文件加入feign注解:@EnableFeignClients FeignApp.java import org.springframework.bo ...

  3. every day a practice —— morning(6)

    "Nearly one in five job ads for China's 2018 national civil service called for 'men only' or 'm ...

  4. 分离vue组件内部css

    当我们使用vue组件的时候,使用webpack打包的时候,默认会把vue组件内部的css打包到页面上,但是打包到页面上很丑陋,所以我们希望可以把vue组件内部的css抽离到css文件中,使用vue-s ...

  5. caffe-ssd

    1.安装依赖 1 sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-ser ...

  6. 深入解析 composer 的自动加载原理 (转)

    深入解析 composer 的自动加载原理 转自:https://segmentfault.com/a/1190000014948542 前言 PHP 自5.3的版本之后,已经重焕新生,命名空间.性状 ...

  7. P4238 【模板】多项式求逆 ntt

    题意:求多项式的逆 题解:多项式最高次项叫度deg,假设我们对于多项式\(A(x)*B(x)\equiv 1\),已知A,求B 假设度为n-1,\(A(x)*B(x)\equiv 1(mod x^{\ ...

  8. spring boot(十五)spring boot+thymeleaf+jpa增删改查示例

    快速上手 配置文件 pom包配置 pom包里面添加jpa和thymeleaf的相关包引用 <dependency> <groupId>org.springframework.b ...

  9. 6月13 ThinkPHP框架基础

    ThinkPHP 一.php框架基础介绍 真实项目开发步骤: 多人同时开发项目,协作开发项目.分工合理.效率有提高(代码风格不一样.分工不好) 测试阶段 上线运行 对项目进行维护.修改.升级(单个人维 ...

  10. springboot 定时任务部署至linux服务器上后会执行两次问题

    springboot定时任务在本地运行时,正常执行且只执行一次,但是在maven打包成war包,部署至linux服务器上之后,定时任务奇怪的执行了两次. 由于未做负载均衡,所以可以先排除是因为多台服务 ...