Excel将图表导出到WMF或EMF

Excel将图表导出到WMF或EMF

本文介绍了Excel将图表导出到WMF或EMF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图表从Excel导出为wmf或emf格式.

I am trying to export a chart from Excel to either the wmf or emf format.

如果您导出到GIF而不使用WMF作为过滤器名称,则该代码有效.

The code works if you export to GIF but not with WMF as the filtername.

这有效:

Chart.Export FileName:="current_sales.gif", FilterName:="GIF"

但是

Chart.Export FileName:="current_sales.wmf", FilterName:="WMF"

失败,提示错误:

Powerpoint允许您导出到WMF.通过将图形复制到Powerpoint中并让Powerpoint将图像导出到WMF中,我已经成功"导出了,但必须有一种更简单的方法-我希望.

Powerpoint allows you to export to WMF. And I have "successfully" exported by copying the graph into Powerpoint and having Powerpoint export the image to WMF but there has to be an easier way - I hope.

我想知道是否可以为Excel注册WMF筛选器,但是我不确定如何执行此操作.请帮忙!谢谢.

I wonder if there may be a way of registering the WMF filter for Excel but I am unsure how to do this. Please help! Thanks.

推荐答案

此复制,保存方法对我有用,我将其分为3部分(声明,另存为EMF函数,然后选择/copy/function调用部分):

This copy, save method worked for me, i put it into 3 sections (declarations, saves as EMF function, and the select/copy/function call section):

*我发现这篇文章详细介绍了如何保存到EMF,然后对其进行了一些修改ActiveChart而不是任意选择.

*I found this article detailing how to save to EMF then doctored it a bit to use the an ActiveChart instead of a arbitrary selection.

首先进行几个声明:

Option Explicit

Private Declare Function OpenClipboard _
    Lib "user32" ( _
        ByVal hwnd As Long) _
As Long

Private Declare Function CloseClipboard Lib "user32" () As Long

Private Declare Function GetClipboardData _
    Lib "user32" ( _
        ByVal wFormat As Long) _
As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long

'// CreateMetaFileA DeleteEnhMetaFile
Private Declare Function CopyEnhMetaFileA _
    Lib "gdi32" ( _
        ByVal hENHSrc As Long, _
        ByVal lpszFile As String) _
As Long

Private Declare Function DeleteEnhMetaFile _
    Lib "gdi32" ( _
        ByVal hemf As Long) _
As Long

这是实际的另存为emf函数(在本文中介绍了CopyEnhMetaFileA和DeleteEnhMetaFile的用法):

This is the actual save as emf function (the use of CopyEnhMetaFileA and DeleteEnhMetaFile are explained in the article):

Public Function fnSaveAsEMF(strFileName As String) As Boolean
Const CF_ENHMETAFILE As Long = 14

Dim ReturnValue As Long

    OpenClipboard 0

    ReturnValue = CopyEnhMetaFileA(GetClipboardData(CF_ENHMETAFILE), strFileName)

    EmptyClipboard

    CloseClipboard

    '// Release resources to it eg You can now delete it if required
    '// or write over it. This is a MUST
    DeleteEnhMetaFile ReturnValue

    fnSaveAsEMF = (ReturnValue <> 0)

End Function

然后选择,复制和函数调用部分:

Then the select, copy, and function call section:

Sub SaveIt()
Charts.Add
    ActiveChart.ChartArea.Select
    Selection.Copy
    If fnSaveAsEMF("C:\Excel001.emf") Then
        MsgBox "Saved", vbInformation
    Else
        MsgBox "NOT Saved!", vbCritical
    End If

End Sub

这篇关于Excel将图表导出到WMF或EMF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:14