// 示例代码:使用 C# 和 Bartender 打印标签
using System;
using Bartender;
class Program
{
static void Main(string[] args)
{
// 创建一个新的 Bartender 应用程序对象
Application btApp = new Application();
// 打开现有的 Bartender 模板文件
string templatePath = @"C:\Labels\SampleTemplate.btw";
Document btDoc = btApp.OpenDocument(templatePath);
// 设置标签上的数据源
btDoc.SetNamedSubStringValue("ItemName", "Sample Item");
btDoc.SetNamedSubStringValue("ItemQuantity", "10");
// 打印标签
btDoc.PrintOut();
// 关闭文档和应用程序
btDoc.Close();
btApp.Quit();
}
}
引用 Bartender 命名空间:
using Bartender;
引入了 Bartender 的命名空间,使你可以使用 Bartender 提供的类和方法。创建 Bartender 应用程序对象:
Application btApp = new Application();
创建了一个新的 Bartender 应用程序实例,用于与 Bartender 进行交互。打开模板文件:
string templatePath = @"C:\Labels\SampleTemplate.btw";
定义了要打开的模板文件路径。Document btDoc = btApp.OpenDocument(templatePath);
打开了指定路径的模板文件。设置数据源:
btDoc.SetNamedSubStringValue("ItemName", "Sample Item");
和 btDoc.SetNamedSubStringValue("ItemQuantity", "10");
为模板中的占位符设置了具体的值。这里假设模板中有名为 ItemName
和 ItemQuantity
的占位符。打印标签:
btDoc.PrintOut();
调用了打印方法,将标签发送到打印机进行打印。关闭文档和应用程序:
btDoc.Close();
和 btApp.Quit();
分别关闭了文档和应用程序,释放资源。希望这段代码和解释对你有帮助!
上一篇:c#string分割
下一篇:c# 入门
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站