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枚举中没有匹配的枚举成员。
44
和50
作为剪贴板格式值的含义是什么?
答案 0 :(得分:4)
不知道这会有多大帮助,但从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