一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - vb.net - C#/VB.NET 在Word中添加條碼、二維碼的示例代碼

C#/VB.NET 在Word中添加條碼、二維碼的示例代碼

2021-11-30 14:00E-iceblue vb.net

這篇文章主要介紹了C#/VB.NET 如何在Word中添加條碼、二維碼,代碼中將分為在Word正文段落中、頁眉頁腳中等情況來添加。感興趣的朋友可以了解下

本文介紹如何通過c# 和vb.net代碼實現在word文檔中添加條碼二維碼。代碼中將分為在word正文段落中、頁眉頁腳中等情況來添加。

使用工具:

free spire.office for .net (免費版)

工具簡介:

這是spire所有.net平臺下免費產品的集合包,包含spire.barcode.dll、spire.dataexport.dll、spire.pdf.dll、spire.doc.dll、spire.docviewer.forms.dll 、spire.pdfviewer.forms.dll 、spire.presentation.dll 、spire.xls.dll等dll可用于操作word/pdf/excel/ppt等文件。

本文添加條碼、二維碼需要在vs程序中添加引用 spire.doc.dll 和 spire.barcode.dll 這兩個dll文件。

dll添加引用效果:

C#/VB.NET 在Word中添加條碼、二維碼的示例代碼

注意:

1. 需要下載安裝到本地指定路徑,dll文件可在安裝路徑下的bin文件夾下獲取。

2. 生成的條碼、二維碼會有水印字樣的文字,可通過此方法去除。

代碼示例

1. 添加條碼到word

c#

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using spire.doc;
using spire.barcode;
using system.drawing;
using system.io;
using spire.doc.documents;
 
namespace addbarcode
{
  class program
  {
    static void main(string[] args)
    {
      //調用方法 applykey(string key) 移除水印文字
      spire.barcode.barcodesettings.applykey("在這里輸入去除水印字樣的序列號");
 
      //創建document對象,加載word文檔
      document doc = new document();
      doc.loadfromfile("test.docx");
 
      //獲取第2節
      section section = doc.sections[1];
 
      //使用spire.barcode的barcodesettings和barcodegenerator類創建條碼并保存為圖片
      barcodesettings settings = new barcodesettings();
      settings.type = barcodetype.code128;
      settings.data = "123456789";
      settings.data2d = "123456789";
      settings.showtext = false;
      settings.barheight = 4;
      settings.x = 0.3f;
      settings.hasborder = true;
      settings.borderwidth = 0.5f;
      settings.bordercolor = color.aliceblue;
      settings.backcolor = color.wheat;
      barcodegenerator barcodegenerator = new barcodegenerator(settings);
      image image = barcodegenerator.generateimage();
      //image.save("barcode.png", system.drawing.imaging.imageformat.png);//如果需要保存生成的barcode圖片,可執行此步驟代碼
 
      //添加條碼到正文段落
      paragraph paragraph = section.addparagraph();
      paragraph.text = "收貨碼:";
      paragraph.appendpicture(image);
      paragraph.format.horizontalalignment = horizontalalignment.right;
 
      //添加條碼圖片到word頁腳
      headerfooter footer = section.headersfooters.footer;
      paragraph footerpara = footer.addparagraph();
      footerpara.text = "掃碼識真偽:";
      footerpara.appendpicture(image);
      footerpara.format.horizontalalignment = horizontalalignment.left;
 
      //保存文檔
      doc.savetofile("barcodetoword.docx", fileformat.docx2013);
      system.diagnostics.process.start("barcodetoword.docx");
    }
  }
}

