0

我在这里确实有一个奇怪的问题,正在寻找有优雅解决方案的人。我使用类似的东西

 With destCell.Parent.QueryTables.Add(Connection:="TEXT;" & exportUrl, Destination:=destCell)
        'all these have sane defaults, yes, but if the user used text to columns with something, this changes magically. So stupid
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileDecimalSeparator = "."
        .TextFileThousandsSeparator = False
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileCommaDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileConsecutiveDelimiter = False
        ' there is no way to set this to nothing, apparently.
        .TextFileOtherDelimiter = ","
        .TextFilePlatform = 65001 'UTF-8
        .Refresh BackgroundQuery:=False
    End With

从 php Web 应用程序中获取数据。我在 URL 中有访问键作为查询参数。如果他们是正确的,一切都会好的。如果错误,php 会返回一个 http 403 页面。这使得 Excel 引发错误 1004,我发现它很好。现在,对代码的任何后续调用,以及更改(现在正确)的访问密钥仍然会引发 1004。根据服务器日志,Excel 甚至不再启动 http 请求。看起来它正在缓存 http 响应代码。

由于用户必须输入密钥,因此很容易发生错误。我想提供输入正确的,但比上面会让它们看起来仍然是错误的......

欢迎提出想法!如果有影响,请运行 Excel 2016。

4

1 回答 1

0

“解决方案”实际上是一种解决方法。我不再发送 http 403,而是处理有效负载中的错误。这仅留下连接问题。因为它们应该很少见,所以我现在只要求用户在发生这种情况时重新启动 excel。

于 2018-03-24T22:44:36.647 回答