我试图逐个单元格输入数据到CSV文件,但是当我打开它时,我得到CSV文件a列中的所有内容,以","分隔。(逗号).
我正在用下面的方法尝试:
oExcel = CREATEOBJECT("Excel.Application")
oWorkBook=oExcel.Workbooks.Open("c:planilla.csv")
oExcel.application.Cells(1,1).Value = "StockCode"
oExcel.application.Cells(1,2).Value = "In-Stock"
oExcel.application.Cells(1,3).Value = "Kit"
oWorkbook.Save()
oWorkbook.Close()
oExcel.Quit()
RELEASE oWorkbook
RELEASE oExcel
打开CSV文档时,输出在单个单元格(列a)中,如下所示:StockCode, In-Stock, Kit.
我希望你能帮助我,regards
首先,我不明白为什么你要尝试使用Excel对象来创建csv文件。为什么不直接用VFP中的命令创建一个csv文件呢?
其次,我确实尝试了您的示例,它确实创建了一个单元格,其中3个项目由2个制表符分隔。但是,如果我在xlsx文件(实际的Excel工作簿)上做同样的事情,您的示例就可以工作了。我不认为Excel办公自动化对象是用来处理CSV文件的。
如果您需要输出到CSV文件,您可以使用VFP命令来完成,而不必创建Excel对象。
看到你的评论了…试着在VFP中运行:
* create cursor and some records
CREATE CURSOR test (nid i, stockcode c(10),instock i,kit c(20), lincsv l)
INSERT INTO test (nid,stockcode,instock,kit,lincsv) VALUES (1,"SC-001",10,"kit001",.f.)
INSERT INTO test (nid,stockcode,instock,kit,lincsv) VALUES (2,"SC-010",0,"kit003",.f.)
INSERT INTO test (nid,stockcode,instock,kit,lincsv) VALUES (3,"SC-200",5,"kit010",.f.)
* call function to add records to csv file
=AddToCSV()
* insert a couple more records to cursor
INSERT INTO test (nid,stockcode,instock,kit,lincsv) VALUES (4,"SC-201",6,"kit001",.f.)
INSERT INTO test (nid,stockcode,instock,kit,lincsv) VALUES (5,"SC-005",520,"kit099",.f.)
* call function again to add new records to existing csv file
=AddToCSV()
FUNCTION AddToCSV
* open csv file (create if it doesn't exist, add to existing)
SET ALTERNATE TO c:tempplanilla.csv ADDITIVE
SET ALTERNATE ON
SCAN FOR NOT linCSV
?? stockcode + ","
?? instock
?? "," + kit
replace lincsv WITH .t.
?
ENDSCAN
SET ALTERNATE OFF
SET ALTERNATE TO
RETURN