读取csv文件行
大家好,我理解为我们可以使用的表格读取csv行
(setq csvline(读取行f))
这从第一行开始
我有点迷路/找不到如何阅读特定的一行,比如说第5行
也可以堆叠输出。
(定义c:csvin()
(setq f(打开“D:/03扫描/test.csv”“r”);打开csv文件
(setq csvdata(读取行f));读取第一行
(命令“text”(getpoint)”“csvdata);选择要插入的位置
)
当做
特雷凡123 或者类似于:
(repeat 5 (setq csvline (read-line f)))
或者,使用我的读取CSV功能:
(setq csvline (nth 4 (LM:readcsv "YourFilename.csv")))
注意,后者将返回单元格值列表,而前者将返回字符串。 李和往常一样回答得很好,特别是LM:Readcsv。
(defun c:csvin ( / f x csvdata)
(setq f (open "D:/03-Scans/test.csv" "r")) ;Open csv file
(setq x (getint "Enter line number to read"))
(repeat x (setq csvline (read-line f)))
(command "text" (getpoint) "" "" csvdata) ;Pick place to insert
(close F) ; good idea to close file
)
(defun c:csvin ( / f x csvdata)
(while (setq x (getint "Enter line number to read"))
(setq f (open "D:/03-Scans/test.csv" "r")) ;Open csv file
(repeat x (setq csvline (read-line f)))
(command "text" (getpoint) "" "" csvdata) ;Pick place to insert
(close F) ; good idea to close file
)
)
更好地使用readcsv
(defun c:csvinm ( / f x csvlines csvdata)
(setq fname (getfiled "Select a csv File" "D:/03-Scans/" "csv" 4))
(while (setq x (getint "Enter line number to read"))
(setq f (open fname "r"))
(repeatx
(setq csvlines(LM:csv->lst (read-line F) "," 1))
)
(close F)
(setq y 0)
(setq textans "")
(repeat (length csvlines)
(setq textans (strcat (nth y csvlines) " " textans))
(setq y (+ y 1))
)
(command "text" (getpoint) "" textans)
)
(princ)
)
(c:csvinm)
请阅读代码发布指南,并将您的代码包含在代码标签中。
Your Code Here=
Your Code Here 谢谢你的帮助,这位beginer又学到了一些东西
BIGAL,请注意,我的LM:readcsv函数接受文件名(字符串)参数,而不是文件描述符。 哎呀,谢谢李没有测试,所以重写并测试了更新的代码。 抱歉,还是搞砸了/试图理解
(defun c:csvin ( iSR / f x csvdata)
(while (setq iSR (getint "Rating :- "))
(if (= iSR 150) ; where Rating is 150#
(progn
(setq f (open "D:/03-Scans/150.csv" "r")) ;Open 150 csv file
那么,如果我需要它来打开一个特定的文件,我可以这样做吗?
然后尝试获取下一个输入,将行设置为读取 我重写了上面发布的代码,包括一个选择CSV。你现在是说你想看每一行并决定是否将其添加到表中? 请容忍我,因为我不完全理解,通常只是把口吃拼凑在一起。
所以我有一个新的攻击线。
它使用DCL文件(由Terry Miller负责),然后慢慢取出我所看到的可能不需要的内容,并补充道。
因此lisp将询问评分和项目
“评级”将作为文件
“项”是文件中需要放置在图形中的行
也许我应该使用excel工作表,但我看到的lisps无法理解到底发生了什么,主要是因为它们是用v.basic编写的。
所以我的理解是csv文件或记事本
很抱歉搞砸了
希望这能解释得一清二楚
I按下。DCL
I按下。LSP
页:
[1]
2