列类型 [英] Column Type
问题描述
我有一张桌子的Acces Db。表有4行(第1行和第3行是
整数,2& 4是文本)。
现在我想将表导出到Excel工作簿。
我使用的下一个代码工作(差不多)。
///代码
''创建一个Recordset Orders表中的所有记录。
Dim sNWind As String
Dim conn As New ADODB.Connection()
Dim rs As ADODB。记录集
conn.Open(" Provider = Microsoft.Jet.OLEDB.4.0; Data Source ="& _
sNorthwind&";")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute(" Orders",,ADODB.CommandTypeEnum.adCmdTable)
>
''在Excel中创建一个新工作簿。
Dim oExcel As Object
Dim oBook as Object
Dim oSheet As Object
oExcel = CreateObject(" Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheet s(1)
''将字段名转移到工作表的第1行:
''注意:CopyFromRecordset只复制数据而不复制字段
''名称,所以你可以通过遍历
''字段集来转移字段名。
Dim n As Int32
对于n = 1到rs.Fields.Count
oSheet.Cells(1,n).Value = rs.Fields(n - 1).Name
下一页
''将数据传输到Excel。
oSheet.Range(" A2")。CopyFromRecordset(rs)
''保存工作簿并退出Excel。
oBook.SaveAs(sSampleFolder& Book3.xls)
oSheet =没什么
oBook =没什么
oExcel.Quit()
oExcel = Nothing
GC.Collect()
''关闭连接
rs.Close()
conn.Close()
///代码
代码没有一件事。也就是说,将
列属性(整数,文本)复制到Excel。
有谁知道我怎么能用它来完成这个。
提前致谢
Niels,
为什么你要使用Adodb?你有ADONET时使用互操作。
这是我的想法中的一个完整示例,如何使用ADONET做你想做的事。
http://support.microsoft.com/default...b ; EN-US; 316934
我希望这有帮助吗?
Cor
" Niels" < ni **** @ hollandridderkerk.nl>
我有一个带有一个表的Acces Db。表有4行(第1行和第3行是
整数,2& 4是文本)。
现在我想将表导出到Excel工作簿。
下一个代码我用来工作(差不多)。
///代码
''从Orders表中的所有记录创建一个Recordset。
Dim sNWind As String
Dim conn As New ADODB.Connection()
Dim rs As ADODB.Recordset
conn.Open(" Provider = Microsoft.Jet.OLEDB.4.0; Data Source ="& _
sNorthwind&" ;;")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute(" Orders",,ADODB.CommandTypeEnum.adCmdTable)
< br'>''在Excel中创建一个新的工作簿。
Dim oExcel As Object
Dim oBook as Object
Dim oSheet as Object
oExcel = CreateObject(" Excel.Application" )
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
''将字段名称传输到工作表的第1行:
''注意:CopyFromRecordset只复制数据,而不复制字段
''名称,因此您可以通过遍历
''字段集来传输字段名。
Dim n As Int32
对于n = 1到rs.Fields.Count
oSheet.Cells(1,n).Value = rs.Fields(n - 1).Name
下一页
''将数据传输到Excel。
oSheet.Range(" A2")。CopyFromRecordset(rs)
''保存工作簿并退出Excel。
oBook.SaveAs(sSampleFolder& Book3.xls)
oSheet =没什么
oBook =没什么
oExcel.Quit()
oExcel = Nothing
GC.Collect()
''关闭连接
rs.Close()
conn.Close()
///代码
代码有一件事才不是。也就是说,将
columnproperties(整数,文本)复制到Excel。
有谁知道我如何能够实现这一点。
提前致谢
Niels,
为什么你使用Adodb,因此在有ADONET时使用互操作。
我的想法中有一个完整的示例如何使用ADONET做你想做的事。
http://support.microsoft.com/default...b;EN-US;316934
我希望这有帮助吗?
Cor
" Niels" < ni **** @ hollandridderkerk.nl>
我有一个带有一个表的Acces Db。表有4行(第1行和第3行是
整数,2& 4是文本)。
现在我想将表导出到Excel工作簿。
下一个代码我用来工作(差不多)。
///代码
''从Orders表中的所有记录创建一个Recordset。
Dim sNWind As String
Dim conn As New ADODB.Connection()
Dim rs As ADODB.Recordset
conn.Open(" Provider = Microsoft.Jet.OLEDB.4.0; Data Source ="& _
sNorthwind&" ;;")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute(" Orders",,ADODB.CommandTypeEnum.adCmdTable)
< br'>''在Excel中创建一个新的工作簿。
Dim oExcel As Object
Dim oBook as Object
Dim oSheet as Object
oExcel = CreateObject(" Excel.Application" )
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
''将字段名称传输到工作表的第1行:
''注意:CopyFromRecordset只复制数据,而不复制字段
''名称,因此您可以通过遍历
''字段集来传输字段名。
Dim n As Int32
对于n = 1到rs.Fields.Count
oSheet.Cells(1,n).Value = rs.Fields(n - 1).Name
下一页
''将数据传输到Excel。
oSheet.Range(" A2")。CopyFromRecordset(rs)
''保存工作簿并退出Excel。
oBook.SaveAs(sSampleFolder& Book3.xls)
oSheet =没什么
oBook =没什么
oExcel.Quit()
oExcel = Nothing
GC.Collect()
''关闭连接
rs.Close()
conn.Close()
///代码
代码有一件事才不是。也就是说,将
columnproperties(整数,文本)复制到Excel。
有谁知道我如何能够实现这一点。
提前致谢
On Thu,2004年11月11日10:23:32 +0100,Cor Ligthert <无************ @ planet.nl>写道:
$ b $b¤Niels,
$ b $b¤
$ b $b¤为什么你使用Adodb,因此在有ADONET时使用互操作。< br $> $ b $b¤
CopyFromRecordset需要ADO或DAO Recordset对象。它不支持ADO.NET。
Paul ~~~ pc ****** @ ameritech.net
Microsoft MVP(Visual Basic)
Hi,
I have a Acces Db with one Table. The Table has 4 rows (row 1 & 3 are
integer and 2 & 4 are text).
Now i want to export the Table to an Excel workbook.
the next code i used is working (almost) fine.
///Code
''Create a Recordset from all the records in the Orders table.
Dim sNWind As String
Dim conn As New ADODB.Connection()
Dim rs As ADODB.Recordset
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sNorthwind & ";")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute("Orders", , ADODB.CommandTypeEnum.adCmdTable)
''Create a new workbook in Excel.
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
''Transfer the field names to Row 1 of the worksheet:
''Note: CopyFromRecordset copies only the data and not the field
'' names, so you can transfer the fieldnames by traversing the
'' fields collection.
Dim n As Int32
For n = 1 To rs.Fields.Count
oSheet.Cells(1, n).Value = rs.Fields(n - 1).Name
Next
''Transfer the data to Excel.
oSheet.Range("A2").CopyFromRecordset(rs)
''Save the workbook and quit Excel.
oBook.SaveAs(sSampleFolder & "Book3.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
''Close the connection
rs.Close()
conn.Close()
///Code
There is one thing that the code does not. And that is, copying the
columnproperties(integer, text) to Excel.
Does anyone know how i can acomplish this.
Thanks in advance
Niels,
Why are you using Adodb wherefore you use interop while there is ADONET.
Here is in my idea a complete sample how to do what you want using ADONET.
http://support.microsoft.com/default...b;EN-US;316934
I hope this helps?
Cor
"Niels" <ni****@hollandridderkerk.nl>
Hi,
I have a Acces Db with one Table. The Table has 4 rows (row 1 & 3 are
integer and 2 & 4 are text).
Now i want to export the Table to an Excel workbook.
the next code i used is working (almost) fine.
///Code
''Create a Recordset from all the records in the Orders table.
Dim sNWind As String
Dim conn As New ADODB.Connection()
Dim rs As ADODB.Recordset
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sNorthwind & ";")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute("Orders", , ADODB.CommandTypeEnum.adCmdTable)
''Create a new workbook in Excel.
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
''Transfer the field names to Row 1 of the worksheet:
''Note: CopyFromRecordset copies only the data and not the field
'' names, so you can transfer the fieldnames by traversing the
'' fields collection.
Dim n As Int32
For n = 1 To rs.Fields.Count
oSheet.Cells(1, n).Value = rs.Fields(n - 1).Name
Next
''Transfer the data to Excel.
oSheet.Range("A2").CopyFromRecordset(rs)
''Save the workbook and quit Excel.
oBook.SaveAs(sSampleFolder & "Book3.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
''Close the connection
rs.Close()
conn.Close()
///Code
There is one thing that the code does not. And that is, copying the
columnproperties(integer, text) to Excel.
Does anyone know how i can acomplish this.
Thanks in advance
Niels,
Why are you using Adodb wherefore you use interop while there is ADONET.
Here is in my idea a complete sample how to do what you want using ADONET.
http://support.microsoft.com/default...b;EN-US;316934
I hope this helps?
Cor
"Niels" <ni****@hollandridderkerk.nl>
Hi,
I have a Acces Db with one Table. The Table has 4 rows (row 1 & 3 are
integer and 2 & 4 are text).
Now i want to export the Table to an Excel workbook.
the next code i used is working (almost) fine.
///Code
''Create a Recordset from all the records in the Orders table.
Dim sNWind As String
Dim conn As New ADODB.Connection()
Dim rs As ADODB.Recordset
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sNorthwind & ";")
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs = conn.Execute("Orders", , ADODB.CommandTypeEnum.adCmdTable)
''Create a new workbook in Excel.
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
''Transfer the field names to Row 1 of the worksheet:
''Note: CopyFromRecordset copies only the data and not the field
'' names, so you can transfer the fieldnames by traversing the
'' fields collection.
Dim n As Int32
For n = 1 To rs.Fields.Count
oSheet.Cells(1, n).Value = rs.Fields(n - 1).Name
Next
''Transfer the data to Excel.
oSheet.Range("A2").CopyFromRecordset(rs)
''Save the workbook and quit Excel.
oBook.SaveAs(sSampleFolder & "Book3.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
''Close the connection
rs.Close()
conn.Close()
///Code
There is one thing that the code does not. And that is, copying the
columnproperties(integer, text) to Excel.
Does anyone know how i can acomplish this.
Thanks in advance
On Thu, 11 Nov 2004 10:23:32 +0100, "Cor Ligthert" <no************@planet.nl> wrote:
¤ Niels,
¤
¤ Why are you using Adodb wherefore you use interop while there is ADONET.
¤
CopyFromRecordset requires an ADO or DAO Recordset object. It doesn''t support ADO.NET.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
这篇关于列类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!