Excel的互操作为什么会处理文件后删除图像? [英] Why would the Excel Interop remove an image after processing a file?

查看:174
本文介绍了Excel的互操作为什么会处理文件后删除图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel的互操作是从处理的文件删除的图像。

Excel Interop is removing images from processed files.

我在使用Excel互操作,没有任何第三方的组件都存在(即我所知道的) 。
中的工作流程是 - 创建一个文件(模板)的副本(目标),填充细胞,改变单选按钮状态

I’m using the Excel Interop, no third-party components are present (that I'm aware of). The workflow is -- create a copy (target) of a file (template), populate cells, change radio-button state


  1. 通过Excel的互操作创建一个预先存在的.xslm文件(模板)的复印件(目标)

  2. 开启目标

  3. 填充靶细胞,变化单选按钮状态

  4. 与图像的工作不被修改

  5. 关闭目标

  1. Create copy (target) of a pre-existing .xslm file (template)
  2. Open target via Excel Interop
  3. Populate target cells, change radio-button state
  4. The worksheet with an image is not modified
  5. Close target

在我的dev的机器,目标文件看起来不错 - 一切都填充,图像存在。 NB:我开发的机器上,我正在从VS2010 IDE中的代码

On my dev machine, the target file looks great -- everything is populated, the image is present. NB: on my dev machine, I'm running the code from the VS2010 IDE.

在生产机 - 一切都被填充,但图像不存在。
而是出现在它的地方出现以下错误:
注:上机生产,它作为服务运行,用的本地服务的帐户

On the production machine -- everything is populated, but the image is not present. Instead, the following error appears in its place: NB: on the production machine, it's running as a service, with the Local Service account.


有关系ID RID1图像部分未在文件中找到

"The image part with relationship ID rId1 was not found in the file"

整个工作簿是通过下面的代码打开:

The entire workbook is opened via the following code:

var workbook = workbooks.Open(targetPath
     0, false, 5, Type.Missing, Type.Missing, false, XlPlatform.xlWindows, "",
     true, false, 0, true, false, false);

请注意,与图像的工作表中的代码不被操作。

Please note that the worksheet with the image is not manipulated in the code.

worksbooks(和个别工作表)的保护。然而,受保护模板在dev的正确处理,而不是在生产。我不认为保护有什么关系呢(但谁知道,对不对?这是互操作。啊)。

The worksbooks (and individual worksheets) are protected. However, the protected template is processed correctly in dev, but not in production. I don't think the protection has anything to do with it (but who knows, right? This is Interop. ugh).

该文件是由其他党创造的,和所有组件(即图像)驻留在.xslm结构中,而不是链接到另一台服务器。

The file was created by another party, and all components (ie, the image) reside within the .xslm structure, not as links to another server.

我已经验证该图像是在生产机器上可见在模板文件中,而不是在一个处理的文件。

I have verified that the image is visible on the production machine in the template file, but not in a processed file.

要确认这不是在生产中打开该文件的一个问题,我通过电子邮件发送自己的副本,图像仍然是不存在的。

To confirm that this was not an issue in opening the file within the production, I emailed myself a copy, and the image continued to be not present.

我也证实了我的开发机上,处理的文件确实有一个可见的图像。

I have also confirmed that, on my development machine, processed files do have a visible image.

我未受保护的工作表,并解压缩文件结构。该.jpg文件确实不存在从生产机器处理后的目标

I unprotected the worksheet, and unzipped the file structure. The .jpg file is indeed not present in the processed target from the production machine.

还要说明一点 - Office 2010的安装我的机器上,但Office 2007的上生产机。其结果是,我使用的是Office 12的互操作。在任何环境下都不会产生运行时错误。

One more note -- Office 2010 is installed on my development machine, but Office 2007 on the production machine. As a result, I'm using the Office 12 Interop. No runtime errors are generated in either environment.

我使用的互操作(而不是一个OPENXML库),因为有ActiveX控件存在,必须填充。但是请注意,没有一个ActiveX控件有任何问题 - 他们工作的罚款。它是从处理的文件消失(他们提供的模板文件罚款)只是图像文件

更新注:另外还有4种图像文件,所有的 .EMF 在不同的工作表;他们全部脱光,以及

UPDATE NOTE: There are four other image-files, all .emf on a different worksheet; they are all stripped as well.

推荐答案

作为评论(最终在编辑的问题)解释的那样,代码为。在生产环境中运行作为一种服务,以本地服务帐户

As explained in comments (and eventually in an edit to the question), the code was running in production as a service, with the Local Service account.

我现在不清楚我为什么选择这个账户 - 这是我发现我对得到的Interop作为服务正常运行的研究过程中传递?

I am now unsure why I picked this account -- something I found in passing during my research on getting the Interop to run correctly as a service?

但是,一旦我从本地服务帐户切换到本地系统帐户(并检查允许服务与桌面交互),它的工作。自动的。

However, once I switched from the Local Service account to the Local System account (and checked "Allow service to interact with desktop") it worked. Automagically.


  1. SERVICES.MSC

  2. 选择服务

  3. 右键单击,选择属性

  4. 选择登录标签

  5. 选择本地系统帐户并勾选允许服务与桌面交互

  1. services.msc
  2. select the service
  3. right-click, select "Properties"
  4. select the "Log On" tab
  5. select "Local System account" and check "Allow service to interact with desktop"

允许服务与桌面交互可能不要求;在自动化互操作其他说明表明,需要其它的桌面设置,但是我做了一个安装在那里的先决条件,分别设置,但这个值选中;应用程序仍然工作......

"Allow service to interact with desktop" might not be required; Other notes on automating the Interop suggest that other desktop settings are required, however I did an install where those pre-requisites were set but THIS value unchecked; app still worked...

这篇关于Excel的互操作为什么会处理文件后删除图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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