在 Mulesoft 中读取 xlsx 文件时忽略空行参数不起作用
ignoreEmptyLine parameter not working while reading xslx file in Mulesoft
我正在尝试使用“在新文件或更新文件上”节点在 Mulesoft 中将 .xslx 文件转换为 CSV
输入 Mime 类型设置为 application/xlsx 并添加了一个设置为 True 的参数“ignoreEmptyLine”。
但在我的输出 CSV 文件中,我仍然得到空记录。
我必须在输入节点设置另一个参数吗?
<flow name="excel2csvFlow" doc:id="0539d502-fef3-40c4-8aff-f35ce56304e8" >
<file:listener doc:name="On New or Updated File" doc:id="2383c725-9ce0-460f-a10e-8a2707174650" config-ref="File_Config" directory="C:\Users\Darshan Vaswani\Desktop\Test\input" recursive="false" outputMimeType="application/xlsx; ignoreemptyline=true" moveToDirectory="C:\Users\Darshan Vaswani\Desktop\Test\archive">
<scheduling-strategy >
<fixed-frequency />
</scheduling-strategy>
<file:matcher />
</file:listener>
<ee:transform doc:name="Transform Message" doc:id="9cd75403-0552-412e-a22e-8d7d1215d1d0" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/csv ignoreEmptyLine=true
---
payload."Daily report international"]]>
</ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="decd4579-03a3-48ca-bb5a-895885b679a2" message="#[payload]"/>
<file:write doc:name="Write" doc:id="55ecc67b-fd53-45af-98f5-4a08e663e208" config-ref="File_Config" path="C:\Users\Darshan Vaswani\Desktop\Test\output\test.csv"/>
</flow>
输出:
ignoreEmptyLine 的作用是从 excel 文档中删除完全为空的行。如果一行中的任何单元格有空格,则它们不会被删除。您可以做的是在写入 CSV 之前在转换步骤中过滤掉它们。如果您的 excel 文档太大,这可能会导致一些性能问题,但我认为如果是这种情况,您可以利用 Mule 4 的流式传输功能。对于过滤逻辑,您可以遵循以下内容:
%dw 2.0
output application/csv
import someEntry from dw::core::Objects
import isWhitespace from dw::core::Strings
---
payload."Daily report international" filter (
$ someEntry (value, key) -> !(isWhitespace(value))
)
请注意,我使用了 someEntry (https://docs.mulesoft.com/mule-runtime/4.3/dw-objects-functions-someentry) so it will already return true for the first occurrence of any non-whitespace value and does not need to check other entries in the row. isWhitespace (https://docs.mulesoft.com/mule-runtime/4.3/dw-strings-functions-iswhitespace) 来检查该值是否包含除空格之外的其他字符。
我正在尝试使用“在新文件或更新文件上”节点在 Mulesoft 中将 .xslx 文件转换为 CSV
输入 Mime 类型设置为 application/xlsx 并添加了一个设置为 True 的参数“ignoreEmptyLine”。
但在我的输出 CSV 文件中,我仍然得到空记录。
我必须在输入节点设置另一个参数吗?
<flow name="excel2csvFlow" doc:id="0539d502-fef3-40c4-8aff-f35ce56304e8" >
<file:listener doc:name="On New or Updated File" doc:id="2383c725-9ce0-460f-a10e-8a2707174650" config-ref="File_Config" directory="C:\Users\Darshan Vaswani\Desktop\Test\input" recursive="false" outputMimeType="application/xlsx; ignoreemptyline=true" moveToDirectory="C:\Users\Darshan Vaswani\Desktop\Test\archive">
<scheduling-strategy >
<fixed-frequency />
</scheduling-strategy>
<file:matcher />
</file:listener>
<ee:transform doc:name="Transform Message" doc:id="9cd75403-0552-412e-a22e-8d7d1215d1d0" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/csv ignoreEmptyLine=true
---
payload."Daily report international"]]>
</ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="decd4579-03a3-48ca-bb5a-895885b679a2" message="#[payload]"/>
<file:write doc:name="Write" doc:id="55ecc67b-fd53-45af-98f5-4a08e663e208" config-ref="File_Config" path="C:\Users\Darshan Vaswani\Desktop\Test\output\test.csv"/>
</flow>
输出:
ignoreEmptyLine 的作用是从 excel 文档中删除完全为空的行。如果一行中的任何单元格有空格,则它们不会被删除。您可以做的是在写入 CSV 之前在转换步骤中过滤掉它们。如果您的 excel 文档太大,这可能会导致一些性能问题,但我认为如果是这种情况,您可以利用 Mule 4 的流式传输功能。对于过滤逻辑,您可以遵循以下内容:
%dw 2.0
output application/csv
import someEntry from dw::core::Objects
import isWhitespace from dw::core::Strings
---
payload."Daily report international" filter (
$ someEntry (value, key) -> !(isWhitespace(value))
)
请注意,我使用了 someEntry (https://docs.mulesoft.com/mule-runtime/4.3/dw-objects-functions-someentry) so it will already return true for the first occurrence of any non-whitespace value and does not need to check other entries in the row. isWhitespace (https://docs.mulesoft.com/mule-runtime/4.3/dw-strings-functions-iswhitespace) 来检查该值是否包含除空格之外的其他字符。