. NET the application of Barcode Library Two
Introduction
in the previous article, I have briefly introduced this library ( one of the barcode applications------------A brief introduction to the library of functions ). In this article I will use this library to provide more operations, I hope to be useful to everyone.
let's look at the following settings :
we have a lot of barcodes to deal with. Their types are stored in one column of the Excel file (such as Barcodetype), and their data is contained in another column (barcodedata). What we want to do is generate the corresponding barcodes based on their type and data and store them in the third column (barcodeimage). In logistics transactions or supermarkets, barcodes are used to identify goods. To remember that commodities are large and varied, it is unwise to use manual processing of barcodes.
We need a better way to get from gets the data in Excel. Under the moderator of this barcode function library We can easily finish this work (download https://freenetexcel.codeplex.com/here). Please refer to the following code:
Sample code
First step: Load Excel File:
Workbook Workbook =NewWorkbook ();
Workbook. LoadFromFile ("sourcefile.xlsx");
Worksheet sheet = workbook. worksheets[0];
Step Two: Use a for Loop to get Excel data in the.
intI
stringBarcodetype,barcodedata;
for(i =2; I<=sheet. AllocatedRange.Rows.Count (); i++)
{
Barcodetype = sheet. Range[i,1]. Text;
Barcodedata = sheet. Range[i,2]. Text;
}
Step three: Generate a barcode picture
Barcodesettings barsetting =NewBarcodesettings ();
Barsetting. Hasborder =true;
Barsetting. BorderWidth =0.5F;
Barsetting. Showtextonbottom =true;
Barsetting. Data = Barcodedata;
Barsetting. data2d = Barcodedata;
Barsetting. Type = (barcodetype) enum.parse (typeof(Barcodetype), barcodetype);
Barcodegenerator Bargenerator =NewBarcodegenerator (barsetting);
Image barcodeimage = Bargenerator. Generateimage ();
String fileName = String.Format ("Image-{0}.png", i);
Barcodeimage. Save (FileName);
Fourth Step: Add these pictures to the the specified area of Excel.
Sheet. Pictures.add (I,3, fileName);
Results
The following is the final Excel the effect of the file:
Application two of Barcode library in. NET