vb.net

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
imports spire.doc
imports spire.barcode
imports system.drawing
imports system.io
imports spire.doc.documents
 
 
namespace addbarcode
  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.code128
      settings.data = "123456789"
      settings.data2d = "123456789"
      settings.showtext = false
      settings.barheight = 4
      settings.x = 0.3f
      settings.hasborder = true
      settings.borderwidth = 0.5f
      settings.bordercolor = color.aliceblue
      settings.backcolor = color.wheat
      dim barcodegenerator as new barcodegenerator(settings)
      dim image as image = barcodegenerator.generateimage()
      'image.save("barcode.png", system.drawing.imaging.imageformat.png);//如果需要保存生成的barcode圖片,可執行此步驟代碼
 
      '添加條碼到正文段落
      dim paragraph as paragraph = section.addparagraph()
      paragraph.text = "收貨碼:"
      paragraph.appendpicture(image)
      paragraph.format.horizontalalignment = horizontalalignment.right
 
      '添加條碼圖片到word頁腳
      dim footer as headerfooter = section.headersfooters.footer
      dim footerpara as paragraph = footer.addparagraph()
      footerpara.text = "掃碼識真偽:"
      footerpara.appendpicture(image)
      footerpara.format.horizontalalignment = horizontalalignment.left
 
      '保存文檔
      doc.savetofile("barcodetoword.docx", fileformat.docx2013)
      system.diagnostics.process.start("barcodetoword.docx")
    end sub
  end class
end namespace

條碼添加效果:

C#/VB.NET 在Word中添加條碼、二維碼的示例代碼

2. 添加二維碼到word

c#

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using spire.doc;
using spire.barcode;
using system.drawing;
using system.io;
using spire.doc.documents;
using system;
 
 
namespace addqrcode
{
  class program
  {
    static void main(string[] args)
    {
      //調用方法 applykey(string key) 移除水印文字
      spire.barcode.barcodesettings.applykey("在這里輸入去除水印字樣的序列號");
 
      //創建document對象,加載word文檔
      document doc = new document();
      doc.loadfromfile("test.docx");
 
      //獲取第2節
      section section = doc.sections[1];
 
      //使用spire.barcode的barcodesettings和barcodegenerator類創建二維碼并保存為圖片
      barcodesettings settings = 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;
      barcodegenerator generator = new barcodegenerator(settings);
      image image = generator.generateimage();
      //image.save("qrcode.png", system.drawing.imaging.imageformat.png);//如果需要保存生成的二維碼圖片,可執行此步驟代碼
 
      //添加二維碼到正文段落
      paragraph paragraph = section.addparagraph();    
      paragraph.appendpicture(image);
      paragraph.format.horizontalalignment = horizontalalignment.right;
 
      //添加二維碼圖片到word頁眉
      headerfooter header = section.headersfooters.header;
      //headerfooter footer = section.headersfooters.footer;//獲取頁腳
      paragraph headerpara = header.addparagraph();
      headerpara.appendpicture(image);
      headerpara.format.horizontalalignment = horizontalalignment.center;
      
 
      //保存文檔
      doc.savetofile("qrcodetoheader.docx", fileformat.docx2013);
      system.diagnostics.process.start("qrcodetoheader.docx");
    }
  }
}

vb.net

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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中添加條碼、二維碼的示例代碼的詳細內容,更多關于c#/vb.net 在word中添加條碼、二維碼的資料請關注服務器之家其它相關文章!

原文鏈接:https://www.cnblogs.com/Yesi/p/13322749.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲激情自拍偷拍 | 日韩精品福利视频一区二区三区 | 小向美奈子av | 色老板影视| 欧美一区高清 | 秋霞黄色片 | 日韩欧美高清一区 | 日本一区二区三区国产 | www亚洲色图 | 9lporm自拍视频在线 | 男人狂擦女人的下面视频 | 国内精品91东航翘臀女神在线 | 国产精品免费综合一区视频 | 午夜宅男在线观看 | 东京道一本热大交乱 | 9966久久精品免费看国产 | 操老逼| 草逼视频免费看 | 天天操夜夜操狠狠操 | 亚洲一欧洲中文字幕在线 | 91热这里只有精品 | 性满足久久久久久久久 | 搓光美女衣 | caopren免费视频国产 | 公妇乱淫在线播放免费观看 | 国产精品久久久久久久久免费观看 | aⅴ天堂小视频 | 插得爽| 免费观看一级欧美在线视频 | 3d欧美人禽交 | 国产色视频网站 | 色噜噜国产精品视频一区二区 | 私人影院在线免费观看 | 丁香婷婷在线视频 | 教室眠催白丝美女校花 | 寡妇快点好大好爽视频 | 亚洲国产精品无码中文字幕 | 亚洲欧美一区二区三区在线观看 | 91麻豆制片厂 | 久久婷婷五月综合色丁香花 | 亚洲图片 自拍偷拍 |