Spax EA将图表导出到Word文档的最佳方法 [英] Spax EA best way to export diagrams into Word document

查看:1060
本文介绍了Spax EA将图表导出到Word文档的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个旧模块,该模块使用sparx ea项目中的数据生成报告.

Got an old module which is generates reports with data from sparx ea project.

有一部分需要在文档中插入图表作为图片.

There is a part where you need to insert diagrams as pictures in the document.

现在看起来像这样

 public static void copyDiagram(
            EA.Diagram diagram,
            EA.Repository eaRepository)
        {
            eaRepository.App.Project.PutDiagramImageOnClipboard(diagram.DiagramGUID, 0);
            eaRepository.CloseDiagram(diagram.DiagramID);
        }

将其复制到剪贴板,然后出现类似 currentDocumentRange.Paste()

copying it to clipboard, and after that there goes something like currentDocumentRange.Paste()

对我来说很奇怪. 我认为使用这样的剪贴板并不是很好,所以我想在将来重写它.

Looks strange for me. I think it's not really good to use clipboard like that, so I want to rewrite it in future.

所以,只有我在那找到的其他功能看起来像PutDiagramImageToFile(diagrammGUID, path, type)

So, only other function I found there looks like that PutDiagramImageToFile(diagrammGUID, path, type)

如果没有更好的选择,可以创建新文件,然后通过路径将其插入到Word文档中,然后将其删除吗?

If there are no better option is it okay to create new file, after that get it by it's path insert into word document, and then delete it?

或者,也许还有其他SparxEA函数,可以从图中以byte[]格式或类似Image格式获取图像?

Or, maybe there are some other SparxEA function, which get image from diagram in byte[] format or like Image format?

哪种方法更好?

推荐答案

我正在使用此代码(在图包装类上)来获取图的图像,而不必使用剪贴板.
此代码主要用于自定义书面文档生成器中,并且速度惊人.

I'm using this code (on a diagram wrapper class) to get the image of a diagram without having to use the clipboard.
This code is used primarily in a custom written document generator and is surprisingly fast.

/// <summary>
/// returns diagram image
/// </summary>
public Image image
{
    get 
    {
        EA.Project projectInterface = this.model.getWrappedModel().GetProjectInterface();
        string diagramGUID = projectInterface.GUIDtoXML(this.wrappedDiagram.DiagramGUID);
        string filename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
        //save diagram image to file (format ".png")
        projectInterface.PutDiagramImageToFile(diagramGUID, filename, 1);
        //load the contents of the file into a memorystream
        MemoryStream imageStream = new MemoryStream(File.ReadAllBytes(filename));
        //then create the image from the memorystream.
        //this allows us to delete the temporary file right after loading it.
        //When using Image.FromFile the file would have been locked for the lifetime of the Image
        Image diagramImage = Image.FromStream(imageStream);
        //delete the temorary file
        System.IO.File.Delete(filename);

        return diagramImage;
    }
}

这篇关于Spax EA将图表导出到Word文档的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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