如何将数据从CSV文件写入Exel文件VB6 [英] How to write data from CSV file to Exel file VB6

查看:145
本文介绍了如何将数据从CSV文件写入Exel文件VB6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Exel文件2003,并且在此exel文件上有一个按钮A.当单击按钮A时,将显示一个打开的对话框,以选择CSV文件并进行读取.将CSV文件的数据写入名称为KQ.xls的exel文件中,并且与CSV文件位于同一位置.将CSV文件的每5行数据写入一张exel文件中,并且工作表名称为KQ + i(i增加每读5行之后)

我只能使用CSV文件,但不能写入exel文件.
你能帮我吗?

感谢您的进步.

I have Exel file 2003 and one button A onside this exel file. when click on button A, A open dialog displayed to choose CSV file and read it. The data of CSV file was write to exel file with name KQ.xls at the same position with CSV file.Each 5 line data of CSV file was written to one Sheet of exel file and with Sheet name is KQ + i (i is increased after each 5 line was read)

I only can CSV file But i can not write to exel file.
Could you help me, please?

Thanks for advance.

推荐答案

您不能直接写入excel文件.相反,您必须使用互操作从VB6打开excel文件.以下是一些如何使用excel的示例:
- http://www.developerfusion.com/code/5322/working- with-excel-files-using-vb6/ [ http://forums.devx.com/showthread.php?t=142557 [ ^ ]

还要注意,您必须将对excel对象库的引用添加到项目中.请参阅: http://support.microsoft.com/kb/219151 [
You cannot directly write to the excel file. Instead you have to open the excel file from VB6 using interop. Here are few examples how to work with the excel:
- http://www.developerfusion.com/code/5322/working-with-excel-files-using-vb6/[^]
- http://forums.devx.com/showthread.php?t=142557[^]

Also note that you have to add the reference to the excel object library into your project. See: http://support.microsoft.com/kb/219151[^] (this contains a small example also)


这里有一些示例代码和可能会帮助您的链接:

Here you have some example code and a link that might help you out:

Dim ExcelApp As Excel.Application
Dim ExcelWorkbook as Excel.Workbook
Dim ExcelSheet as Excel.Worksheet
Dim DataArray(5, nRowValues) as variant
Dim SheetIndex as Long

SheetIndex = 1

Set ExcelApp As New Excel.Application 
Set ExcelWorkbook = ExcelApp.Workbooks.Add

'' Write the code that will fill the DataArray

'' Write the values of the 5 lines to a new sheet
ExcelSheet = ExcelWorkbook.Worksheets.Add
ExcelSheet.Name = "KQ" & CStr(SheetIndex)
ExcelSheet.Range("A1").Value = DataArray

ExcelWorkbook.Close False, "c:\filename.xls"
ExcelApp.Quit

Set ExcelWorkbook = Nothing
Set ExcelApp = Nothing




有关打开的对话框的更多信息:
http://www.mrexcel.com/archive/VBA/19208.html [ ^ ]

祝你好运!




More info on the open dialog box:
http://www.mrexcel.com/archive/VBA/19208.html[^]

Good luck!


我是否必须打开exel应用程序(将ExcelApp设置为New Excel.Application)?
因为我正在研究Exel
Do I have to open exel application(Set ExcelApp As New Excel.Application)?
because I am working on Exel


这篇关于如何将数据从CSV文件写入Exel文件VB6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