Re: saving Excel data as a file to read in program
Derek Parnell wrote:
> sixs wrote:
>>I want to read data that is in an Excel spreadsheet. I saved it as a text
>>file. I then open the file and then use the gets command to access a line
>>of data.the data . I try to get the length of the line and don't seem to get
>>a real length.
> Here is the type of code you need to read text lines. This function
> below reads in an entire text file into a sequence, which you
> can then process one line at a time.
Excel saves text files with CR *and* NL.
Might I suggest changing the routine as follows?
global function ReadTextFile(sequence pFileName)
sequence lLines
object lNextLine
integer fh
lLines = {}
fh = open(pFileName, "r")
if fh = -1 then
return -1
end if
lNextLine = gets(fh)
while sequence(lNextLine) do
-- if lNextLine[length(lNextLine)] = '\n' then
-- Don't include any trailing newline.
-- lLines = append(lLines, lNextLine[1..length(lNextLine)-1])
-- else
-- lLines = append(lLines, lNextLine)
-- end if
--******************** Added CW 9/9/4 ******************
while lNextLine[length(lNextLine)] = '\n' or
lNextLine[length(lNextLine)] = '\r' do
lNextLine = lNextLine[1..length(lNextLine)-1]
end while
lLines = append(lLines, lNextLine)
--******************************************************
lNextLine = gets(fh)
end while
close(fh)
return lLines
end function
--
Craig
|
Not Categorized, Please Help
|
|