Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ubuntu 18.04下导出图片失败 #285

Closed
zhdwwf opened this issue Jun 16, 2021 · 15 comments
Closed

ubuntu 18.04下导出图片失败 #285

zhdwwf opened this issue Jun 16, 2021 · 15 comments
Labels

Comments

@zhdwwf
Copy link

zhdwwf commented Jun 16, 2021

在ubuntu 18.04下使用模板导出图片失败,同一个程序在windows下导出正常,请问ubuntu下是需要专门配置什么吗?已安装 libgdiplus

@hueifeng
Copy link
Member

请问ubuntu下是需要专门配置什么吗?
可以参考Dockerfile

# 如不使用上述基础镜像,那么需要添加以下命令来安装libgdiplus库,用于Excel导出
RUN apt-get update && apt-get install -y libgdiplus libc6-dev
RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll

在上述处理完后,还不能解决您的问题,我建议您附加一下错误明细信息.

@hueifeng hueifeng added the area-excel excel label Jun 17, 2021
@zhdwwf
Copy link
Author

zhdwwf commented Jun 17, 2021

谢谢您的回复,我遇到的问题比较奇怪,程序没有报任何错误,执行后程序卡住无响应,一直处于处理中的状态,查看进程,cpu使用100%,程序代码如下:

    class Program
    {
        static async Task Main(string[] args)
        {
            IExporter exporter = new ExcelExporter();
            var data = new List<ExportTestDataWithPicture>();
            data.Add(new ExportTestDataWithPicture
            {
                Img = "http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg"
            });

            var filePath = Path.Combine(AppContext.BaseDirectory, "test.xlsx");
            var result = await exporter.Export(filePath, data);
            Console.WriteLine(result.FileName);
        }
    }

    [ExcelExporter(Name = "测试")]
    public class ExportTestDataWithPicture
    {
        [ExportImageField(Width = 50, Height = 120, Alt = "404")]
        [ExporterHeader(DisplayName = "", IsAutoFit = false)]
        public string Img { get; set; }
    }

执行后的情况:
image
image
同样的程序在windows下可以正常生成Excel,Ubuntu下已经安装了libgdiplus、libc6-dev并且做了软链接,这种问题根据您的经验有可能是哪里引起的呢?

@hueifeng
Copy link
Member

您可以通过WSL2进行调试,也可以将这个测试项目上传,我这边看一下。

@xin-lai
Copy link
Collaborator

xin-lai commented Jun 17, 2021

我们测试一下。

@zhdwwf
Copy link
Author

zhdwwf commented Jun 17, 2021

测试项目地址:https://github.com/zhdwwf/ExcelExportDemo
ubuntu环境是:阿里云ECS,Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-88-generic x86_64)
接下来我在win10的WSL2下测试一下, @hueifeng @xin-lai 您二位方便的话也可以用上边项目地址测试下,非常感谢!

@xl-wenqiang
Copy link
Collaborator

image

@xl-wenqiang
Copy link
Collaborator

https://www.nuget.org/packages/Magicodes.IE.Tools/

dotnet tool install --global Magicodes.IE.Tools --version 0.0.3

@xl-wenqiang
Copy link
Collaborator

@zhdwwf
Copy link
Author

zhdwwf commented Jun 18, 2021

测试了您的示例代码和mie test,对比了我的代码,发现问题出在图片格式上,如果是png图片,导出成功,jpg图片程序就会卡死,测试代码如下(已同步更新到 https://github.com/zhdwwf/ExcelExportDemo/blob/master/ExcelExportDemo/Program.cs)

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;

namespace ExcelExportDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            string format=args[0];
            string img=format.ToLower() == "png" ? "https://gitee.com/magicodes/Magicodes.IE/raw/master/docs/Magicodes.IE.png" : "https://gitee.com/magicodes/Magicodes.IE/raw/master/res/wechat.jpg";
            IExporter exporter = new ExcelExporter();

            var data = new List<ExportTestDataWithPicture>
            {
                new ExportTestDataWithPicture
                {
                    Img =img
                }
            };

            var filePath = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "test.xlsx");
            var result = exporter.Export("test.xlsx", data).Result;
            Console.WriteLine("导出成功!");
        }
    }

    [ExcelExporter(Name = "测试")]
    public class ExportTestDataWithPicture
    {
        [ExportImageField(Width = 50, Height = 120, Alt = "404")]
        [ExporterHeader(DisplayName = "", IsAutoFit = false)]
        public string Img { get; set; }
    }
}

测试结果见图:
test

@xin-lai
Copy link
Collaborator

xin-lai commented Jun 18, 2021

收到,非常感谢,我再试试。

@xin-lai
Copy link
Collaborator

xin-lai commented Jun 18, 2021

确实存在这个问题。

@zhdwwf
Copy link
Author

zhdwwf commented Jun 18, 2021

在WSL下调试发现JPG图片没能成功取到图片的HorizontalResolution、VerticalResolution导致while循环一直在执行,代码文件:
https://github.com/xin-lai/Magicodes.EPPlus/blob/479c8f7a08c35bba49d8d7ea2804edba352ce2a6/EPPlus/Drawing/ExcelPicture.cs#L262

        
        private void SetPosDefaults(Image image)
        {
            EditAs = eEditAs.OneCell;
            SetPixelWidth(image.Width, image.HorizontalResolution);
            SetPixelHeight(image.Height, image.VerticalResolution);
        }

此处的HorizontalResolution和VerticalResolution均为0,搜了一下此问题,发现libgdiplus下有issue提到
mono/libgdiplus#611
但我使用了新版本的libgdiplus依然获取不到,这里是否能够把获取图片分辨率改为固定值呢,比如使用定义的这个标准DPI

const float STANDARD_DPI = 96;

@xin-lai
Copy link
Collaborator

xin-lai commented Jun 18, 2021

收到,非常感谢,我们尽量尽快处理!

hueifeng added a commit to xin-lai/Magicodes.EPPlus that referenced this issue Jun 18, 2021
hueifeng added a commit that referenced this issue Jun 18, 2021
- Update ImportTestColumnIndex_Test
- Magicodes.EPPlus was upgraded to 4.6.7[#285](#285)
@hueifeng
Copy link
Member

目前我们发布了2.5.4.3现在您可以更新到最新版本,该问题已在该版本修复

@zhdwwf
Copy link
Author

zhdwwf commented Jun 18, 2021

感谢您的工作,我升级一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants