You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用TDL导出Tally Ledger Outstanding报表生成空白PDF问题

TDL脚本导出Ledger Outstanding报表生成空白PDF问题

我使用以下Tally定义语言(TDL)脚本导出Ledger Outstanding报表,脚本运行成功,但生成的PDF文件为空白,未包含报表数据。

[Function: ExportLedgerGroup] 
Variable : LedgerName22       : String 
Variable : ContactNumber      : String 
Variable : PrintFileName      : String 
Variable : ExportedFilePath   : String

;; Confirm action
01 : Query Box : "Do you want to export reports?" : Yes : No
02 : If : $$LastResult

    ;; Ensure export directory exists
    03 : If : NOT $$IsDirectory:"LedgerOutstandingReports"
        04 : Make Dir : "LedgerOutstandingReports"
    05 : End If

    ;; Walk through the filtered collection of visible rows
    06 : Walk Collection : LWcollevc
        
        08 : SET : ContactNumber : $LedgerMobile:Ledger:$Name

        10 : Msg Box : "Contact Missing" : "No contact number for ledger: " + ##LedgerName22
        
        ;; Generate file name for export
        15 : SET : PrintFileName : "LedgerOutstandingReports" + "\" + ##LedgerName22 + "_" + $$String:##SVToDate + ".pdf"
        16 : SET : SVExportFormat : $$SysName:PDF
        17 : SET : SVPrintFileName : $$MakeExportName:##PrintFileName:##SVExportFormat
        18 : SET : SVOpenFileAfterExport : No

        ;; Export report for the ledger
        19 : EXPORT REPORT : Ledger Outstandings : No : No

        ;; Get the exported file path
        20 : SET : ExportedFilePath : $$GetFileFullPath:##SVPrintFileName

    27 : End Walk

    ;; Completion message
    28 : Msg Box : "Process Complete" : "All visible rows have been processed and sent."
29 : End If
30 : Return

[Collection: LWcollevc] 
Data Source : Report : All 
Fetch       : Name, LedgerMobile, ClosingBalance 
Filter      : IsNameNotEmpty

[System: Formula] 
IsNameNotEmpty : NOT $$IsEmpty:$Name

预期行为

  • 脚本应为集合LWcollevc中每个可见科目生成PDF文件,保存到LedgerOutstandingReports目录,文件名符合规范。

观察到的行为

  • 脚本执行后成功创建文件,但PDF内容空白,无Ledger Outstanding报表数据。

已尝试操作

  • 用Msg Box验证集合LWcollevc已获取正确科目
  • 检查生成的文件路径,确认指向正确位置
  • 手动查看“Ledger Outstanding”报表,确认所选科目有数据

疑问

  1. EXPORT REPORT函数的使用是否存在问题?
  2. 是否需要为EXPORT REPORT配置额外参数确保文件包含数据?
  3. 集合LWcollevc的数据源或过滤器是否可能导致该问题?

排查方向与解决指导

1. 核心问题:未指定报表筛选条件

当前EXPORT REPORT仅导出默认的Ledger Outstandings报表,未关联遍历的当前科目,导致报表无对应数据,生成空白PDF。需在导出前设置报表筛选参数,指定当前遍历的ledger:

;; 在循环内添加,指定当前科目为报表筛选范围
SET : SVFromLedger : $Name
SET : SVToLedger : $Name
LOAD REPORT : Ledger Outstandings

2. 修复变量赋值缺失

代码中LedgerName22变量未赋值,导致第10行弹窗显示空值。需在循环内添加赋值语句:

;; 放在ContactNumber赋值前
SET : LedgerName22 : $Name

3. 修正集合数据源合理性

当前集合LWcollevc的Data Source : Report : All指向不明确,建议直接从ledger主数据获取,避免报表集合的不确定性:

[Collection: LWcollevc] 
Data Source : Ledger
Fetch       : Name, LedgerMobile, ClosingBalance 
Filter      : IsNameNotEmpty

4. 优化弹窗逻辑

原代码每次循环都会弹出“Contact Missing”提示,需添加判断仅当联系号码为空时触发:

09 : If : $$IsEmpty:##ContactNumber
    10 : Msg Box : "Contact Missing" : "No contact number for ledger: " + ##LedgerName22
11 : End If

完整修正后的核心循环示例

06 : Walk Collection : LWcollevc
    07 : SET : LedgerName22 : $Name
    08 : SET : ContactNumber : $LedgerMobile:Ledger:$Name

    09 : If : $$IsEmpty:##ContactNumber
        10 : Msg Box : "Contact Missing" : "No contact number for ledger: " + ##LedgerName22
    11 : End If
    
    12 : SET : SVFromLedger : $Name
    13 : SET : SVToLedger : $Name
    14 : LOAD REPORT : Ledger Outstandings

    15 : SET : PrintFileName : "LedgerOutstandingReports" + "\" + ##LedgerName22 + "_" + $$String:##SVToDate + ".pdf"
    16 : SET : SVExportFormat : $$SysName:PDF
    17 : SET : SVPrintFileName : $$MakeExportName:##PrintFileName:##SVExportFormat
    18 : SET : SVOpenFileAfterExport : No

    19 : EXPORT REPORT : Ledger Outstandings : No : No

    20 : SET : ExportedFilePath : $$GetFileFullPath:##SVPrintFileName

27 : End Walk

额外注意事项

  • 确保SVToDate变量已正确赋值,避免文件名日期异常
  • 检查Tally权限,确保脚本有导出报表和写入文件的权限
  • 测试时先遍历单个科目验证,确认PDF有数据后再批量处理

内容的提问来源于stack exchange,提问作者Sandy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 11:58:19