示例,将以下 两个元组分别写入表格中,元组a在第一行,元组b在第二行
a:= [1,2,3]
b:= [4,5,6]
1、读入文件,先判断是否存在,如果存在将内容清空
fileName:='E:/test.csv'
file_exists(fileName, FileExists)
if(FileExists)
delete_file(fileName)
endif
*假如文件不存在,将重新创建一个新的
open_file (fileName, 'append', FileHandle)
2、将元组a、b中的内容按照顺序依次写入表中
for Index := 0 to |a|-1 by 1
fwrite_string (FileHandle, a[Index] +',')
endfor
*换行
fwrite_string (FileHandle, '\n') 或者 fnew_line (FileHandle)
for Index := 0 to |b|-1 by 1
fwrite_string (FileHandle, b[Index] +',')
endfor
close_file(FileHandle)
博客介绍了使用Halcon将两个元组写入CSV文件的方法。先判断文件是否存在,若存在则清空内容,不存在则创建新文件。然后依次将元组a和b中的内容按顺序写入文件,最后关闭文件。
706





