【问题标题】:Excel Interop ( insert image) in Windows Server 2012 R2Windows Server 2012 R2 中的 Excel 互操作(插入图像)
【发布时间】:2014-09-28 07:36:46
【问题描述】:

我们正在将我们的 Web 应用程序从 Windows 2003 迁移到 Windows 2012 R2。

该应用程序具有 Excel 报告功能。我们使用 Interop 打开 excel(模板文件)并写出一些数据并从服务器中的特定文件夹插入图像。

MS office 版本是 2007。奇怪的是插入图像功能仅在图像大小小于 20 kb 时有效,一旦应用程序尝试插入大于 20 kb 的图像,例如 250 kb,系统挂起,好像它没有足够的内存来完成这项工作,并且 excel.exe 在任务管理器中挂起。

在 Dcomcnfg 中,excel 以“启动用户”身份运行。

IIS 应用程序池正在使用网络服务来运行应用程序。

插入图像的代码如下所示,但由于它在 Windows 2003 中工作,我们没有更改任何内容

public void InsertImage(string imagePath, float leftPosition, float topPosition, float   imageWidth, float heightImage)
    {
        if (!File.Exists(imagePath))
            throw new   OfficeHelperException(OfficeHelperException.ExceptionType.ImageFileNotFound);

        WorkingSheet.Shapes.AddPicture(
            imagePath,
            Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoCTrue,
            leftPosition,
            topPosition,
            imageWidth,
            heightImage);
    }

新的windows 2012 r2有内存分配设置吗? Web 应用程序有其他没有图像导出的 excel 报告,它们工作正常。

我们试图通过在模板文件中放置一个宏来删除此插入图像功能,该宏将插入图像并从互操作中调用宏。它在本地机器上工作,但在服务器上,当图像大小大于 20 kb 时,它再次挂起。

我们对此感到困惑,不确定 Windows Server 2012 R2 是否存在与 Excel 互操作相关的任何已知问题。任何建议将不胜感激。

【问题讨论】:

  • 我们找到了您的帖子,因为我们几乎处于完全相同的情况并面临同样的问题......只是挂在 AddPicture 调用一些图像。您找到问题/解决方案了吗?
  • 根据@B17 的回答Server-Side automation of Office is not supported,尝试使用Open XML SDK 而不是Interop。

标签: excel office-interop excel-interop


【解决方案1】:

我将参数 MsoTriState LinkToFile 设置为 true 并且工作正常!我正在使用 Win 2012 R2 和 Excel 2010 x64。

例如:

oHoja.Shapes.AddPicture(HttpContext.Current.Server.MapPath("~/images/logos/57/teix.png", 
     MsoTriState.msoCTrue, MsoTriState.msoCTrue,float.Parse(3.ToString()), 
     float.Parse(65.ToString()), 
     float.Parse("113"), 
     float.Parse("54"));

祝你好运!

【讨论】:

    【解决方案2】:

    我们有同样的问题。我通过安装 MS Office 2013 修复了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多