周一至周五 : 08:30 - 17:30 客服专员电话/微信:17301649370 QQ:2982200781
微信咨询

扫码微信咨询

关注公众号

关注微信公众号

电话: 021 5161 9370
返回顶部
咨询 快表VBA中引用第三方打印dll??
显示全部楼层 倒序浏览 发表日期 2025-12-15 09:39:09 70次阅读 3次回复

itextsharp.7z.rar

802.09 KB, 下载次数: 0

目前想用第三方的打印控件iTextSharp.dll

在快表vba中

Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.pdf.security

直接导入好像不可以,咨询大神导入方法,如此就可以更灵活的完成复杂的打印操作了
可以参考:


  1. Public Sub CallImgToPdfAsync(urls As Object(, ), outputPdf As String)
  2.                         'Dim exePath As String = "C:\Users\Administrator\source\repos\imgTopdf\bin\Debug\ImgToPdf.exe"
  3.                         Dim exePath As String = Directory.GetCurrentDirectory() + "\Dll\topdf\ImgToPdf.exe"
  4.                         ' urls参数是二维数组,每行所有列用逗号分隔
  5.                         Dim arguments As New System.Text.StringBuilder()
  6.                         If urls IsNot Nothing Then
  7.                                 Dim rows As Integer = urls.GetLength(0)
  8.                                 Dim cols As Integer = urls.GetLength(1)
  9.                                 Dim first As Boolean = True
  10.                                 For r As Integer = 0 To rows - 1
  11.                                         Dim arr As New List(Of String)()
  12.                                         For c As Integer = 0 To cols - 1
  13.                                                 Dim val As String = ""
  14.                                                 If urls(r, c) IsNot Nothing Then val = urls(r, c).ToString().Trim()
  15.                                                 arr.Add(val)
  16.                                         Next
  17.                                         If arr(0) <> "" Then
  18.                                                 If Not first Then arguments.Append(" ")
  19.                                                 arguments.Append(String.Join(",", arr))
  20.                                                 first = False
  21.                                         End If
  22.                                 Next
  23.                         End If
  24.                         If Not String.IsNullOrWhiteSpace(outputPdf) Then
  25.                                 If arguments.Length > 0 Then arguments.Append(" ")
  26.                                 arguments.Append("-o ")
  27.                                 arguments.Append(outputPdf)
  28.                         End If
  29.                         '                        MessageBox.Show(arguments.ToString(), "调用参数")
  30.                         Task.Run(Sub()
  31.                         Dim psi As New ProcessStartInfo() With {
  32.                         .FileName = exePath,
  33.                         .Arguments = arguments.ToString(),
  34.                         .UseShellExecute = False,
  35.                         .RedirectStandardOutput = False,
  36.                         .RedirectStandardError = False,
  37.                         .CreateNoWindow = True,
  38.                         .WorkingDirectory = IO.Path.GetDirectoryName(exePath)
  39.                         }
  40.                         Dim proc As New Process()
  41.                         proc.StartInfo = psi
  42.                         proc.Start()
  43.                         proc.WaitForExit()

  44.                         ' 进程结束后尝试打开输出 PDF(静默尝试)
  45.                         Try
  46.                                 If Not String.IsNullOrWhiteSpace(outputPdf) AndAlso IO.File.Exists(outputPdf) Then
  47.                                         Try
  48.                                                 Process.Start(outputPdf)
  49.                                         Catch
  50.                                                 ' 忽略打开失败
  51.                                         End Try
  52.                                 End If
  53.                         Catch
  54.                         End Try


  55.                         proc.Dispose()
  56.                 End Sub )
  57.                 End Sub
复制代码


能不能出一个快表中用的呢?
lexianfeng 发表于 2025-12-17 12:47
能不能出一个快表中用的呢?

上面就是快表中所使用的VBA

精彩评论3

可以参考:


  1. Public Sub CallImgToPdfAsync(urls As Object(, ), outputPdf As String)
  2.                         'Dim exePath As String = "C:\Users\Administrator\source\repos\imgTopdf\bin\Debug\ImgToPdf.exe"
  3.                         Dim exePath As String = Directory.GetCurrentDirectory() + "\Dll\topdf\ImgToPdf.exe"
  4.                         ' urls参数是二维数组,每行所有列用逗号分隔
  5.                         Dim arguments As New System.Text.StringBuilder()
  6.                         If urls IsNot Nothing Then
  7.                                 Dim rows As Integer = urls.GetLength(0)
  8.                                 Dim cols As Integer = urls.GetLength(1)
  9.                                 Dim first As Boolean = True
  10.                                 For r As Integer = 0 To rows - 1
  11.                                         Dim arr As New List(Of String)()
  12.                                         For c As Integer = 0 To cols - 1
  13.                                                 Dim val As String = ""
  14.                                                 If urls(r, c) IsNot Nothing Then val = urls(r, c).ToString().Trim()
  15.                                                 arr.Add(val)
  16.                                         Next
  17.                                         If arr(0) <> "" Then
  18.                                                 If Not first Then arguments.Append(" ")
  19.                                                 arguments.Append(String.Join(",", arr))
  20.                                                 first = False
  21.                                         End If
  22.                                 Next
  23.                         End If
  24.                         If Not String.IsNullOrWhiteSpace(outputPdf) Then
  25.                                 If arguments.Length > 0 Then arguments.Append(" ")
  26.                                 arguments.Append("-o ")
  27.                                 arguments.Append(outputPdf)
  28.                         End If
  29.                         '                        MessageBox.Show(arguments.ToString(), "调用参数")
  30.                         Task.Run(Sub()
  31.                         Dim psi As New ProcessStartInfo() With {
  32.                         .FileName = exePath,
  33.                         .Arguments = arguments.ToString(),
  34.                         .UseShellExecute = False,
  35.                         .RedirectStandardOutput = False,
  36.                         .RedirectStandardError = False,
  37.                         .CreateNoWindow = True,
  38.                         .WorkingDirectory = IO.Path.GetDirectoryName(exePath)
  39.                         }
  40.                         Dim proc As New Process()
  41.                         proc.StartInfo = psi
  42.                         proc.Start()
  43.                         proc.WaitForExit()

  44.                         ' 进程结束后尝试打开输出 PDF(静默尝试)
  45.                         Try
  46.                                 If Not String.IsNullOrWhiteSpace(outputPdf) AndAlso IO.File.Exists(outputPdf) Then
  47.                                         Try
  48.                                                 Process.Start(outputPdf)
  49.                                         Catch
  50.                                                 ' 忽略打开失败
  51.                                         End Try
  52.                                 End If
  53.                         Catch
  54.                         End Try


  55.                         proc.Dispose()
  56.                 End Sub )
  57.                 End Sub
复制代码


能不能出一个快表中用的呢?
lexianfeng 发表于 2025-12-17 12:47
能不能出一个快表中用的呢?

上面就是快表中所使用的VBA
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则  允许回帖邮件提醒楼主

快表软件是国内较早研究表格类软件开发平台的团队之一,迄今已有十多年的行业经验.致力于为企事业单位提供实用可靠的数字化平台。
  • 微信公众号

  • 微信小商店

  • 微信客服

  • Powered by Discuz! X3.4 | Copyright © 2022-2024, XiRong Soft. | 快表软件
  • 沪ICP备13033196号 | 营业执照 |上海西戎软件科技有限公司|沪公网安备31011502002146号|沪ICP备13033196号 |