简体   繁体   English

Pentaho Kettle-生成空行的Excel输出

[英]Pentaho Kettle - Generate Excel Output With Empty Rows

I am new to Pentaho kettle. 我是Pentaho水壶的新手。

I need to generate a microsoft excel output using the result set of a Table Input step. 我需要使用表输入步骤的结果集生成一个Microsoft Excel输出。

I am using the following steps in my transformation 我在转换中使用以下步骤

  1. Get system Data - To provide the date range for the table data to retrieve 获取系统数据-提供要检索的表数据的日期范围
  2. Table Input - SQL to retrieve the table data based on the date range given in prior step 表格输入-基于上一步中指定的日期范围检索表格数据的SQL
  3. Excel output - To generate an excel with the resultset of step2. Excel输出-用step2的结果集生成一个excel。

My excel output should have 3 empty rows before the Column header. 我的Excel输出在Column标头之前应该有3空行。 so i have tried using union to generate empty rows and constructed the column header also using the sql. 因此,我尝试使用union生成空行,并且还使用sql构造了列标题。 but kettle wont apply the formatting on fields if i select empty rows in sql(All field values will be considered as String). 但是如果我在sql中选择空行,水壶将不会对字段应用格式设置(所有字段值都将视为字符串)。

Is there anyway to generate empty rows in the excel output before column header, without disturbing my result set. 无论如何,有没有在列标题之前的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;

I See 2 options: 我看到2个选项:

  1. Use the select values step to properly change your columns from strings to integers or whatever. 使用选择值步骤正确地将列从字符串更改为整数或其他。
  2. Use Cast('' as Integer) or similar to make sure that the SQL query returns the columns as the correct data type. 使用Cast(''作为Integer)或类似内容以确保SQL查询返回的列为正确的数据类型。

I would have thought your union query would generate an error if you had different data types at different parts of the union anyway!? 我本以为如果在联合的不同部分使用不同的数据类型,联合查询将产生错误! So perhaps something else is going on here? 那么,也许这里还有其他事情吗?

您也可以使用MS Excel Writer步骤,并在内容选项卡上的“通过写入...空行开始”框中输入3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM