问题标签 [excel-automation]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
943 浏览

.net - Feedback for Excel Automation and execution of long running macro

I have the most god-awful task of automating an excel workbook in C#. Part of the process is to call a macro in the workbook which takes around 2 minutes to execute. This all happens in a Windows service and happily runs from start to finish. At present it writes events to a database table just before calling the macro and when the macro has finished executing. It does a lot of calculations and exporting data to a text file within the macro code.

As it takes so long the users have asked if they can be notified at various parts of the process.

My initial thought with reservation was to periodically poll the Application.StatusBar which gets update whilst running the macro using System.Timers.Timer. I thought there might be some kind of thread issues with this - which I think is happening as the call from the timer to get the StatusBar does not return/complete for quite a large period of time (tens of seconds).

I have my workbook wrapped up in the following class which makes sure Excel closes correctly and runs the macro:

Then I have tried to do the monitoring using the following nested/internal class in my report processing class:

This is all triggered by executing the following code in the ReportGeneratorProcess class (I've omitted the unnecessary code)

AddEvent simply adds a new event to the database using the main class.

I remain defeated at the moment trying to think of an alternative solution/nice way around this. Anyone got any hints?

Unfortunately the process HAS to operate as is. There is no scope to move anything out of excel.

0 投票
1 回答
747 浏览

c# - 获取类型下拉列表的形状

这是一些我想改进的可怕代码:

有没有办法更容易获得下拉列表?尝试获取FormControlType时如何避免上述异常?

0 投票
1 回答
196 浏览

excel - 如何使用applescript仅选择列中的非空单元格

我想使用 applescript 在列中仅选择非空单元格。

A B C D

1

2

3

4

在上述场景中,我想知道 A 列的非空单元格的范围是 1、2、3、4。

提前致谢

0 投票
1 回答
2268 浏览

c# - C#和excel自动化,如何使用CopyFromRecordset函数

我正在尝试使用来自 SQL 服务器的一些数据填充一个 excel 文件,

我的代码如下,

我收到以下错误

{“不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE))”}

我需要将阅读器转换为数组吗?

0 投票
1 回答
479 浏览

wcf - 使用 Excel 在 WCF mex Moniker 上调用方法时出现自动化错误

我成功地为我的 WCF 服务创建了一个服务名字对象作为客户端。但我无法在绰号上调用任何方法。

在 WCF 服务端,我有一个名为 TestMethod 的虚拟方法,如下所示:

以下代码在 Excel 中创建 Moniker。

上面的代码在GetObject调用之前有效,这意味着名字对象已成功创建。但是,一旦我尝试调用任何方法,我就会收到错误消息。

自动化错误

WCF 方法与 Microsoft WCF 测试客户端和其他 WCF 客户端完美配合。所以我知道服务本身没有问题。

0 投票
0 回答
69 浏览

visual-foxpro - 更改excel页脚中的字体

我录制宏 "&""Arial,Bold""&10Page" 在 foxpro excel 自动化中不起作用。

pagesetup.leftFooter 应该是什么?

0 投票
1 回答
1246 浏览

c# - 如何将新创建的 Excel 工作簿作为活动工作簿打开

我在 Excel 中开发了一个插件。此插件有一个包含按钮的功能区。单击此按钮时,我会根据用户凭据从数据库中检索的 xml 字符串创建一个新的工作簿和工作表。我能够与工作表一起创建工作簿,但是,此工作簿不会显示为用户的主要工作簿。

我想要实现的是:当在 excel 工作簿上单击插件时,生成的工作簿将成为活动的工作簿,并且旧的 excel 工作簿可视化,以便用户的注意力现在集中在创建的工作表上。他不得不搜索创建的工作簿。

这是我使用过的代码,但它似乎不起作用:Ps:我正在使用 Excel 2013 和 VS 2013 以及 C#

0 投票
1 回答
1651 浏览

vsto - Insert SQL query result into Excel worksheet using VSTO

I'm trying to write Excel application-level add-in. It makes SQL query to the database and populates worksheet with its results. I thought, it should be simple... But not. Is there any way to insert DataTable into excel worksheet? Something like this:

Maybe, I should use another approach (not DataTable)? However, my query can return up to 100000 rows of data with 4 columns. So, cell-by-cell pasting will not work, I think.

0 投票
0 回答
564 浏览

c# - ASP.NET 网站与 ms excel 集成

我正在研究 asp.net 网站和 excel 集成项目。我有一个 excel 文件,其中包含许多执行一些计算的宏。我可以简单地传递单元格的值,并根据宏公式在 Excel 的其他单元格中显示输出。我需要从 ASP.NET 网站传递这些参数,并在 asp.net webform 上显示 excel 的输出。我可以使用以下代码实现此功能,并且在开发时可以正常工作。

当我将站点部署到生产服务器时,我收到以下错误 -

由于以下错误,检索具有 CLSID {00024500-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80070005 访问被拒绝。(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))。

为了解决这个问题,我应用了以下解决方案,但它不起作用 - 在大多数链接中提到发布 32 位或 64 位应用程序,但我将其开发为 asp.net 网站,因此没有 32 位选项和64 位。在 IIS 上,我已经将“启用 32 位应用程序”设置为 true。

0 投票
0 回答
114 浏览

c# - 从 C# 中断运行 Excel VBA

我读过的所有内容都表明这是不可能的,但也许有人知道我不知道的事情。

我用 C# 开发了中间件,用于通过 COM 或 .NET 接口运行不同的程序。其他程序允许您异步运行它们,并在必要时中断计算。

程序选项之一是 Excel,中间件将启动 Excel 并运行用户命名的 VBA 代码。我想像其他程序一样中断从 C# 运行 Excel VBA。似乎没有任何方法可以做到这一点,因为 Run(macro) 调用被阻塞并在 VBA 代码完成时返回。

有 _Run2(macro) 和 _Wait() 调用,这表明可能有一些方法可以做到这一点,但这些是供内部使用的,因此它们故意记录得很差。