需求:把excel明细批量生成word文档,每条明细生成1个文档。
将上面的WIFI用户名、密码填到word文档中相应位置,并且需要插入图片。
通常用的是word邮件合并功能,但是步骤多,麻烦。插件简化了导出步骤,使用特别简单。
操作步骤:
- 制作模板
我们把需要更新的位置,根据excel中的列对应关系,标注出来。例如,excel中是WIFI用户名,那我们在word中相应位置就写上【WIFI用户名】,以此类推即可。
注意:需要插入图片的位置,也要单独标注。 Excel表格中,列出来图片的名称。
- 开始生成
选择word模板路径,选择数据源的明细区域(包含标题行,且标题行位于第一行),如果需要插入图片,要单独把图片的名字列入到表格中。
支持生成到1个word中,也支持生成多个word文档。结果如下:
成功!
Imports System.Windows.Forms
Public Class Form1
Private Const WM_DRAWCLIPBOARD As Integer = &H308
Private Const WM_CHANGECBCHAIN As Integer = &H30D
Private mNextClipBoardViewerHWnd As IntPtr
Declare Auto Function SetClipboardViewer Lib "user32" (ByVal HWnd As IntPtr) As IntPtr
Declare Auto Function ChangeClipboardChain Lib "user32" (ByVal HWnd As IntPtr, ByVal HWndNext As IntPtr) As Boolean
Declare Auto Function SendMessage Lib "User32" (ByVal HWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Long
Public Sub NewViewer()
mNextClipBoardViewerHWnd = SetClipboardViewer(Me.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case Is = WM_DRAWCLIPBOARD 'The clipboard has changed...
SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)
If Clipboard.ContainsText = True Then
TextBox1.Text = Clipboard.GetText
End If
If Clipboard.ContainsImage() = True Then
PictureBox1.Image = Clipboard.GetImage()
PictureBox1.Update()
End If
Case Is = WM_CHANGECBCHAIN 'Another clipboard viewer has removed itself...
If m.WParam = CType(mNextClipBoardViewerHWnd, IntPtr) Then
mNextClipBoardViewerHWnd = m.LParam
Else
SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)
End If
End Select
MyBase.WndProc(m)
End Sub
Private Sub clipboardMon_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NewViewer()
End Sub
End Class