- [VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
- [VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview
- GIỚI THIỆU TOOL: DUAL MESSENGER TOOLKIT
- [PHẦN MỀM] Giới thiệu Phần mềm Gmap Extractor
- Hướng Dẫn Đăng Nhập Nhiều Tài Khoản Zalo Trên Máy Tính Cực Kỳ Đơn Giản
- [C#] Chia sẻ source code phần mềm đếm số trang tập tin file PDF
- [C#] Cách Sử Dụng DeviceId trong C# Để Tạo Khóa Cho Ứng Dụng
- [SQLSERVER] Loại bỏ Restricted User trên database MSSQL
- [C#] Hướng dẫn tạo mã QRcode Style trên winform
- [C#] Hướng dẫn sử dụng temp mail service api trên winform
- [C#] Hướng dẫn tạo mã thanh toán VietQR Pay không sử dụng API trên winform
- [C#] Hướng Dẫn Tạo Windows Service Đơn Giản Bằng Topshelf
- [C#] Chia sẻ source code đọc dữ liệu từ Google Sheet trên winform
- [C#] Chia sẻ source code tạo mã QR MOMO đa năng Winform
- [C#] Chia sẻ source code phần mềm lên lịch tự động chạy ứng dụng Scheduler Task Winform
- [Phần mềm] Tải và cài đặt phần mềm Sublime Text 4180 full version
- [C#] Hướng dẫn download file từ Minio Server Winform
- [C#] Hướng dẫn đăng nhập zalo login sử dụng API v4 trên winform
- [SOFTWARE] Phần mềm gởi tin nhắn Zalo Marketing Pro giá rẻ mềm nhất thị trường
- [C#] Việt hóa Text Button trên MessageBox Dialog Winform
[VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
Xin chào các bạn, bài viết hôm nay mình tiếp tục hướng dẫn các bạn cách fill dữ liệu từ winform vào file tài liệu microsoft word.
[VB.NET] How to fill data from winform to Microsoft Word Template File.
Dưới đây là video demo ứng dụng:
Đầu tiên, các bạn cần cài đặt thư viện DocX
.
Thư viện này có cung cấp 2 phiên bản: cá nhân và thương mại.
Nếu dùng cá nhân thì vẫn dùng bình thường nhé bạn.
Source code vb.net:
Imports Xceed.Words.NET
Public Class Form1
Private templatePath As String = "Template.docx"
Private outputPath As String = "Output.docx"
Private newImagePath As String = ""
<Obsolete>
Private Sub btnFillToWord_Click(sender As Object, e As EventArgs) Handles btnFillToWord.Click
Try
Dim document As DocX = DocX.Load(templatePath)
document.ReplaceText("<sohopdong>", txtSoHopDong.Text.Trim())
document.ReplaceText("<tenkhachhang>", txtTenKhachHang.Text.Trim())
document.ReplaceText("<dienthoai>", txtDienThoai.Text.Trim())
document.ReplaceText("<diachi>", txtDiaChi.Text.Trim())
If newImagePath <> "" Then
Dim placeholderParagraph = document.Paragraphs.FirstOrDefault(Function(p) p.Text.Contains("<hinhkhachhang>"))
If placeholderParagraph IsNot Nothing Then
Dim img = document.AddImage(newImagePath)
Dim picture = img.CreatePicture()
picture.Width = 80
picture.Height = 100
placeholderParagraph.InsertPicture(picture)
document.ReplaceText("<hinhkhachhang>", "")
Else
MessageBox.Show("The picture placeholder was not found in the document.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
document.SaveAs(outputPath)
MessageBox.Show("File Word đã được tạo thành công tại:" & vbCrLf & outputPath, "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information)
Process.Start(outputPath)
Catch ex As Exception
MessageBox.Show("Có lỗi xảy ra: " & ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim dlg = New OpenFileDialog()
If dlg.ShowDialog() = DialogResult.OK Then
newImagePath = dlg.FileName
PictureBox1.LoadAsync(newImagePath)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Thanks for watching!