如何用VBA宏打开CSV文件 [英] How to open CSV file with VBA macro

查看:812
本文介绍了如何用VBA宏打开CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有VBA中的CSV文件和宏。我想在Excel中打开CSV文件,并自动启动一个宏,创建一个图表。可能吗?如何做到这一点(使用语言:Java)?

I have CSV file and Macro in VBA. I want to open CSV file in Excel and automatically launch a macro which creates a chart. Is it possible? How to do this (Using language: Java)?

推荐答案

首先,您可以使用Excel Automation(这是一组COM对象,实际上使用Excel的内部引擎来编程)。这通常使用Microsoft语言(Visual Basic或C#)完成,虽然可能有一些方法通过某种适配器与Java(我会避开这种方法自己,因为Excel自动化是有问题的,足够当使用作为预期,更不用说尝试从Java做它)。请尝试开始此处

First, you could use "Excel Automation" (which is a set of COM objects that actually uses Excel's internal engine to do things programatically). This is typically done using Microsoft languages (Visual Basic or C#), though there may be ways to do this with Java through some kind of adapter (I'd shy away from this method myself, as Excel automation is problematic enough when used as intended, let alone trying to do it from Java). Try research starting here.

或者,您可以使用一些外部Java库(例如 Java Excel API )从.csv源数据手动创建文件。包括产生图表的宏在这里可能更困难;我的快速研究没有打开任何支持该级别的交互(例如创建和运行宏来生成图表)。

Alternately, or you could use some external Java library (such as the Java Excel API) to create the file manually from the .csv source data. Including a macro that produces charts may be more difficult here; my quick research doesn't turn up any that support that level of interaction (e.g. creating and running macros to produce charts).

一般来说,这是一个非平凡的任务,你将需要做自己的研究。首先对Java Excel,Java Excel Automation,Java Excel图表,Java Excel宏以及任何相关组合执行Web搜索。

Generally speaking, this is a non-trivial task that you're going to need to do your own research on. Start by doing a web search for "Java Excel", "Java Excel Automation", "Java Excel Chart", "Java Excel Macro", and any related combination.

您还可以考虑是否有其他解决方案来解决基本问题。例如,您是否可以以某种其他方式导入.csv数据(例如,使用Python脚本或关系数据库导入到内存中),然后使用 Google Chart API 来生成您的图表?如果这些要求本身并不那么复杂,你可以在这里找到更多的成功,避免Excel。

You may also want to consider whether there are other solutions to the underlying problem. For example, can you import the .csv data in some other way (for example, into memory with a Python script or into a relational database), and then use the Google Chart API to produce your charts? If the requirements aren't that complex in themselves, you may find more success avoiding Excel here.

这篇关于如何用VBA宏打开CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