Imports Spire.Doc Imports Spire.Barcode Imports System.Drawing Imports System.IO Imports Spire.Doc.Documents Namespace AddQRCode Class Program Private Shared Sub Main(args As String()) '调用方法 ApplyKey(string key) 移除水印文字 Spire.Barcode.BarcodeSettings.ApplyKey("在这里输入去除水印字样的序列号") '创建Document对象,加载Word文档 Dim doc As New Document() doc.LoadFromFile("test.docx") '获取第2节 Dim section As Section = doc.Sections(1) '使用Spire.Barcode的BarcodeSettings和BarcodeGenerator类创建二维码并保存为图片 Dim settings As New BarcodeSettings() settings.Type = BarCodeType.QRCode settings.ImageWidth = 50 settings.ImageHeight = 50 settings.Data = "123456" settings.Data2D = "123456" settings.X = 0.7F settings.LeftMargin = 1 settings.ShowTextOnBottom = True settings.QRCodeECL = QRCodeECL.Q settings.QRCodeDataMode = QRCodeDataMode.Numeric Dim generator As New BarCodeGenerator(settings) Dim image As Image = generator.GenerateImage() 'image.Save("QRCode.png", System.Drawing.Imaging.ImageFormat.Png);//如果需要保存生成的二维码图片,可执行此步骤代码 '添加二维码到正文段落 Dim paragraph As Paragraph = section.AddParagraph() paragraph.AppendPicture(image) paragraph.Format.HorizontalAlignment = HorizontalAlignment.Right '添加二维码图片到Word页眉 Dim header As HeaderFooter = section.HeadersFooters.Header 'HeaderFooter footer = section.HeadersFooters.Footer;//获取页脚 Dim headerpara As Paragraph = header.AddParagraph() headerpara.AppendPicture(image) headerpara.Format.HorizontalAlignment = HorizontalAlignment.Center '保存文档 doc.SaveToFile("QRCodeToHeader.docx", FileFormat.Docx2013) System.Diagnostics.Process.Start("QRCodeToHeader.docx") End Sub End Class End Namespace
二维码添加效果:
以上就是C#/VB.NET 在Word中添加条码、二维码的示例代码的详细内容,更多关于C#/VB.NET 在Word中添加条码、二维码的资料请关注脚本之家其它相关文章!
您可能感兴趣的文章: