'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. PHP中如何命令行

    PHP中如何命令行 一.总结 一句话总结:配置php系统环境,然后命令行中运行 php -f 文件名即可 配置php系统环境 php_-f_文件名 例如: 1.三种运行php的方式? 运行文件_-f ...

  2. (转)基于C#的socket编程的TCP异步实现

    一.摘要 本篇博文阐述基于TCP通信协议的异步实现. 二.实验平台 Visual Studio 2010 三.异步通信实现原理及常用方法 3.1 建立连接 在同步模式中,在服务器上使用Accept方法 ...

  3. 第十二周(MySort)

    注意:研究sort的其他功能,要能改的动代码,需要答辩 模拟实现Linux下Sort -t : -k 2的功能. 要有伪代码,产品代码,测试代码(注意测试用例的设计) 参考 Sort的实现.提交博客链 ...

  4. c++-pimer-plus-6th-chapter06

    Chapter Review 1 Both version give the same answers, but the if else version is more efficient. Cons ...

  5. LeetCode--235--二叉树的最近公共祖先

    问题描述: 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 x 是 p.q 的 ...

  6. synchronized相关用法简述

    synchronized 锁,他是一个java 的关键字,能够保证同一线程只有一个线程访问或使用此修饰的代码块 用法 synchronized方法,synchronized块 synchronized ...

  7. PHP个人博客项目------切切歆语博客

    php+mysql+apache, ThinkPHP3.2框架开发 我的个人博客项目 适合新手练习 源码地址下载:https://github.com/DickyQie/php-myblog

  8. linux基础知识(1)

    1.date man date :查看帮助 1. date [OPTION]... [+FORMAT]:显示时间 ,format表示格式符号 例如: date :Sun Dec 23 21:45:34 ...

  9. lanmp中环境变量的更改方法

    1.vim /etc/profile 改成: export PATH=$PATH:/www/wdlinux/phps/71/bin/ 然后运行: source /etc/profile

  10. php字符串的拆分截取

    /* * strstr区分大小写 * stristr不区分大小写 * */ $str="test/abc.jpg"; echo stristr($str,'.'); echo '& ...