Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I read Excel files from QBASIC? 1

Status
Not open for further replies.

markh999

Programmer
Aug 4, 2003
10
0
0
GB
I need to read an Excel spreadsheet from my Qbasic program (the speadsheet is just lots of rows of normal data - numbers and text). I have tried various 'save as' options from Excel (e.g. CSV (comma delimited)) to try and get it to a format that Qbasic understands but all I get is 'bad file name' when I try to open the file from Qbasic.

Any help much appreciated.

 
Excel files are so complicated that I don't think you could decode them, you have to deal with things like spacing, formulas, formatting, it would be incredibly difficult. It would be much easier to build your own spreadsheet program.

 
Markh999:

1) If you 'SAVED AS' a CVS file, QB will absolutely be able to read it.

2) Only help I can give you (since you didn't post any code to review) is to save the CVS in the 8.3 format and don't use LFN...QB can't understand it since it wasn't designed with that in mind; this includes directories as well.

3) Post the code you wrote so we can all GUIDE you to a solution.

--MiggyD
 
Thanks to both of you for the response. Here is some more info that may help (as I'm still getting problems).

I save my Excel spreadsheet as as 'CSV (comma delimited)' file and called it 'football results csv'. It then saved the file as the name 'football results csv.csv'

In my QBASIC program I have the following code

OPEN "football results csv" FOR INPUT AS #1

and it says File not found.

I have tried OPEN "football results csv.csv" FOR INPUT #1 and it says Bad file name.

I've tried putting a path, so OPEN "c:\Qbasic\football results csv" as INPUT #1 and I get File not found again.

So its looks like its not even detecting the file, let alone trying to interpret the data !

I'm sure its something simple but its beaten me. Any further help would be very gratefully received. If I can post any more info please let me know.

Thanks again.

 
As I said in paragraph #2 above: "...save the CVS in the 8.3 format and don't use LFN...". But you are still using the Long File Nameing [LFN] format. Please re-read the above first then continue with the rest of this response. You need to do ONE of the following TWO options:
[sup]NOTE: This is considering that the CVS file is saved/located in the same directory as your QB.[/sup]


OPTION 1 -> use 8.3 in your QB code. In other words, change the following in your code:

FROM:
OPEN "football results csv.csv" FOR INPUT AS #1
{see the LFN format you are using?}

TO:
OPEN "[red]footba~1.csv[/red]" FOR INPUT AS #1
{see the "~1"?}
{The length of 'FOOTBA~1' = 8}
{The extension of 'CVS' = 3}
{see the 8.3 format in my revision?}



OPTION 2 -> "Save/Save As" the data in the 8.3 file nameing format already for easier access with your QB program. In other words;

->(in Excel)<- do the following
>Click FILE
>Click SAVE AS
>Type FOOTBALL in 'file name' only [note: this word is 8 characters]
>Change 'Save Type' to CVS [note: this makes the .3 characters]
>Click SAVE button
{see how this adds up??}
[tt]{F O O T B A L L . C V S}
{^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^}
{| | | | | | | | | | |}
{1 2 3 4 5 6 7 [red]8 .[/red] 1 2 [red]3[/red]} = 8.3[/tt]

->(in QB)<- change the following:
FROM:
OPEN &quot;football results csv.csv&quot; FOR INPUT AS #1
{see the LFN format you are using?}

TO:
OPEN &quot;[red]football.csv[/red]&quot; FOR INPUT AS #1
{see the 8.3 format in my revision?}



Hope this clarifies it for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top