是否可以在 CSV 文件和工作表之间创建 VBA QueryTable 外连接?
我正在创建一个 Excel 工作簿来管理我的个人财务。我的银行提供 CSV 格式的交易数据,我找到了一种使用 QueryTable(使用“TEXT”连接)将该数据导入 Excel 的方法。
我想自动将交易类别规则应用于每个导入的交易。我有一个包含两列的工作表 - 一个与我的银行 CSV 文件中提供的交易“详细信息”相匹配的字符串,以及适用于匹配交易的类别。
是否可以在 CSV 数据和类别工作表之间创建外连接并将结果表转储到另一个工作表中?
例如(SQL 伪代码): SELECT csv.date, csv.details, csv.debit, csv.credit, ws.category FROM [csvfile] csv LEFT OUTER JOIN [worksheet] ws ON csv.details ~= ws.details
~=上面是某种字符串匹配。我可以弄清楚 SQL,我的问题实际上是如何将 CSV 文件和工作表合并到同一个查询表中。
I'm creating an excel workbook to manage my personal finances. My banks provide transaction data in CSV format and I found a way to import that data into excel using a QueryTable (using a "TEXT" connection.)
I'd like to automatically apply transaction category rules to each imported transaction. I have a worksheet with two columns - a string to match against the transaction "details" provided in my bank's CSV file and the category to apply to the matching transactions.
Is it possible to create an outer join between the CSV data and the categories worksheet and dump the resulting table into another worksheet?
For example (SQL pseudocodeish): SELECT csv.date, csv.details, csv.debit, csv.credit, ws.category FROM [csvfile] csv LEFT OUTER JOIN [worksheet] ws ON csv.details ~= ws.details
~= above would be some kind of string match. I can figure out the SQL, my question is really how to combine the CSV file and worksheet in the same QueryTable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Excel 将不闪烁地打开 CSV 文件,但如果您愿意,可以使用连接字符串。甚至可以编写一个查询,将现有工作表或命名范围与使用 Excel 连接的文本文件进行比较。您所需要的只是一点 VBA。
您可以对连接使用任何合适的 Jet SQL 查询,但要注意区分大小写。例如,使用与当前工作簿的连接:
Excel will open CSV files without blinking, but you can use a connection string, if you prefer. It is even possible to write a query that compares an existing worksheet or named range with a text file using an Excel connection. All you need is a little VBA.
You can use any suitable Jet SQL queries against the connection, just be careful about case sensitivity. For example, working with a connection to the current workbook:
可以在 ADO 查询中使用 ISAM 名称创建引用不同数据源(csv、Excel、Access、txt、SQL、Oracle 等)的 OUTER JOIN。结果保存在记录集中,可以根据需要发布回 Excel 或其他数据源。通过 Google“SQL ISAM 名称”查找我关于该主题的其他帖子。
It is possible to create an OUTER JOIN referencing disparate data sources (csv, Excel, Access, txt, SQL, Oracle, etc) using ISAM Names in an ADO query. The results are held in a recordset that can be published back to Excel or another datasource as desired. Google "SQL ISAM Names" to find my other posts on the topic.
我相信更多的信息将有助于消除我的困惑,但我不认为可以针对 CSV 设置 SQL 查询,因为 Excel 不会将其识别为数据源。
您是否考虑过简单地将 csv 加载到 Excel 中并生成数据透视表/查找?
I am sure a little more info would help clear up my confusion but I don't believe it is possible to set up a SQL query against a CSV as Excel will not recognise it as a Data Source.
Have you thought about simply loading the csv into Excel and generating a pivot table/lookups on the data?