【问题标题】:Meaning of ClipboardFormat values 44 and 50ClipboardFormat 值 44 和 50 的含义
【发布时间】:2018-05-29 16:24:45
【问题描述】:

Excel 的 Application 对象有一个 ClipboardFormats 属性。来自文档:

以数值数组的形式返回剪贴板上当前的格式。

但是,当我运行以下代码时:

var app = new ActiveXObject('Excel.Application');
app.Visible = true;
var results = new VBArray(app.ClipboardFormats).toArray();
app.Quit();
window.alert(results.join(','));

我回来了:

0、44、50

0 对应于 XlClipboardFormat.xlClipboardFormatText,但其他值在 XlClipboardFormat 枚举中没有匹配的枚举成员。

4450 作为剪贴板格式值是什么意思?

【问题讨论】:

  • 人们已经对此感到疑惑十多年了,我认为我们应该在这里得到官方的回答
  • 数字数组是否会根据剪贴板中的内容而变化?例如,普通默认单元格 A1 与 A1 加粗字体?
  • @Banana [citation needed]

标签: vba excel jscript


【解决方案1】:

不知道这对进一步发展有多大帮助,但以this source 为例,我想出了以下测试代码:

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
Private Declare Function EnumClipboardFormats Lib "user32" _
                         (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardFormatName Lib "user32" _
                         Alias "GetClipboardFormatNameA" (ByVal wFormat As Long, _
                                                          ByVal lpString As String, _
                                                          ByVal nMaxCount As Long) As Long

Private Sub test()
    Dim results As Variant
    Dim fmtName As String
    Dim fmt As Long

    Range("A1").Copy
    results = Application.ClipboardFormats
    Debug.Print "For cell A1 (plain) = " & Join(results, ",")
    ClipboardFormats

    Range("A2").Copy
    results = Application.ClipboardFormats
    Debug.Print "For cell A2 (bold ) = " & Join(results, ",")
    ClipboardFormats

End Sub

Private Sub ClipboardFormats()
    Dim fmt As Long
    Dim fmtName As String
    Dim iClipBoardFormatNumber As Long

    OpenClipboard 0&
    If iClipBoardFormatNumber = 0 Then
        fmt = EnumClipboardFormats(0)
        Do While fmt <> 0
            fmtName = Space(255)
            GetClipboardFormatName fmt, fmtName, 255
            fmtName = Trim(fmtName)
            If fmtName <> vbNullString Then
                fmtName = Left(fmtName, Len(fmtName) - 1)
                Debug.Print "fmtName (" & fmt & ") = " & fmtName
            End If
            fmt = EnumClipboardFormats(fmt)
        Loop
    End If

    EmptyClipboard
    CloseClipboard
End Sub

输出很有趣,但不一定具有启发性:

For cell A1 (plain) = 0,2,4,5,6,7,8,9,11,12,14,17,19,22,23,31,32,33,44,45,50,58,63
fmtName (49161) = DataObject
fmtName (50023) = Biff12
fmtName (50004) = Biff8
fmtName (50006) = Biff5
fmtName (49910) = XML Spreadsheet
fmtName (49349) = HTML Format
fmtName (49566) = CSV
fmtName (49273) = Rich Text Format
fmtName (49163) = Embed Source
fmtName (49156) = Native
fmtName (49155) = OwnerLink
fmtName (49166) = Object Descriptor
fmtName (49165) = Link Source
fmtName (49167) = Link Source Descriptor
fmtName (50003) = Link
fmtName (49154) = ObjectLink
fmtName (49171) = Ole Private Data
For cell A2 (bold ) = 0,2,4,5,6,7,8,9,11,12,14,17,19,22,23,31,32,33,44,45,50,58,63
fmtName (49161) = DataObject
fmtName (50023) = Biff12
fmtName (50004) = Biff8
fmtName (50006) = Biff5
fmtName (49910) = XML Spreadsheet
fmtName (49349) = HTML Format
fmtName (49566) = CSV
fmtName (49273) = Rich Text Format
fmtName (49163) = Embed Source
fmtName (49156) = Native
fmtName (49155) = OwnerLink
fmtName (49166) = Object Descriptor
fmtName (49165) = Link Source
fmtName (49167) = Link Source Descriptor
fmtName (50003) = Link
fmtName (49154) = ObjectLink
fmtName (49171) = Ole Private Data

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 2014-10-02
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 2021-05-13
    相关资源
    最近更新 更多