周一至周五 : 08:30 - 17:30 客服专员电话/微信:17301649371 QQ:2627049059
微信咨询

扫码微信咨询

关注公众号

关注微信公众号

电话: 021 5161 9370
返回顶部
将快表中的数据填充在word模版中自动生成新的word文档
显示全部楼层 倒序浏览 发表日期 2018-08-03 06:47:42 6434次阅读 5次回复
  1. Imports SpreadsheetGear
  2. Imports KbInterfaces
  3. Imports System.Windows.Resources
  4. Imports System.Windows.Threading
  5. Imports System.Windows
  6. Imports System.Windows.Co**ols
  7. Imports Newtonsoft.Json.Linq
  8. Imports System.Runtime.InteropServices.Automation

  9. Namespace ExcelViewVBDotnet
  10. Public Class StandardInterface '自定义名称
  11. Implements Interfaces.IExcelWorkBook
  12. Public Property ActiveWorkbook() As IWorkbook Implements Interfaces.IExcelWorkBook.Workbook
  13. Dim AW As SpreadsheetGear.IWorkbook, Range As SpreadsheetGear.IRange
  14. Public Sub Workbook_Open(OldRoot As Grid, NewRoot As Grid, Excel As SpreadsheetGear.Windows.Co**ols.WorkbookView) Implements Interfaces.IExcelWorkBook.Workbook_Open
  15. Excel.GetLock()
  16. AW = Excel.ActiveWorkbook
  17. Range = AW.ActiveWorksheet.Range
  18. Excel.ReleaseLock()

  19. End Sub '打开时执行事件

  20. Public Sub RangeSelection(sender As Object, e As SpreadsheetGear.Windows.Co**ols.RangeSelectionChangedEventArgs) Implements Interfaces.IExcelWorkBook.RangeSelection

  21. End Sub '单元格选择后执行的事件

  22. Public Sub RangeChanged(sender As Object, e As SpreadsheetGear.Windows.Co**ols.RangeChangedEventArgs) Implements Interfaces.IExcelWorkBook.RangeChanged

  23. End Sub '单元格编辑完成后执行事件

  24. Public Sub ButtunClick(sender As Object, e As SpreadsheetGear.Windows.Co**ols.ShapeActionEventArgs) Implements Interfaces.IExcelWorkBook.ButtunClick
  25. ActiveWorkbook.WorkbookSet.GetLock()

  26. If e.Shape.Name = "Button 1" Then
  27. '判断是否OOB模式运行
  28. If Application.Current.IsRunningOutOfBrowser = True Then
  29. '实例化Word接口
  30. Dim _myWord As Object = AutomationFactory.CreateObject("Word.Application")


  31. With _myWord
  32. .Visible = True
  33. .documents.open("D:\word\abc.doc")

  34. 'If _myWord.ActiveDocument.Bookmarks.Exists("Party_Co") = True Then
  35. ' MessageBox.Show(123)
  36. 'End If
  37. AW.WorkbookSet.GetLock()
  38. '_myWord.ActiveDocument.bookmarks("Party_Co").range.Text = Range("F_4068").Text

  39. While .Selection.Find.Execute("姓名")
  40. .Selection.Text = Range("F_4068").Text
  41. .Selection.HomeKey(6)
  42. End While

  43. AW.WorkbookSet.ReleaseLock()
  44. _myWord.ActiveDocument.SaveAs("D:\word" & Range("F_4068").Text)
  45. _myWord.ActiveDocument.Close()

  46. _myWord.Quit()
  47. _myWord = Nothing

  48. End With

  49. Else
  50. MessageBox.Show("必须在桌面启动才能使用!")
  51. End If
  52. End If
  53. ActiveWorkbook.WorkbookSet.ReleaseLock()
  54. End Sub '按钮/标签点击事件

  55. Public Sub FollowHyperlink(sender As Object) Implements Interfaces.IExcelWorkBook.FollowHyperlink

  56. End Sub '暂不支持


  57. Public Function ReText(ReTextA As IRange)
  58. ReText = StrReverse(ReTextA.ToString)
  59. Return (ReText)
  60. End Function

  61. Private Function DataTemplate() As String
  62. Throw New NotImplementedException
  63. End Function

  64. Private Function wdGoToBookmark() As Object
  65. Throw New NotImplementedException
  66. End Function

  67. Private Function strBookMark() As Object
  68. Throw New NotImplementedException
  69. End Function

  70. Private Sub SaveAs(p1 As Object)
  71. Throw New NotImplementedException
  72. End Sub

  73. End Class
  74. '注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。

  75. End Namespace
复制代码

电话/微信:18049989370 QQ:857188287
提示: 作者被禁止或删除 内容自动屏蔽
提示: 作者被禁止或删除 内容自动屏蔽

精彩评论5

提示: 作者被禁止或删除 内容自动屏蔽
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则  允许回帖邮件提醒楼主

快表软件是国内较早研究表格类软件开发平台的团队之一,迄今已有十多年的行业经验.致力于为企事业单位提供实用可靠的数字化平台。
  • 微信公众号

  • 微信小商店

  • 微信客服

  • Powered by Discuz! X3.4 | Copyright © 2022-2024, XiRong Soft. | 快表软件
  • 沪ICP备13033196号 | 营业执照 |上海西戎软件科技有限公司|沪公网安备31011502002146号|沪ICP备13033196号 |