首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从C#到Python的“简单”转换

从C#到Python的“简单”转换
EN

Stack Overflow用户
提问于 2018-05-03 18:01:57
回答 1查看 1.3K关注 0票数 0

使用Python,我正在尝试创建一个可以打印条形码标签的exe。这将与BarTender标签软件交互。我知道这是可能的,但我对Python是个新手,不知道该怎么做。我有它的C#,但我需要转换成Python.对于两种语言都懂的人来说,这是一种简单的转换吗?)

代码语言:javascript
运行
复制
// Declare a BarTender application variable
BarTender.Application btApp;
// Declare two BarTender document variables
BarTender.Format btFormat1;
BarTender.Format btFormat2;
// Create a new instance of BarTender
btApp = new BarTender.Application();
// Set the BarTender application visible
btApp.Visible = true;
// Open a BarTender document
btFormat1 = btApp.Formats.Open("c:\\Format1.btw", false, "");
// Open a second BarTender document
btFormat2 = btApp.Formats.Open("c:\\Format2.btw", false, "");
// Set focus to the first opened document
btFormat1.Activate();
// End the BarTender process
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

到目前为止,我已经

代码语言:javascript
运行
复制
import win32.com.client

btApp = win32com.client.Dispatch("BarTender.Application")
btApp.Visible = 1
btFormat = btApp.Formats.Open(r"C:\Users\kmoe\Desktop\Print-Self_Labels.btw", false, "")

第一个参数是必需的,它是一个包含要打开的文档的路径和文件名的字符串。第二个参数是一个布尔值:如果为真,则该方法将关闭BarTender启动时自动打开的名为"Document1“的默认空白文档。它无法关闭具有任何其他名称的文档。第三个参数指定要使用的打印机。

但是,这只会打开正确的标签模板,而不会打印到默认打印机

更多信息可以在这里找到

http://help.seagullscientific.com/2016/en/#../Subsystems/ActiveX/Content/opening_format.htm%3FTocPath%3DAutomating%2520BarTender%7CAutomation%2520with%2520ActiveX%7CGetting%2520Started%7CExamples%2520Using%2520ActiveX%2520Automation%7C_____1

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2020-02-19 21:45:34

我不得不从web服务器上实现Bartender标签打印,并且我无法使用安装的Bartender版本的Integration builder,所以我决定继续使用ActiveX。旧帖子,但这里是测试代码,如果其他人需要它。

代码语言:javascript
运行
复制
import win32com.client as win32

btApp = win32.Dispatch("BarTender.Application")
btApp.Visible = True


btFormat = btApp.Formats.Open("C:\\Users\\someUser\\Desktop\\YourLabel.btw", False, "PrinterName")

btFormat.SetNamedSubStringValue("btField1", "Data1")
btFormat.SetNamedSubStringValue("btField2", "Data2")
btFormat.SetNamedSubStringValue("btField3", "Data3")

btFormat.IdenticalCopiesOfLabel = 1
btFormat.PrintOut(False, False)
btFormat.Close(1)
btApp.Quit(1)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50152251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档