Pentaho Kettle - 用空行生成Excel输出

时间:2012-12-12 09:10:33

标签: mysql excel export-to-excel pentaho kettle

我是Pentaho水壶的新手。

我需要使用表输入步骤的结果集生成microsoft excel输出。

我在转型中使用以下步骤

  1. 获取系统数据 - 提供要检索的表数据的日期范围
  2. 表输入 - 用于根据前一步骤中给出的日期范围检索表数据的SQL
  3. Excel输出 - 使用步骤2的结果集生成excel。
  4. 我的excel输出在Column标题之前应该有3个空行。所以我尝试使用union生成空行,并使用sql构造列标题。但是如果我在sql中选择空行,水壶就不会在字段上应用格式化(所有字段值都将被视为字符串)。

    无论如何都要在列标题之前的excel输出中生成空行,而不会干扰我的结果集。

    SELECT 
        '' AS 'Accounting Month',   '' AS 'Insured Name','' AS 'Policy Number','' AS 'Company Name','' AS 'Line Of Business','' AS 'Transaction Type',  '' AS 'Effective Date','' AS 'Rate','' AS 'Gross Premium','' AS 'Commission Amount',    '' AS 'Expense Constant',   '' AS 'Net Amount','' AS 'Payment Amount', 1 as ORDERS
    UNION ALL
    
    SELECT 
        '' AS 'Accounting Month',   '' AS 'Insured Name','' AS 'Policy Number','' AS 'Company Name','' AS 'Line Of Business','' AS 'Transaction Type',  '' AS 'Effective Date','' AS 'Rate','' AS 'Gross Premium','' AS 'Commission Amount',    '' AS 'Expense Constant',   '' AS 'Net Amount','' AS 'Payment Amount', 1 as ORDERS
    UNION ALL
    
    SELECT 
        '' AS 'Accounting Month',   '' AS 'Insured Name','' AS 'Policy Number','' AS 'Company Name','' AS 'Line Of Business','' AS 'Transaction Type',  '' AS 'Effective Date','' AS 'Rate','' AS 'Gross Premium','' AS 'Commission Amount',    '' AS 'Expense Constant',   '' AS 'Net Amount','' AS 'Payment Amount', 1 as ORDERS
    UNION ALL
    
    
    SELECT 
        '' AS 'Accounting Month',   '' AS 'Insured Name','' AS 'Policy Number','' AS 'Company Name','' AS 'Line Of Business','' AS 'Transaction Type',  '' AS 'Effective Date','' AS 'Rate','' AS 'Gross Premium','' AS 'Commission Amount',    '' AS 'Expense Constant',   '' AS 'Net Amount','' AS 'Payment Amount', 3 as ORDERS
    UNION ALL
    
    SELECT 
     'Accounting Month',
     'Insured Name',
     'Policy Number',
     'Company Name',
     'Line Of Business',
     'Transaction Type',
     'Effective Date',
     'Rate',
    'Gross Premium',
    'Commission Amount',
    'Expense Constant',
    'Net Amount',
    'Payment Amount', 
    2 ORDERS
    
    UNION ALL
    
    SELECT * FROM (
    SELECT 
            CONCAT(ACCOUNT_YEAR,ACCOUNT_MONTH) AS 'Accounting Month',
            INSURED_NAME AS 'Insured Name',
            POLICY_NUMBER AS 'Policy Number',
            COMPANY AS 'Company Name',
            LINE_OF_BUSINESS AS 'Line Of Business',
            TRANSACTION_DETAIL_TYPE 'Transaction Type',
            DATE_FORMAT(CHANGE_EFFECTIVE_DATE,'%m/%d/%Y') AS 'Effective Date',
            OWNER_COMMISSION_RATE AS 'Rate',
            GROSS_PREMIUM AS 'Gross Premium',
            OWNER_COMMISSION_AMOUNT AS 'Commission Amount',
            EXPENSE_CONSTANT AS 'Expense Constant',
            NET_AMOUNT AS 'Net Amount',
            NET_AMOUNT AS 'Payment Amount' ,
            4 ORDERS
            FROM TABLE1
            WHERE           
            DATE(TRANSACTION_ENTRY_DATE) >=?
            AND 
            DATE(TRANSACTION_ENTRY_DATE) <=?
            ORDER BY TABLE1.POLICY_NUMBER,TABLE1.FLAG,TABLE1.ENDORSEMENT_NUMBER
    )T
    ORDER BY ORDERS;
    

2 个答案:

答案 0 :(得分:0)

我看到2个选项:

  1. 使用选择值步骤将列从字符串正确地更改为整数或其他任何内容。
  2. 使用Cast('作为整数)或类似方法确保SQL查询将列作为正确的数据类型返回。
  3. 如果你在联盟的不同部分有不同的数据类型,我会认为你的联合查询会产生错误!?那么也许其他事情正在发生?

答案 1 :(得分:0)

您还可以使用MS Excel Writer步骤,并在内容选项卡上为“以书写方式编写...空行”框输入3。