[AccessLogAttribute(Note = "导出条形码箱单 — 条形码")]
public ActionResult ExportContract(string INNER_NO)
{

try
{
string export = "条形码箱单.xls";
CommonResult cr = new CommonResult();
DataSet ds = new DataSet();

//获得表头数据  
DataTable dtHead1 = new DataTable();

//获得方法  具体参数可以根据需要传
dtHead1 = tab1Servcie.QRGetInvoiceFirstHead(INNER_NO, CurrentCorporation.SITE);

//获得表体数据
DataTable dtList1 = new DataTable();
dtList1 = tab1Servcie.QRGetInvoiceFirstList(INNER_NO, CurrentCorporation.SITE);
ds.Tables.Add(dtHead1);
ds.Tables.Add(dtList1);

//导出(需要配置XML)
ds.Tables[0].TableName = "Export_Invoice_QR_HEAD";
ds.Tables[1].TableName = "Export_Invoice_QR_LIST";
Dictionary<string, List<ExportItem>> dicMapping = FileHelper.GetMappingDictionary(this, "WExport.xml", false, "Export_Invoice_QR");
Dictionary<string, string> dicSheetName = new Dictionary<string, string>();
dicSheetName.Add("Export_Invoice_QR", "装箱单");
return Step3(export.Substring(0, export.Length - 4), ds, dicMapping, dicSheetName, GetFilePhysicalPath("/Content/ExportTemplate/Dec/" + export, false), INNER_NO);
}
catch (Exception e)
{
CommonResult cr = new CommonResult();
cr.ErrorMessage = e.Message;
return Json(cr);
}
}

/// <summary>
/// 打印二维码
/// </summary>
/// <param name="fileName"></param>
/// <param name="ds"></param>
/// <param name="dicMapping"></param>
/// <param name="dicSheetName"></param>
/// <param name="tempaltePath"></param>
/// <param name="inner_no">内部编号(数据的标识编号)</param>
/// <returns></returns>
public ActionResult Step3(string fileName, DataSet ds, Dictionary<string, List<ExportItem>> dicMapping, Dictionary<string, string> dicSheetName, string tempaltePath, string inner_no)
{
string path1 = "";
CommonResult commonResult = new CommonResult();
try
{
//地址
string a = Path.GetExtension(tempaltePath);
commonResult.ErrorMessage = NPOIHelper.SaveExcel(fileName, NPOIHelper.ExportToMemoryStream(ds, dicMapping, dicSheetName, tempaltePath, false), Path.GetExtension(tempaltePath));
commonResult.Success = true;
commonResult.Data1 = AppDomain.CurrentDomain.BaseDirectory + commonResult.ErrorMessage;
path1 = commonResult.Data1;
commonResult.ErrorMessage = BaseController.Host + BaseController.ApplicationPath + commonResult.ErrorMessage;
FileStream file = new FileStream(@commonResult.Data1, FileMode.Open, FileAccess.ReadWrite);
HSSFWorkbook excelBook = new HSSFWorkbook(file);
ISheet sheet = excelBook.GetSheet("装箱单");
List<PIDMSHNotifyThird> lists = tab1Servcie.GetThirdList(inner_no, CurrentCorporation.SITE);
//拆分 生产日期 生产批号 数量
Image image;
int width =200, height = 60;
int lastRow = lists.Count * 30;
for (int k = 0; k < lastRow; k++)
{

//创建行 (如果不创建会出现二维码积压覆盖) 
IRow row = sheet.CreateRow(28 + k); //创建行对象 --注意这点
row.HeightInPoints = (float)(0.91 * 15.00);

for (int line = 0; line < 13; line++)
{
ICell cell1 = row.CreateCell(line); //在第二行中创建单元格
ICellStyle style = excelBook.CreateCellStyle();
}
}

//自适应界面
//for (int i = 0; i < lists.Count; i++)
//{
// int _Row = 16;
// int currLine = _Row + i * 4;
// int rowCount = sheet.LastRowNum;
// if (i % 9 == 0 && i != 0)
// {
// currLine = currLine + 4;
// }
// excelBook.SetPrintArea(0, 0, 10, 0, 30);
// //是否自适应界面
// sheet.FitToPage = false;
//}
excelBook.SetPrintArea(0, 0, 10, 0, lastRow);
//是否自适应界面
sheet.FitToPage = false;
int result = 28;

for (int i = 0; i < lists.Count; i++)
{
string[] strCount = null;
if (lists[i].NET_WT_SEP!=null)
{
strCount = lists[i].NET_WT_SEP.Split(','); //数量分批
}
string[] strNo = null;
if (lists[i].PROD_BATCH_NO_SEP!=null)
{
strNo = lists[i].PROD_BATCH_NO_SEP.Split(','); //生产批号分批
}
string[] strDate = null;
if (lists[i].PRODUCE_DATE!=null)
{
strDate = lists[i].PRODUCE_DATE.Split(','); //生产日期分批
}

if (strCount.Length== strNo.Length&& strNo.Length== strDate.Length&& strNo.Length!=0 && strDate!=null && strNo != null && strCount != null)
{

for (int j = 0; j < strCount.Length; j++)
{
//[Display(Name = "客户货号")]
//public string NOTE { get; set; }
if (lists[i].NOTE != null)
{
byte[] note = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, lists[i].NOTE, out image);
sheet.GetRow((j+1) * 4 + result).GetCell(1).SetCellValue(lists[i].NOTE);
int pictureIdx = excelBook.AddPicture(note, PictureType.PNG);
HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(100, 50, 950, 0, 0, result+1 + (j + 1) * 4, 2, result+3 + (j + 1) * 4);
HSSFPicture pict = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIdx);
}

// string[] strNo = lists[i].PROD_BATCH_NO_SEP.Split(','); //生产批号分批
if (strNo[j]!= null)
{
byte[] prod = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, strNo[j], out image);
sheet.GetRow((j + 1) * 4 + result).GetCell(4).SetCellValue(strNo[j]);
int pictureIdx1 = excelBook.AddPicture(prod, PictureType.PNG);
HSSFPatriarch patriarch1 = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
HSSFClientAnchor anchor1 = new HSSFClientAnchor(300, 50, 900, 0, 3, result + 1+ (j + 1) * 4, 5, result + 3 + (j + 1) * 4);
HSSFPicture pict1 = (HSSFPicture)patriarch1.CreatePicture(anchor1, pictureIdx1);
}

// string[] strCount = lists[i].NET_WT_SEP.Split(','); //数量分批
if (strCount[j] != null)
{
byte[] net_no = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, strCount[j], out image);
sheet.GetRow((j + 1) * 4 + result).GetCell(6).SetCellValue(strCount[j]);
int pictureIdx2 = excelBook.AddPicture(net_no, PictureType.PNG);
HSSFPatriarch patriarch2 = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
HSSFClientAnchor anchor2 = new HSSFClientAnchor(300, 50, 500, 0, 6, result + 1 + (j + 1) * 4, 7, result + 3 + (j + 1) * 4);
HSSFPicture pict2 = (HSSFPicture)patriarch2.CreatePicture(anchor2, pictureIdx2);
}

// string[] strDate = lists[i].PRODUCE_DATE.Split(','); //生产日期分批
if (strDate[j] != null)
{
byte[] prodce = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, strDate[j], out image);
sheet.GetRow((j + 1) * 4 + result).GetCell(9).SetCellValue(strDate[j]);
int pictureIdx3 = excelBook.AddPicture(prodce, PictureType.PNG);
HSSFPatriarch patriarch3 = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
HSSFClientAnchor anchor3 = new HSSFClientAnchor(300, 50, 500, 0, 8, result + 1 + (j + 1) * 4, 10, result + 3 + (j + 1) * 4);
HSSFPicture pict3 = (HSSFPicture)patriarch3.CreatePicture(anchor3, pictureIdx3);
}
if (j+1== strCount.Length)
{
result = result + (j + 1) * 4;
}

}
}
}

