【问题标题】:Cannot get a numeric value from a text cell Mule Dataweave无法从文本单元格中获取数值 Mule Dataweave
【发布时间】:2017-04-03 18:46:25
【问题描述】:

我正在使用文件连接器从an Excel file (xlsx) 读取数据,并使用数据编织将数据转换为应用程序/java。如果 Excel 中有任何类型为 Accounting 的单元格,我会收到此异常:

消息:无法从文本单元格中获取数值 (java.lang.IllegalStateException)。 有效载荷:com.mulesoft.weave.reader.DefaultSeekableStream@6fe3727f

<dw:input-payload mimeType="application/xlsx">  
</dw:input-payload>

这是数据编织:

%dw 1.0 
%output application/java 
--- 

payload."Sheet1" map ((sheet1 , indexOfSheet1) -> { 
   id: sheet1.id 
})

如果单元格格式更改为常规,则异常消失。如何使用会计类型的单元格在 excel 中使用此功能?

【问题讨论】:

标签: mule mule-component dataweave


【解决方案1】:

我最初使用 Studio 版本 6.2.3 和 Mule runtime 3.8.1 EE 在本地 Anypoint 工作室创建了相同的场景,但遇到了几个问题。我将运行时更新为 3.8.3 EE,所有问题都消失了,一切似乎都运行良好。验证您是否有任何版本问题,最近添加到 dataweave 的 Excel 支持仍处于测试阶段。

https://forums.mulesoft.com/questions/42650/ms-excelxls-on-dataweave.html

这是对我有用的流程

                <?xml version="1.0" encoding="UTF-8"?>
    <mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
    http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
        <flow name="xslxreaderFlow">
            <file:inbound-endpoint path="C:\files\input" responseTimeout="10000"  doc:name="File"/>
            <dw:transform-message doc:name="Transform Message" metadata:id="aa47f058-609d-4d96-9646-a52accacaf9f">
                <dw:input-payload doc:sample="sample_data\excel_1.xlsx" mimeType="application/xlsx"/>
                <dw:set-payload><![CDATA[%dw 1.0
    %output application/java
    ---

    payload."Sheet1" map ((sheet1 , indexOfSheet1) -> { 
       id: sheet1.ID, 
       amount:sheet1.Amount
    })]]></dw:set-payload>
            </dw:transform-message>
            <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
        </flow>
    </mule>

从控制台输出结果

INFO  2017-04-04 16:46:57,940 [[test].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\files\input\Book1.xlsx
INFO  2017-04-04 16:47:00,719 [[test].xslxreaderFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: [{id=123456, amount=5000.75}, {id=234567, amount=45367.34}]

这是您文件的日志消息

INFO  2017-04-06 09:37:38,650 [[test].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\files\input\file1.xlsx
INFO  2017-04-06 09:37:38,792 [[test].xslxreaderFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: [{id=1234, amount=500.5}, {id=456, amount=700.25}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}, {id=, amount=}]

【讨论】:

  • 您是否使用了我作为输入源附加的相同 excel?我使用的是 3.8.3 EE 运行时版本。我的流程可以成功读取 excel 文件,但不能读取我附加的文件。这是因为金额字段的数据类型。如果单击格式单元格,您将看到它是会计。如果我将其更改为通用,一切正常。如果 excel 输入源中有任何具有会计格式的字段,我怎样才能使它工作?
  • 我通过从谷歌驱动器下载你的文件运行,似乎工作正常,但它也产生空白单元格。我在答案中添加了日志消息。
  • 当然流程正在读取文件,并且在拾取后会被删除,因为我没有将 autoDelete 设置为 false。文件名模式是可选参数,在我添加到流程后仍然照常运行。有任何问题请告诉我。
  • 您没有看到前两个有效项目“{id=1234, amount=500.5}, {id=456, amount=700.25}”。扩孔数据是空单元格,因为您的文件有问题。
  • 抱歉,我没看到前 2 项
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多