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

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产成人免费高清激情明星 | 亚洲第一色视频 | 国产乱码免费卡1卡二卡3卡四 | 国产亚洲精品91 | 我把寡妇日出水好爽 | 我要看免费毛片 | 免费视频 久久久 | 亚洲国产欧美目韩成人综合 | 嫩草影院国产 | 俄罗斯女人与公拘i交酡 | 久久r视频| tube69xxxxhd日本| 亚洲va欧美va国产va天堂影 | 成年人免费在线看的惊悚动作片 | 欧美日韩一区二区三区在线观看 | 欧美一区二区三区在线观看不卡 | 精品久久久久久午夜 | 免费视频一区 | 欧美成人免费观看久久 | 青青国产在线观看 | 紧身牛仔裤美女被啪啪久久网 | 日韩精品欧美 | 91高清免费国产自产 | 色噜噜国产精品视频一区二区 | 日本护士xxxx视频免费 | 爽好舒服宝贝添奶吻戏 | 欧美日韩一区二区三区免费不卡 | a免费看| 国产在线视频色综合 | 视频国产91 | 久久久精品免费免费直播 | 91精品国产亚一区二区三区 | 日本三级欧美三级人妇英文 | 成年性生交大片免费看 | а天堂中文最新版在线官网视频 | 日本免费在线观看 | 色愉拍亚洲偷自拍 | 国产成人盗拍精品免费视频 | 精品久久久久香蕉网 | 99视频观看 | 免费看日韩 |