章鱼哥出品—VB.NET Office *** 作之Word(一)
本文是在上文给出的Class_Word1类的实例,实现了类中的各个功能,读者可借鉴参考。
实现窗体:
代码实现:代码直接复制到上文的窗体类中
'*********************************************************************
'作者:章鱼哥,QQ:3107073263 群:309816713 '如有疑问或好的建议请联系我,大家一起进步 '*********************************************************************imports Microsoft.Office.InteropPublic Class Form1 Dim Array_Word As New ArrayList Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load RichTextBox1.Text = "章鱼哥出品VB.NET" End Sub '新建一个Word文档 Private Sub But_NewWord_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_NewWord.Click Dim My_word As New Class_Word1 My_word.Newdocument() Array_Word.Add(My_word) End Sub '以模板新建 Private Sub But_ModuleNewWord_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_ModuleNewWord.Click Dim My_word As New Class_Word1 My_word.ModulNewdocument(TextBox1.Text) Array_Word.Add(My_word) End Sub '打开一个文档 Private Sub But_OpenWord_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_OpenWord.Click Dim My_word As New Class_Word1 My_word.OpenWorddocument(TextBox1.Text,False) Array_Word.Add(My_word) End Sub '关闭当前打开的所有文档 Private Sub But_CloseAlldocument_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_CloseAlldocument.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.CloseWorddocument() Next Array_Word.Clear() End Sub '保存文档 Private Sub But_Save_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_Save.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.Save() Next End Sub '另存为 Private Sub But_SaveAs_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_SaveAs.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.SaveAs(TextBox1.Text) Next End Sub '插入文本 Private Sub But_Insert_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_Insert.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.InsertText(RichTextBox1.Text) Next End Sub '插入表格 Private Sub But_InsertTabel_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_InsertTabel.Click Dim tabel As Datatable = GetTabel(ListVIEw1) For Each Word_Class As Class_Word1 In Array_Word Word_Class.InsertTabel(GetTabel(ListVIEw1)) Next End Sub '从ListvIEw 中读取数据生成Datatable Private Function GetTabel(ByVal lis As ListVIEw) As Datatable Dim Tabel As New Datatable() '加表头 For i = 0 To lis.Columns.Count - 1 Tabel.Columns.Add(lis.Columns(i).Text.ToString) Next For i = 0 To lis.Items.Count - 1 Dim row As DaTarow = Tabel.NewRow For j = 0 To lis.Columns.Count - 1 row.Item(j) = lis.Items(i).SubItems(j).Text Next Tabel.Rows.Add(row) Next Return Tabel End Function '插入图片 Private Sub But_InsertPic_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_InsertPic.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.InsertPic(TextBox2.Text) Next End Sub '读取文档的内容 Private Sub But_ReadText_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_ReadText.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.ReadText() RichTextBox1.Paste() Next End Sub<pre @R_301_6889@="code" >'********************************************************************* '获取文档路径 Private Sub But_GetAdrress_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_GetAdrress.Click Dim opendialog As New OpenfileDialog If opendialog.ShowDialog = DialogResult.OK Then TextBox1.Text = opendialog.file@R_301_6889@ End If End Sub '获取当前鼠标的位置 Private Sub But_GetCursor_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_GetCursor.Click For Each Word_Class As Class_Word1 In Array_Word Dim Cursor As ArrayList = Word_Class.GetCursor() If Cursor IsNot nothing Then For i = 0 To Cursor.Count - 1 RichTextBox1.Text &= " " & Cursor(i) Next End If Next End Sub '将光标移动到指定页 Private Sub But_GoTo_Page_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_GoTo_Page.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.Gotopage(Tex_Page.Text) Next End Sub '光标移动到指定行(绝对) Private Sub But_GotoAbsoultRow_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_GotoAbsoultRow.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.GoToAbsolutline(Tex_Row_Absoult.Text) Next End Sub '光标移动到指定行(相对) Private Sub But_GotoOppsitRow_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles But_GotoOppsitRow.Click For Each Word_Class As Class_Word1 In Array_Word Word_Class.GoToOppsiteline(Tex_Row_Oppsit.Text) Next End Sub '上下左右按钮,点击按钮一次移动一位 Private Sub PictureBox1_MouseUp(ByVal sender As System.Object,ByVal e As System.windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp 'MsgBox("X:" & e.X & "Y:" & e.Y) Dim x As Integer = e.X Dim y As Integer = e.Y 'RichTextBox1.Text &= "|" & e.X & ":" & e.Y For Each Word_Class As Class_Word1 In Array_Word If x > 70 And x < 130 Then If y > 20 And y < 45 Then Word_Class.MoveUp() ElseIf y > 110 And y < 135 Then Word_Class.MoveDown() End If End If If y > 45 And y < 105 Then If x > 40 And x < 65 Then Word_Class.Moveleft() ElseIf x > 135 And y < 160 Then Word_Class.MoveRight() End If End If Next End SubEnd Class总结
以上是内存溢出为你收集整理的章鱼哥出品—VB.NET Office *** 作之Word(二)全部内容,希望文章能够帮你解决章鱼哥出品—VB.NET Office *** 作之Word(二)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)