ExcelÀ» ÀÚµ¿ÈÇÏ¿© ADO ·¹ÄÚµå ÁýÇÕÀÇ ³»¿ëÀ» Microsoft Excel ¿öÅ©½ÃÆ®·Î Àü¼ÛÇÒ ¼ö
ÀÖ½À´Ï´Ù. ÀÚµ¿ÈÇÒ Excel ¹öÀü¿¡ µû¶ó »ç¿ëÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀÌ °¢°¢ ´Ù¸¨´Ï´Ù. Excel 97, Excel 2000 ¹× Excel
2002¿¡´Â ·¹ÄÚµå ÁýÇÕÀ» ¹üÀ§·Î Àü¼ÛÇÏ´Â µ¥ »ç¿ëÇÒ ¼ö ÀÖ´Â CopyFromRecordset ¸Þ¼µå°¡ ÀÖ½À´Ï´Ù. Excel 2000 ¹×
2002ÀÇ CopyFromRecordset´Â DAO ¶Ç´Â ADO ·¹ÄÚµå ÁýÇÕÀ» º¹»çÇÏ´Â µ¥ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×·¯³ª Excel 97ÀÇ
CopyFromRecordset´Â DAO ·¹ÄÚµå ÁýÇÕ¸¸ Áö¿øÇÕ´Ï´Ù. ADO ·¹ÄÚµå ÁýÇÕÀ» Excel 97·Î Àü¼ÛÇÏ·Á¸é ·¹ÄÚµå ÁýÇÕÀÇ ¹è¿À»
¸¸µç ´ÙÀ½ ¹üÀ§¸¦ ÇØ´ç ¹è¿ÀÇ ³»¿ëÀ¸·Î ä¿ï ¼ö ÀÖ½À´Ï´Ù.
ÀÌ ¹®¼¿¡¼´Â µÎ ¹æ¹ýÀ» ¸ðµÎ ¼³¸íÇÕ´Ï´Ù. Á¦°øµÈ ¿¹Á¦ Äڵ忡¼´Â
ADO ·¹ÄÚµå ÁýÇÕÀ» Excel 97, Excel 2000 ¶Ç´Â Excel 2002·Î Àü¼ÛÇÏ´Â ¹æ¹ýÀ» º¸¿©ÁÝ´Ï´Ù.
¾Æ·¡¿¡ Á¦°øµÈ ÄÚµå ¿¹Á¦¿¡¼´Â Microsoft Visual BasicÀÇ ÀÚµ¿È ±â´ÉÀ» »ç¿ëÇÏ¿© ADO
·¹ÄÚµå ÁýÇÕÀ» Microsoft Excel ¿öÅ©½ÃÆ®¿¡ º¹»çÇÏ´Â ¹æ¹ýÀ» º¸¿©ÁÝ´Ï´Ù. ÄÚµå´Â ¸ÕÀú Excel ¹öÀüÀ» °Ë»çÇÕ´Ï´Ù. Excel
2000 ¶Ç´Â 2002°¡ °Ë»öµÇ¸é È¿À²ÀûÀÌ°í º¸´Ù ÀûÀº Äڵ带 ÇÊ¿ä·Î ÇÑ´Ù´Â ÀÌÀ¯·Î CopyFromRecordset ¸Þ¼µå°¡ »ç¿ëµË´Ï´Ù.
±×·¯³ª Excel 97 ÀÌÀü ¹öÀüÀÌ °Ë»öµÇ¸é ADO ·¹ÄÚµå ÁýÇÕ °³Ã¼ÀÇ GetRows ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© ·¹ÄÚµå ÁýÇÕÀÌ ¸ÕÀú ¹è¿·Î º¹»çµË´Ï´Ù.
ÀÌÈÄ ·¹Äڵ尡 ù ¹øÂ° Â÷¿ø(Çà)¿¡ ÀÖ°í Çʵ尡 µÎ ¹øÂ° Â÷¿ø(¿)¿¡ ÀÖµµ·Ï ¹è¿ÀÌ ¹Ù²ò´Ï´Ù. ±×·± ´ÙÀ½ ¹è¿À» ¼¿ ¹üÀ§¿¡ ÇÒ´çÇÏ´Â ¹æ¹ýÀ»
ÅëÇØ ¹è¿ÀÌ Excel ¿öÅ©½ÃÆ®·Î º¹»çµË´Ï´Ù. ¹è¿Àº ¿öÅ©½ÃÆ®ÀÇ °¢ ¼¿À» ¸ðµÎ ¼øÈ¯ÇÏ´Â ´ë½Å ÇÑ ´Ü°è·Î º¹»çµË´Ï´Ù.
ÄÚµå
¿¹Á¦¿¡¼´Â Microsoft Office¿¡ Æ÷ÇÔµÈ Northwind ¿¹Á¦ µ¥ÀÌÅͺ£À̽º¸¦ »ç¿ëÇÕ´Ï´Ù. Microsoft Office¸¦ ¼³Ä¡ÇÒ ¶§
±âº» Æú´õ¸¦ ¼±ÅÃÇÑ °æ¿ì µ¥ÀÌÅͺ£À̽º´Â ´ÙÀ½ À§Ä¡¿¡ ÀÖ½À´Ï´Ù.
\Program Files\Microsoft
Office\Office\Samples\Northwind.mdb
Northwind µ¥ÀÌÅͺ£À̽º°¡ ÄÄÇ»ÅÍÀÇ ´Ù¸¥ Æú´õ¿¡ ÀÖ´Â
°æ¿ì ¾Æ·¡¿¡ Á¦°øµÈ Äڵ忡¼ µ¥ÀÌÅͺ£À̽ºÀÇ °æ·Î¸¦ ÆíÁýÇØ¾ß ÇÕ´Ï´Ù.
½Ã½ºÅÛ¿¡ Northwind µ¥ÀÌÅͺ£À̽º°¡ ¼³Ä¡µÇ¾î ÀÖÁö
¾ÊÀº °æ¿ì Microsoft Office ¼³Ä¡ ÇÁ·Î±×·¥ÀÇ Ãß°¡/Á¦°Å ¿É¼ÇÀ» »ç¿ëÇÏ¿© ¿¹Á¦ µ¥ÀÌÅͺ£À̽º¸¦ ¼³Ä¡ÇÒ ¼ö ÀÖ½À´Ï´Ù.
¿¹Á¦¸¦ ¸¸µå´Â ´Ü°è
- Visual BasicÀ» ½ÃÀÛÇϰí Ç¥ÁØ EXE ÇÁ·ÎÁ§Æ®¸¦ »õ·Î ¸¸µì´Ï´Ù. ±âº»ÀûÀ¸·Î Form1ÀÌ
»ý¼ºµË´Ï´Ù.
- Form1¿¡ CommandButtonÀ» Ãß°¡ÇÕ´Ï´Ù.
- ÇÁ·ÎÁ§Æ® ¸Þ´º¿¡¼ ÂüÁ¶¸¦ ´©¸¨´Ï´Ù. Microsoft ActiveX Data Objects 2.1 Library¿¡ ´ëÇÑ ÂüÁ¶¸¦ Ãß°¡ÇÕ´Ï´Ù.
- Form1ÀÇ ÄÚµå ±¸¿ª¿¡ ´ÙÀ½ Äڵ带 ºÙ¿© ³Ö½À´Ï´Ù.
Private Sub Command1_Click()
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim recArray As Variant
Dim strDB As String
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer
' Set the string to the path of your Northwind database
strDB = "c:\program files\Microsoft office\office11\samples\Northwind.mdb"
' Open connection to the database
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDB & ";"
' Open recordset based on Orders table
rst.Open "Select * From Orders", cnt
' Create an instance of Excel and add a workbook
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets("Sheet1")
' Display Excel and give user control of Excel's lifetime
xlApp.Visible = True
xlApp.UserControl = True
' Copy field names to the first row of the worksheet
fldCount = rst.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next
' Check version of Excel
If Val(Mid(xlApp.Version, 1, InStr(1, xlApp.Version, ".") - 1)) > 8 Then
'EXCEL 2000 or 2002: Use CopyFromRecordset
' Copy the recordset to the worksheet, starting in cell A2
xlWs.Cells(2, 1).CopyFromRecordset rst
'Note: CopyFromRecordset will fail if the recordset
'contains an OLE object field or array data such
'as hierarchical recordsets
Else
'EXCEL 97 or earlier: Use GetRows then copy array to Excel
' Copy recordset to an array
recArray = rst.GetRows
'Note: GetRows returns a 0-based array where the first
'dimension contains fields and the second dimension
'contains records. We will transpose this array so that
'the first dimension contains records, allowing the
'data to appears properly when copied to Excel
' Determine number of records
recCount = UBound(recArray, 2) + 1 '+ 1 since 0-based array
' Check the array for contents that are not valid when
' copying the array to an Excel worksheet
For iCol = 0 To fldCount - 1
For iRow = 0 To recCount - 1
' Take care of Date fields
If IsDate(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = Format(recArray(iCol, iRow))
' Take care of OLE object fields or array fields
ElseIf IsArray(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = "Array Field"
End If
Next iRow 'next record
Next iCol 'next field
' Transpose and Copy the array to the worksheet,
' starting in cell A2
xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = _
TransposeDim(recArray)
End If
' Auto-fit the column widths and row heights
xlApp.Selection.CurrentRegion.Columns.AutoFit
xlApp.Selection.CurrentRegion.Rows.AutoFit
' Close ADO objects
rst.Close
cnt.Close
Set rst = Nothing
Set cnt = Nothing
' Release Excel references
Set xlWs = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
End Sub
Function TransposeDim(v As Variant) As Variant
' Custom Function to Transpose a 0-based array (v)
Dim X As Long, Y As Long, Xupper As Long, Yupper As Long
Dim tempArray As Variant
Xupper = UBound(v, 2)
Yupper = UBound(v, 1)
ReDim tempArray(Xupper, Yupper)
For X = 0 To Xupper
For Y = 0 To Yupper
tempArray(X, Y) = v(Y, X)
Next Y
Next X
TransposeDim = tempArray
End Function
- F5 ۸¦ ´·¯ ÇÁ·ÎÁ§Æ®¸¦ ½ÇÇàÇÕ´Ï´Ù. Form1ÀÌ ³ªÅ¸³³´Ï´Ù.
- Form1¿¡¼ CommandButtonÀ» ´©¸£°í Orders Å×À̺íÀÇ ³»¿ëÀÌ ExcelÀÇ »õ ÅëÇÕ ¹®¼¿¡ Ç¥½ÃµÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
CopyFromRecordset »ç¿ë È¿À²¼º°ú ¼º´ÉÀ» À§ÇØ ±âº»ÀûÀ¸·Î »ç¿ëÇÏ´Â ¸Þ¼µå´Â CopyFromRecordsetÀÔ´Ï´Ù. Excel
97Àº CopyFromRecordset°¡ ÀÖ´Â DAO ·¹ÄÚµå ÁýÇÕ¸¸ Áö¿øÇϱ⠶§¹®¿¡ Excel 97¿¡¼ ADO ·¹ÄÚµå ÁýÇÕÀ»
CopyFromRecordset·Î Àü´ÞÇÏ·Á°í ÇÏ¸é ´ÙÀ½ ¿À·ù°¡ ¹ß»ýÇÕ´Ï´Ù.
·±Å¸ÀÓ ¿À·ù 430:
Ŭ·¡½º°¡ ÀÚµ¿È¸¦ Áö¿øÇÏÁö ¾Ê°Å³ª ¿¹»óµÇ´Â ÀÎÅÍÆäÀ̽º¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.
ÄÚµå ¿¹Á¦¿¡¼ 97 ¹öÀü¿¡ ´ëÇØ
CopyFromRecordset¸¦ »ç¿ëÇÏÁö ¾Êµµ·Ï ExcelÀÇ ¹öÀüÀ» °Ë»çÇÏ¿© ÀÌ ¿À·ù¸¦ ÇÇÇÒ ¼ö ÀÖ½À´Ï´Ù.
Âü°í CopyFromRecordset¸¦ »ç¿ëÇÒ ¶§´Â »ç¿ëÇÏ´Â ADO ¶Ç´Â DAO ·¹ÄÚµå ÁýÇÕÀÌ °èÃþÀû ·¹ÄÚµå ÁýÇÕ °°Àº
OLE °³Ã¼ Çʵ峪 ¹è¿ µ¥ÀÌÅ͸¦ Æ÷ÇÔÇÒ ¼ö ¾ø´Ù´Â °ÍÀ» ¾Ë°í ÀÖ¾î¾ß ÇÕ´Ï´Ù. ·¹ÄÚµå ÁýÇÕ¿¡ ¾î´À ÇÑ À¯ÇüÀÇ Çʵ带 Æ÷ÇÔÇÏ´Â °æ¿ì
CopyFromRecordset ¸Þ¼µå´Â ´ÙÀ½ ¿À·ù¿Í ÇÔ²² ½ÇÆÐÇÕ´Ï´Ù.
·±Å¸ÀÓ ¿À·ù
-2147467259:
Range °³Ã¼ÀÇ CopyFromRecordset ¸Þ¼µå¿¡¼ ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.
GetRows »ç¿ë Excel 97ÀÌ °Ë»öµÇ¸é ADO ·¹ÄÚµå ÁýÇÕÀÇ GetRows ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© ·¹ÄÚµå ÁýÇÕÀ»
¹è¿·Î º¹»çÇÕ´Ï´Ù. GetRows¿¡¼ ¹ÝȯÇÏ´Â ¹è¿À» ¿öÅ©½ÃÆ®ÀÇ ¼¿ ¹üÀ§¿¡ ÇÒ´çÇÏ´Â °æ¿ì µ¥ÀÌÅÍ´Â Çà ¾Æ·¡ÂÊÀÌ ¾Æ´Ñ ¿ °¡·Î ¹æÇâÀ¸·Î
¹è¿µË´Ï´Ù. ¿¹¸¦ µé¾î, ·¹ÄÚµå ÁýÇÕ¿¡ µÎ Çʵ尡 ÀÖ°í 10°³ÀÇ ÇàÀÌ ÀÖ´Â °æ¿ì ¹è¿Àº µÎ Çà°ú 10°³ÀÇ ¿·Î ³ªÅ¸³³´Ï´Ù. µû¶ó¼ ¹è¿À» ¼¿
¹üÀ§¿¡ ÇÒ´çÇϱâ Àü¿¡ TransposeDim() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¹è¿À» ¹Ù²Ù¾î¾ß ÇÕ´Ï´Ù. ¹è¿À» ¼¿ ¹üÀ§¿¡ ÇÒ´çÇÒ ¶§ ¸î °¡Áö Á¦ÇÑ »çÇ×ÀÌ
ÀÖ´Ù´Â °ÍÀ» ¾Ë¾Æ µÎ¾î¾ß ÇÕ´Ï´Ù.
´ÙÀ½ Á¦ÇÑ »çÇ×Àº ¹è¿À» Excel Range °³Ã¼¿¡ ÇÒ´çÇÒ ¶§ Àû¿ëµË´Ï´Ù.
- ¹è¿¿¡´Â °èÃþÀû ·¹ÄÚµå ÁýÇÕ °°Àº OLE °³Ã¼ Çʵ峪 ¹è¿ µ¥ÀÌÅͰ¡ Æ÷Ç﵃ ¼ö ¾ø½À´Ï´Ù. ÄÚµå ¿¹Á¦¿¡¼´Â
ÀÌ Á¶°ÇÀ» °Ë»çÇϰí "Array Field"¸¦ Ç¥½ÃÇÏ¿© Çʵ带 Excel¿¡ Ç¥½ÃÇÒ ¼ö ¾øÀ½À» »ç¿ëÀÚ¿¡°Ô
¾Ë¸³´Ï´Ù.
- ¹è¿¿¡´Â ³¯Â¥°¡ 1900³â ÀÌÀüÀÎ ³¯Â¥ Çʵ尡 Æ÷Ç﵃ ¼ö ¾ø½À´Ï´Ù. ÇØ´ç Microsoft ±â¼ú ÀÚ·á ¹®¼
¸µÅ©´Â "ÂüÁ¶" ÀýÀ» ÂüÁ¶ÇϽʽÿÀ. ÄÚµå ¿¹Á¦¿¡¼´Â ÀÌ ¹®Á¦°¡ ¹ß»ýÇÏÁö ¾Êµµ·Ï ³¯Â¥ Çʵ带 º¯Çü ¹®ÀÚ¿·Î ¼½Ä ÁöÁ¤ÇÕ´Ï´Ù.
¹è¿À» Excel ¿öÅ©½ÃÆ®·Î º¹»çÇϱâ Àü¿¡ TransposeDim() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¹è¿À» ¹Ù²ß´Ï´Ù. ÀÚü
ÇÔ¼ö¸¦ ¸¸µé¾î ¹è¿À» ¹Ù²Ù´Â ´ë½Å ¾Æ·¡ Ç¥½ÃµÈ ¼¿¿¡ ¹è¿À» ÇÒ´çÇÏ´Â ¿¹Á¦ Äڵ带 ¼öÁ¤ÇÏ¿© ExcelÀÇ Transpose ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö
ÀÖ½À´Ï´Ù.
xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = _
xlApp.WorksheetFunction.Transpose(recArray)
TransposeDim() ÇÔ¼ö¸¦ »ç¿ëÇÏ´Â ´ë½Å ExcelÀÇ Transpose ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© ¹è¿À» ¹Ù²Ù·Á´Â °æ¿ì
Transpose ¸Þ¼µå¿¡ ´ÙÀ½°ú °°Àº Á¦ÇÑ »çÇ×ÀÌ ÀÖÀ½À» À¯³äÇØ¾ß ÇÕ´Ï´Ù.
- ¹è¿¿¡´Â 255ÀÚ ÀÌ»óÀÇ ¿ä¼Ò°¡ Æ÷Ç﵃ ¼ö ¾ø½À´Ï´Ù.
- ¹è¿¿¡´Â Null °ªÀÌ Æ÷Ç﵃ ¼ö ¾ø½À´Ï´Ù.
- ¹è¿¿¡ ÀÖ´Â ¿ä¼Ò ¼ö´Â 5461À» ÃʰúÇÒ ¼ö ¾ø½À´Ï´Ù.
¹è¿À» Excel ¿öÅ©½ÃÆ®·Î º¹»çÇÒ ¶§ À§ÀÇ Á¦ÇÑ »çÇ×À» °í·ÁÇÏÁö ¾ÊÀ» °æ¿ì ´ÙÀ½°ú °°Àº ·±Å¸ÀÓ ¿À·ù Áß Çϳª°¡
¹ß»ýÇÒ ¼ö ÀÖ½À´Ï´Ù.
·±Å¸ÀÓ ¿À·ù 13: Çü½ÄÀÌ ÀÏÄ¡ÇÏÁö ¾Ê½À´Ï´Ù.
·±Å¸ÀÓ ¿À·ù 5: À߸øµÈ ÇÁ·Î½ÃÀú È£Ãâ ¶Ç´Â ÀμöÀÔ´Ï´Ù.
·±Å¸ÀÓ ¿À·ù 1004: ÀÀ¿ë ÇÁ·Î±×·¥ Á¤ÀÇ ¶Ç´Â °³Ã¼ Á¤ÀÇ ¿À·ùÀÔ´Ï´Ù.
´Ù¾çÇÑ Excel ¹öÀü¿¡ ¹è¿À» Àü´ÞÇÒ ¶§ÀÇ Á¦ÇÑ »çÇ׿¡ ´ëÇÑ ÀÚ¼¼ÇÑ
³»¿ëÀº Microsoft ±â¼ú ÀÚ·áÀÇ ´ÙÀ½ ¹®¼¸¦ ÂüÁ¶ÇϽʽÿÀ.
177991
(http://support.microsoft.com/kb/177991/
)
XL: ÀÚµ¿È¸¦ »ç¿ëÇÏ¿© Excel¿¡ ¹è¿À» Àü´ÞÇÒ ¶§ÀÇ Á¦ÇÑ »çÇ×
ÀÚ¼¼ÇÑ ³»¿ëÀº Microsoft ±â¼ú ÀÚ·áÀÇ ´ÙÀ½ ¹®¼¸¦ ÂüÁ¶ÇϽʽÿÀ.
146406
(http://support.microsoft.com/kb/146406/
)
DAO¸¦ »ç¿ëÇÏ¿© Access¿¡¼ Excel·Î Å×À̺íÀ» °Ë»öÇÏ´Â ¹æ¹ý
215965
(http://support.microsoft.com/kb/215965/
)
XL2000: 12:00:00 AMÀÌ 1900³â ÀÌÀü ³¯Â¥·Î Ç¥½ÃµÈ´Ù
243394
(http://support.microsoft.com/kb/243394/
)
HOWTO: MFC¸¦ »ç¿ëÇÏ¿© ÀÚµ¿È·Î DAO ·¹ÄÚµå ÁýÇÕÀ» Excel·Î º¹»ç
247412
(http://support.microsoft.com/kb/247412/
)
INFO: Visual Basic¿¡¼ Excel·Î µ¥ÀÌÅ͸¦ Àü¼ÛÇÏ´Â ¹æ¹ý
Microsoft Á¦Ç° °ü·Ã ±â¼ú Àü¹®°¡µé°ú ¿Â¶óÀÎÀ¸·Î Á¤º¸¸¦ ±³È¯ÇϽ÷Á¸é Microsoft ´º½º ±×·ì
(http://support.microsoft.com/newsgroups/default.aspx)
¿¡ Âü¿©ÇϽñ⠹ٶø´Ï´Ù.±â¼ú ÀÚ·á: 246335 - ¸¶Áö¸· °ËÅä: 2005³â 11¿ù 3ÀÏ ¸ñ¿äÀÏ - ¼öÁ¤: 4.3
º» ¹®¼ÀÇ Á¤º¸´Â ´ÙÀ½ÀÇ Á¦Ç°¿¡ Àû¿ëµË´Ï´Ù.
- Microsoft Office Excel 2003
- Microsoft Excel 2002 Standard Edition
- Microsoft Excel 2000 Standard Edition
- Microsoft Excel 97 Standard Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft ActiveX Data Objects 2.0
- Microsoft ActiveX Data Objects 2.1
- Microsoft ActiveX Data Objects 2.5
| kbhowto kbautomation KB246335 |