Grid++Report 组件使用最简代码

在‘添加引用’窗口中选择‘COM’选项卡,在列表中双击‘Grid++Report Engine 6.0 Type Library’项


使用设计器设计一个模板 ,加入 vs2022 项目   设置为 文件新则拷贝

image

因为是打印标签 ,数据有限,所以模板使用参数传递数据,纸型按实际标签的长宽设置

image


c# 调用模板的代码如下

private void 打印()
{
     var anonymousEntity = new
     {
         条码 = "232500476910-0002",
         反应时间 = DateTime.Now,
         出料重量 = 2000,
         开罐时间 = DateTime.Now,
         测试时间 = DateTime.Now,
         粘度值 = 1800
     };
     GridppReport Report = new GridppReport();
     Report.LoadFromFile(Environment.CurrentDirectory + "\\PI.grf");
     报表压入参数(anonymousEntity, Report);
     Report.Print(false);
}



private void 报表压入参数(object anonymousEntity, GridppReport Report)
{
     Type type = anonymousEntity.GetType();
     var properties = type.GetProperties();
     foreach (var property in properties)
     {
         Report.ParameterByName($"{property.Name}").Value = Convert.ToString(property.GetValue(anonymousEntity));
     }
}

posted @ 2024-08-17 08:33  网络来者  阅读(707)  评论(0)    收藏  举报