Jump to content

Converting .csv file to .xls file


sonali

Recommended Posts

Hi. I am working on Autolisp in which I have generated one csv file (excel). Now, my task is to convert .csv file into .xls file using Auotlisp itself. But, I don't know what to do. Please help me to get over this. Thank you in advance.

Link to comment
Share on other sites

Thank you all for your reply. Sir, please guide me in how can I import values of csv into xls. The file I am generating (csv) contains coordinates which are saved in different cells. So please help me some more regarding importing those values to xls file to move further in my work.

Link to comment
Share on other sites

Ok, sir I have got one logic. Please tell me that if I want to read the value of a cell in B2 of csv file. Then, I want to write in a cell C3 of xls file. So, please help in terms of code, that what I can do regarding it. Please help me. If I simply get this idea then my whole problem will get solved.

Link to comment
Share on other sites

Sir, it is not working.

Please tell me that if I want to read the value of a cell B2 of csv file. Then, I want to write in a cell C3 of xls file. So, please help in terms of code, that what I can do regarding it. Please help me. If I simply get this idea then my whole problem will get solved. Please please please.

Link to comment
Share on other sites

The Autocad to excel is not one of the simplest things to do, but it is achieveable, if you have no programming skills in say lisp then it will be hard for you. There are so many different ways and combinations of things that people want that there is not just 1 answer. Have a search here and there is a vast amount of examples read the post comments and find one that sounds like it does what you want post its page link here and then we can probably help you.

 

If you have some lisp skill then find "getexcel.lsp" it has a library of functions to and from Autocad.

Link to comment
Share on other sites

Thank you for your response.

 

I request all the giants of autolisp to come forward and help me. It really matters for me.

 

My need is just simple:

1. To read the value from cell B3 of the csv file, and

2. To write that value to cell C3 of xls file.

 

If anyone can do this, then please help me. I badly need this.

Link to comment
Share on other sites

1. To read the value from cell B3 of the csv file, and

2. To write that value to cell C3 of xls file.

 

sorry for interrupting..

hi sonali, do you mean 2 different files :unsure:

read csv write to xls?

 

if your out-put is just acsii text with delimiter, i prefer csv.

it's easier & faster than using xls format which need import type-library.

 

i suggest you post an example data in .csv or output

Link to comment
Share on other sites

Thank you sir, for coming forward to help me.

 

Yes sir, two different file.

Read csv and write it xls.

 

Now I will explain initially what problem I am facing in csv file:

 

1.The data I am getting in csv file, I have to process them by mathematical formulas.

For example, for summation of data availbale in the cell B1 to B4.

i.e. ( =SUM (B1:B4) ).

 

Now, these cannot be done in csv files. These operations can only be performed in xls file.

 

So, after getting the data from particular program, the csv file is generated.

 

Now, what I want to do is to get the data transferred from csv file to xls file. So, that I can process the data available in xls file.

 

So, if whole file can simultaneously be transferred from csv to xls then it will be awesome.

 

Or at least, I am in search of code by which, I can exactly read the value of a perticular cell in csv file. And write that value exactly to the destination cell of the xls file.

Please help me something about it.

 

Here I am attaching my csv and xls file. So, that you can visualize them.

Thank you again.

csv file.csv

xls file.xls

Link to comment
Share on other sites

Your both csv & xls same data?

why not just open csv with Excel, edit or formulas etc..

then Save As xls?

 

cannot be done in csv files. These operations can only be performed in xls file...

 

 

summation can be done in list:

example: from your data.

 

(setq data

'(

"3,5,5"

"5,7,1"

"84,7,7454"

"5454,7,4"

"4,1,48"

"44,7,4"

"5,54,444"

))

 

 

split list as rows

'(("3" "5" "5") ("5" "7" "1") ("84" "7" "7454") ("5454" "7" "4") ("4" "1" "48") ("44" "7" "4") ("5" "54" "444"))

 

Transposed list as columns

'(("3" "5" "84" "5454" "4" "44" "5") ("5" "7" "7" "7" "1" "7" "54") ("5" "1" "7454" "4" "48" "4" "444"))

 

then can use list manipulating functions: nth , car , assoc , cdr , mapcar etc..

 

 

Example:

 

;split list as rows

(setq rows

(mapcar ''((x)(csv$ x)) data))

 

;Transposed list as columns

(setq columns (trp row))

 

;sum for each column (A,B,C)

(_sum columns)

;(5599.0 88.0 7960.0)

 

;sump for each row (1~7)

(_sum rows)

;(13.0 13.0 7545.0 5465.0 53.0 55.0 503.0)

 

 

sub-functions

;transpose : Doug Wilson
(defun trp (x)
(apply 'mapcar (cons 'list x)))

(defun csv$ (str / i l) ;split csv
	(while (setq i (vl-string-search "," str))
	  (setq	l   (cons (substr str 1 i) l)
		str (substr str (+ 2 i) (- (strlen str) i))
		) ;_ end of setq
	  ) ;_ end of while
	(reverse(vl-remove "" (cons str l)))
	)

(defun _sum (lst)
(mapcar ''((x)(apply '+ (mapcar 'atof x))) lst))

Edited by hanhphuc
fixed error argument
Link to comment
Share on other sites

Thnak you sir, for your reply.

 

But, these summation is just an example, I have to go for multiple mathematical operations. And I have to do it with autolisp without opening csv file.

 

So, what I need is simple:

 

How can I read the value specific cell B4 of csv file available ? If I get this answer then I can move forward for writing Xls. Please help me sir.

Link to comment
Share on other sites

Thnak you sir, for your reply.

 

But, these summation is just an example, I have to go for multiple mathematical operations. And I have to do it with autolisp without opening csv file.

 

So, what I need is simple:

 

How can I read the value specific cell B4 of csv file available ? If I get this answer then I can move forward for writing Xls. Please help me sir.

 

Maybe you overlooked the advise by BIGAL at post#10 :)

what he mentioned was getexcel.lsp

read the comments with usage, putcell is one of the functions.

perhaps this is what you are looking for?

 

;;example function:

;PUTCELL

 

; PutCell - Put values into Excel cells

; Syntax: (PutCell StartCell$ Data$) or (PutCell StartCell$ DataList@)

; Example: (PutCell "A1" (list "GP093" 58.5 17 "Base" "3'-6 1/4\""))

Link to comment
Share on other sites

ok a solution inside excel you have VBA so could do all the reading of the csv file and maths involved and the "put" the answer into cell b23. Same with lisp. I think the problem here is not us writing something but you learning how to program Using Google you can find the sample coding again you can cut and paste code into excel macros. As a reverse you could probably use excel to drive Autocad. hanphuc has provided some examples as start You need to just get on top of taking a variable from Autocad and putting into a cell the maths is easy.

 

there is a CSV to list lisp I use it on iPad now not available but example

 

(3 4 6) (* (nth 0 lst)(nth 1 lst)) = 12

Link to comment
Share on other sites

Thank you very much, to hanhphuc, BIGAL and ReMark for your help. It is finally done. Without you guys, it would never have been possible. Thank you again, god bless you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...