string FileN = "/Temp/Export/" + fileName + CommonHelper.GetGuid() + ".xls";
string path = AppDomain.CurrentDomain.BaseDirectory + FileN;
commonResult.Data1 = path;
commonResult.ErrorMessage = BaseController.Host + BaseController.ApplicationPath + FileN;
FileStream files = new FileStream(@path, FileMode.Append);
excelBook.Write(files);
//释放文件流
file.Close();
file.Dispose();
files.Close();
files.Dispose();
}
catch (Exception ex)
{
commonResult.ErrorMessage = ex.Message;
}
finally
{

}
return base.Json(commonResult, 0);
}

static byte[] GetBarcode(int height, int width, TYPE type, string code, out Image image)
{
image = null;
Barcode b = new Barcode();
b.BackColor = Color.White;
b.ForeColor = Color.Black;
b.IncludeLabel = false;
b.Alignment = AlignmentPositions.CENTER;
b.LabelPosition = LabelPositions.BOTTOMCENTER;
b.ImageFormat = ImageFormat.Jpeg;
Font font = new Font("verdana", 10f);
b.LabelFont = font;
b.Height = height;
b.Width = width;
b.Encode(type, code);
byte[] buffer = b.GetImageData(SaveTypes.JPG);
return buffer;
}

.Net core_Excel 导出二维码(以导出箱单为例)的更多相关文章

  1. PHP生成二维码【谷歌API+qrcode+圆角Logo】

    方法一:谷歌二维码API 接口地址:https://chart.googleapis.com/chart 官方文档:https://developers.google.com/chart/infogr ...

  2. 使用zxing生成二维码 - servlet形式

    因为项目有个功能需要打印二维码,因为我比较喜欢使用html+css+js实现,所以首先想到的是jquery.qrcode.js插件,这个插件可以用canvas和table生成二维码,效果也不错,不过对 ...

  3. 使用ZXing.Net生成与识别二维码(QR Code)

    Google ZXing是目前一个常用的基于Java实现的多种格式的1D/2D条码图像处理库,出于其开源的特性其现在已有多平台版本.比如今天要用到的ZXing.Net就是针对微软.Net平台的版本.使 ...

  4. Java与JS生成二维码

    1.二维码概念 二维码/二维条码是用某种特定的集合图形按一定规律在平面上(二维方向上)分布的黑白相间的图形记录数据符号信息的图片. 黑线是二进制的1,空白的地方是二进制的0,通过1.0这种数据组合用于 ...

  5. 在ts+vue中实现前端批量下载打包二维码

    ---恢复内容开始--- 一.插件安装 首先是插件的安装与引入,这里我们用的是qrcode的这个插件,直接使用npm install qrcodejs2安装即可,但是这里要注意,如果你用的是ts进行开 ...

  6. php生成微信小程序二维码源码

    目前有3个接口可以生成小程序码,开发者可以根据自己的需要选择合适的接口.第一步:获取   access_token public function getWxAccessToken(){ $appid ...

  7. 杂项收集,包括-发邮件、二维码生成、文件下载、压缩、导出excel

    本篇就最近工作解决的问题做个代码收集.包括以下几个方面:发邮件.二维码生成.文件下载.压缩.导出excel.有一种可用的解决方法就好,不求全面,不求原理. 1.发邮件: 命名空间:System.Net ...

  8. [Unity3D]自制UnityForAndroid二维码扫描插件

    一周左右终于将二维码生成和扫描功能给实现了,终于能舒缓一口气了,从一开始的疑惑为啥不同的扫码客户端为啥扫出来的效果不同?通用的扫描器扫出来就是一个下载APK,自制的扫描器扫出来是想要的有效信息,然后分 ...

  9. 制作IOS企业版App网页扫描二维码下载安装

    有时候我们需要在XX网站的主页上去扫描二维码下载,那么ios开发中如何做到这一点呢. 我给大家解答一下,这也是在最近工作中用到的部分,在网上了解了一些. 下面给大家分解一下步骤: 1.Plist 和 ...

随机推荐

  1. 掌握git命令的正确使用姿势

    前言 最近在团队内部发起了一个小的python项目(用tkinter实现一个小工具),但是发现大家对git的使用还不太熟悉,不知道怎么同步代码.解决冲突等等.因为我觉得对测试工程师来说,git应该是必 ...

  2. 8行代码批量下载GitHub上的图片

    [问题来源] 来打算写一个的小游戏,但是图片都在GitHub仓库中,GitHub网页版又没有批量下载图片的功能,只有单独一张一张的下载,所以自己就写了个爬虫脚本模拟人的操作把整个页面上需要的图片爬取下 ...

  3. day7-format字符串格式化

    tpl = "i am {name}, age {age}, really {name}".format(name="seven", age=18) print ...

  4. Chrome Extension 小试牛刀

    自从有了Chrome以后,就喜欢上了这个浏览器,从此IE 886了. 以前作爬虫,做登录,做数据采集,做数据处理等各种功能,后来H5出来后,出现了,除了Session/Cookie 出了Local S ...

  5. 解决vuex的数据刷新(F5)后会被初始化的问题

    介绍一个vuex的数据刷新(F5)后会被初始化的问题处理的插件:vuex-localstorage 实现的原理大概就是监听浏览器的刷新,关闭事件,把vuex的值存储到本地localstorage,刷新 ...

  6. ThinkPHP的主从数据库配置

    Thinkphp 框架本身是支持读写分离的,如何做呢?   最简单的做法是在配置文件中修改:   PHP代码 'DB_TYPE'=> 'mysql', 'DB_DEPLOY_TYPE' => ...

  7. 用IDEA导入Eclipse的JavaWEB项目

    1.File----Open 2.选择项目路径 点击OK,这时候会弹出一个窗口,让你选择本窗口打开项目还是新建一个窗口,这个随意. 3.添加WEB框架 4.添加各种自己需要的jar包 5.添加Tomc ...

  8. Java枚举——枚举的作用、使用方法、使用场景

    枚举的定义 枚举关键字enum 枚举类是一种特殊类,它和普通类一样可以使用构造器.定义成员变量和方法,也可以实现多个接口,但不能继承类. 枚举的使用 enum Color { RED, BLUE, G ...

  9. shell——数组

    默认从0开始索引:也可以单独(像字典一样)pid[35420]=httpd -k ssl, 只能是一维的 bash4.0增加了关联数组 数组赋值: declare -a myarray声明数组 一次一 ...

  10. ZeroC ICE的远程调用框架 Callback(一)-AMI异步方法调用框架

    Ice框架提供了不少回调设施,其中一些是使用Ice远程调用进行ami模式或amd模式的支撑.本篇来看一下用于代理端的回调设施. Ice代码中有好几个Callback相关命名的基类,并且slice还会为 ...