Dataweave不识别Excel文件中的标题

问题描述 投票:1回答:1

我正在使用Mule 4和Anypoint Studio 7。

我想从Excel电子表格中提取数据,但是我希望从工作表第4行的起始处提取数据,并且Transform消息的输出为null,我认为这是因为它没有检测到列名,因为它们位于第4行而不是第1行。

我怎样才能解决这个问题?

Dataweave XML

        <ee:transform doc:name="Transform Message" doc:id="1bdda7fe-2abe-48d3-8bc5-42a94c12b6b9" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
input payload application/xlsx header=true
output application/json
---
{
    "Customers": payload."CUSTOMERS" filter $$ > 2 map ( cUSTOMER , indexOfCUSTOMER ) -> {
        "Type": cUSTOMER.type,
        "Category": cUSTOMER.category
    }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>

数据编码:

%dw 2.0
input payload application/xlsx header=true
output application/json
---
{
    "Customers": payload."CUSTOMERS" filter $$ > 2 map ( cUSTOMER , indexOfCUSTOMER ) -> {
        "Type": cUSTOMER.type,
        "Category": cUSTOMER.category
    }
}

高强

enter image description here

谢谢你的帮助

mule anypoint-studio dataweave
1个回答
1
投票

您可以将属性tableOffset设置为xlsx格式的数据开始列。

对于Mule 3:在GUI中:

  1. 右键单击“Payload”标签(左侧面板)。
  2. 单击“Reader Configuration”选项。
  3. GUI打开,可以设置多个选项。
  4. 将“tableOffset”配置为表的起始单元格。在你的例子中A4。

代码示例:

<dw:transform-message doc:name="Transform Message" metadata:id="9abf7128-71b8-4610-8fca-7ceda17f852e">
            <dw:input-payload mimeType="application/xlsx">
                <dw:reader-property name="tableOffset" value="A4"/>
            </dw:input-payload>
            <dw:set-payload><![CDATA[%dw 1.0 
%output application/json
---
payload]]></dw:set-payload>
        </dw:transform-message>

对于Mule 4,您需要在事件源上设置reader属性:

https://docs.mulesoft.com/mule-runtime/4.1/dataweave-formats#reader_writer_properties

例如,如果您正在从文件中读取xlsx:

<file:listener doc:name="On New File" config-ref="File_Config" outputMimeType='application/xlsx tableOffset="A4"'>
  <scheduling-strategy >
    <fixed-frequency frequency="45" timeUnit="SECONDS"/>
  </scheduling-strategy>
  <file:matcher filenamePattern="myfile.xlsx" />
</file:listener>

在转换之前,您还可以尝试使用简单的转换来添加新的阅读器属性:

<set-payload value="#[output application/xlsx tableOffset='A4' --- payload]" />
        <!-- Then your normal transformer -->
        <ee:transform xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd"
            doc:id="bed303c7-1549-45da-af58-10c4ad937926">

            <ee:message>

                <ee:set-payload><![CDATA[%dw 2.0
output application/json --- payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
© www.soinside.com 2019 - 2024. All rights reserved.