gpt4 book ai didi

Excel 将图表导出为 wmf 或 emf?

转载 作者:行者123 更新时间:2023-12-02 04:32:40 32 4
gpt4 key购买 nike

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

如果导出为 GIF 但不使用 WMF 作为过滤器名称,则该代码有效。

这有效:

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

但是

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

失败并给出错误:

Run-time error '1004': Application-defined or object-defined error

Powerpoint 允许您导出为 WMF。我通过将图形复制到 Powerpoint 并让 Powerpoint 将图像导出到 WMF 来“成功”导出,但必须有一种更简单的方法 - 我希望。

我想知道是否有办法为 Excel 注册 WMF 过滤器,但我不确定如何执行此操作。请帮忙!谢谢。

最佳答案

这种复制、保存方法对我有用,我将其分为 3 个部分(声明、另存为 EMF 函数以及选择/复制/函数调用部分):

*我找到了this article详细说明了如何保存到 EMF,然后对其进行了一些修改以使用 ActiveChart 而不是任意选择。

首先声明几个:

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的使用在文章中有解释):

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

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

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?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1791369/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com