MS Word本身不支持直接插入条形码和二维码,可以使用条形码控件Spire.Barcode来创建条码图片,然后以图片的形式添加到Word中。
11月优惠进行时,消费满额即享折上豪礼,想买Spire.Doc的朋友赶快咨询在线客服吧!
推荐阅读:【想要快速完成文档格式转换吗pire系列组件格式转换完整攻略来啦!】
C# 在 Word 中添加条形码、二维码
使用条形码字体创建条形码
使用条形码字体创建条形码时,请确保字体已经正确至电脑中。按照默认路径安装后,在目录C:WindowsFonts下能查找到。

//创建Document对象,添加section及段落Document doc = new Document();Section section = doc.AddSection();Paragraph paragraph = section.AddParagraph();//添加文字“Code 128:”TextRange txtRang = paragraph.AppendText("Code 128:n");txtRang.CharacterFormat.FontSize = 15f;//添加条形码txtRang = paragraph.AppendText("H63TWX11072"); //条形码数据txtRang.CharacterFormat.FontName = "Code 128"; //应用条形码字体txtRang.CharacterFormat.FontSize = 60f;//将字体嵌入Word文档,使条形码能在未安装该字体的电脑中正确显示doc.EmbedFontsInFile = true;doc.EmbedSystemFonts = true;//保存文档doc.SaveToFile("Code128.docx", FileFormat.Docx2013);

使用Spire.Barcode创建条码(以二维码为例)图片,添加图片到Word文档
//创建Document对象,添加section及段落Document doc = new Document();Section section = doc.AddSection();Paragraph paragraph = section.AddParagraph();//添加文字“QR Code:”TextRange txtRang = paragraph.AppendText("QR Code:n");txtRang.CharacterFormat.FontSize = 15f;//使用Spire.Barcode的BarcodeSettings和BarcodeGenerator类创建二维码图形Spire.Barcode.BarcodeSettings settings = new BarcodeSettings();settings.Type = BarCodeType.QRCode;settings.Data = "123456789";settings.Data2D = "123456789";settings.X = 2f;settings.LeftMargin = 0;settings.ShowTextOnBottom = true;settings.QRCodeECL = QRCodeECL.Q;settings.QRCodeDataMode = QRCodeDataMode.Numeric;Spire.Barcode.BarCodeGenerator generator = new BarCodeGenerator(settings);Image image = generator.GenerateImage();//添加二维码图形到Wordparagraph.AppendPicture(image);//保存文档doc.SaveToFile("QRCode.docx", FileFormat.Docx2013);

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!