QrCodeNet 二维码

例子为 项目中 导出 Excel 在某一列增加二维码 ,使用的是 Interop.Excel.dll      Gma.QrCodeNet.Encoding.Net35.dll  

using Gma.QrCodeNet.Encoding;
using Gma.QrCodeNet.Encoding.Windows.Render;



Range pic = worksheet.get_Range(worksheet.Cells[j, 18], worksheet.Cells[j, 18]);
pic.Select();
float PicLeft, PicTop;
PicLeft = Convert.ToSingle(pic.Left);
PicTop = Convert.ToSingle(pic.Top);

string str = "http://oa.kingtech-mould.com/UpdateMaterielPorc/Index?id1="+BOM_Model.id1; 
var qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode;
qrEncoder.TryEncode(str, out qrCode);
var codeSize = new FixedCodeSize(100, QuietZoneModules.Zero); // 图片大小
var gRenderer = new GraphicsRenderer(
codeSize,
Brushes.Black, Brushes.White);
var ms = new MemoryStream();
gRenderer.WriteToStream(qrCode.Matrix, System.Drawing.Imaging.ImageFormat.Png, ms);
System.Drawing.Image img = new Bitmap(ms);
string imgPath = "\\" + Guid.NewGuid() + ".jpg";
// pictureBox1.Image = img;
string webFilePath = pf.ReadXmlNode(Server.MapPath("~") + "\\config\\system.xml", "//system//file//files");// 服务器端原图路径 
img.Save(webFilePath + imgPath);
worksheet.Shapes.AddPicture(webFilePath + imgPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, PicLeft+2, PicTop+2, 20, 20);
img.Dispose();
File.Delete(webFilePath + imgPath);

asas

你可能感兴趣的:(QrCodeNet 二维码)