控制台程序读取WIKI形式的TXT文件并一表格的形式显示在Word中
'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中的更多相关文章
- C# 读取大文件 (可以读取3GB大小的txt文件)
原文:C# 读取大文件 (可以读取3GB大小的txt文件) 在处理大数据时,有可能 会碰到 超过3GB大小的文件,如果通过 记事本 或 NotePad++去打开它,会报错,读不到任何文件. 如果你只是 ...
- 控制台程序读取Excel设置角色权限
摘要: 本人微信公众号:微软动态CRM专家罗勇 ,回复283或者20181118可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me ...
- Net Core 控制台程序使用Nlog 输出到log文件
using CoreImportDataApp.Common; using Microsoft.Extensions.Configuration; using Microsoft.Extensions ...
- C语言重定向输入:txt文件内容是中文,重定向输入显示乱码的原因
一.txt文件中的内容是中文,重定向输入显示乱码原因: 是因为文本文件的编码和和编译器的不一致导致的.我文本文件用的编码是UTF-8,而编译器是ANSI,不匹配,所以输出乱码.文本另存为时把编码改为A ...
- C#控制台程序读取项目中文件路径
//使用appdomain获取当前应用程序集的执行目录 string dir = AppDomain.CurrentDomain.BaseDirectory; //使用path获取当前应用程序集的执行 ...
- springboot 控制台程序读取配置文件(原创)
首先新建一个springboot项目,此处省略. 1.新建一个application.properties person.name=kevin person.age=6 person.sex=male ...
- C# 调用控制台程序,并获取输出写入文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- windows下控制台程序更改图标和加载资源文件
1.在空项目的Resouce FIles中右击创建一个新的.rc文件. 2.选中这个.rc文件右击在界面中选择导入icon 3.选中icon,将icon的ID更改为IDC_MAINFRAME. 4.重 ...
- 利用Python读取文件名并生成txt文件——以图片文件为例
效果如下: 代码: import os class ReadImageName(): def __init__(self): self.path = '.' def readname(self): f ...
随机推荐
- 第 8 章 容器网络 - 059 - 安装配置 flannel
安装配置 flannel 1) build flannel flannel 没有现成的执行文件可用,必须自己 build,最可靠的方法是在 Docker 容器中 build. 不过用于做 build ...
- fiddler学习笔记&&基本使用
周末在网上找了些fiddler相关的资料来看,学习下如何使用这个工具(平时接口测试用得比较多,在没有接口文档的情况下,可以通过抓包工具来提取需要测试的接口,ps.好久没写博客了,争取5月结束前再写2篇 ...
- Python核心编程的四大神兽
http://www.cnblogs.com/ssy3340/p/9747722.html
- English Voice of <<if were a boy >>
<if i were a boy>中英文歌词: If I were a boy 如果我是个男孩 Even just for a day 就算只是一天 I' roll out of bed ...
- find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax
1.3.100 find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax find_first_zero_bit 修订后: /* * Find-bit routines ...
- 启动mysql5.7异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
异常表现 mysql5.7启动时报错 Starting MySQL...The server quit without updating PID file [FAILED]sql/data/insta ...
- 笔记react router 4(三)
上一篇我们说到了路由组件的嵌套.想必你已经运用自如了.那么,这一次我们来聊一聊4.X中Router的变更. 在3.X中我们若使用路由的模式,可通过在Router上配置history的值即可. 例如, ...
- Ant Design 日期选择组件RangePicker 选择时间范围后计算范围内的天数。
/** *需求:同年同月,同年不同月(两个月相减大于1,小于1),不同年(两个年相减大于1(是否为闰年),小于1),起止包含的月份及天 */ //首先引入组件 import { DatePicker} ...
- cf-914D-线段树
http://codeforces.com/contest/914/problem/D 题目大意是给出一个数列,进行两种操作,一个是将位置i的数置为x,另一个操作是询问[l,r]内的数的gcd是不是x ...
- Leetcode 127 **
class Solution { public: int ladderLength(string beginWord, string endWord, vector<string>& ...