Category : Lotus and other Spreadsheets
Archive   : WRT123.ZIP
Filename : WRT123.C

 
Output of file : WRT123.C contained in archive : WRT123.ZIP
/*------------------- file: WRT123.DOC -----------------------------*/

The infromation for this came from a book entitled
WORKSHEET
FILE FORMAT
from Lotus(tm)
First Printing 1984.

It does not have a Library of Congress number or any
thing like that, it has LOTUS PART NUMBER 06010 on it.

We bought the book from lotus quite a while back.
I forget the cost.

There's a little DEMO program at the end of this file, Try it out.

These routines allow you to write data to a Lotus 1-2-3 file, (.WKS)
they are by nature, very limited.

All you can do is write, LABELS, FLOATs, INTEGERS, and Name Ranges
that's it.

It does not support WRITING formulas, graphics, tables, data base
things, print ranges, print settings, etc, etc

Most of these things could easily be added with the execption of the
formulas, that gets a little bit complicated

I wrote these functions so that I could transfer data from my data
acquistion program directly into Lotus 1-2-3 and Symphony, and name
a few ranges, and put neat titles in various places.

Latter, I will add most of the other things needed with the execption
of FORMULAS... or.... maybe formulas will be included...

There is a very imporant thing you must watch out for, these functions
do not check for OUT OF BOUNDS, 1-2-3 Vrs 1A only has 2048 rows, but
you could easily put data in row 3000 for or column 400, if you do, that's
your mistake and I would expect 123 to blow up in your face. You could
add a 'OUT OF BOUNDS' check if you want to.

There is something you should note, I don't know if it will cause problems
or not... If you where to put the number 1 in cell A1 and save the file
with 123, your file will be very large comparied to the one this program
generates. I belive 123 saves EVERYTHING UNDER THE SUN thus, the bigger
file. I hope 123 does not blow up, it has not for me and I have been using
these functions for about 6 to 8 months with no problems (tested with
123 vrs 2.00 only)

You can goof up and put two things in the same cell location, it seems
that 123 will keep the last one, and not blow up.. but you should not do
this for your own safty.

These functions are copy right 1987 by Duane Ellis,
you can use them all you want, you can change them modify them
or even distrubute them I don't care. But, please if you are
going to pass them out, add some things to them and don't cut my name out...

Yes, you can use these with out any royalties, with the exception of
if you do make mega bucks on them, I ask that you send some money
to your local public tv station of public radio station, and if some
body makes REAL MEGA BUCKS and sends MEGA BUCKS to them, may be those
guys will stop the constant begging for money.


These functions could defintatly be spead up, but for clarity
reasons, i don't use things like copy memory functions, just
simple ones


/*------------------- file: 123.H -----------------------------*/
/*
Every thing in a 123 file has a header like this,
the REC_HDR.len is how many bytes follow the header
in the data block. NOTE: THERE MAY BE NO DATA BLOCK
if that's the case, then len is ZERO!
*/

typedef struct { /* Lotus 123 Record Header */
int type; /* Record Type */
int len; /* Data Block Length */
} REC_HDR;


REC_HDR _123_hdr; /* The Header you want to use.. */

char _123_Data[1024]; /* The Data block that follows the header */

#define HIGH(x) ((x>>8) & 0x0ff)
#define LOW(x) ( x & 0x0ff)

/*------------------- file: WRT123.C -----------------------------*/


#include
#include
#include "123.h"

/* Replace this with your compilers ERROR list... */
/* typicaly the string that corisponds to the errno */
#define ERROR_TEXT (sys_errlist[errno])

/*
* I assume you know something about Lotus 1-2-3,
*
* The ROW and COL for each of these functions is 0 to XXXX
* Cell A1, is Row 0, Col 0, Cell Z44 is Row 25, Col 44, etc...
*
*/

start_file(fp) /* This is a START OF FILE marker */
FILE *fp;
{
_123_hdr.type = 0;
_123_hdr.len = 2;
_123_Data[0] = 0x04; /* this is a 123 file... */
_123_Data[1] = 0x04;
return wrt_record( fp );
}

end_file(fp) /* Put the END OF FILE marker in the file */
FILE *fp;
{
_123_hdr.type = 1; /* End of File Marker */
_123_hdr.len = 0;
return wrt_record( fp );
}


integer( fp, row, col, value ) /* insert an INTEGER at Row, Col */
FILE *fp;
int row, col;
int value;
{
_123_hdr.type = 13; /* this is a INTEGER */
_123_hdr.len = 7;

_123_Data[0] = 0xff;
_123_Data[1] = LOW(col);
_123_Data[2] = HIGH(col);
_123_Data[3] = LOW(row);
_123_Data[4] = HIGH(row);
_123_Data[5] = LOW(value);
_123_Data[6] = HIGH(value);

return wrt_record( fp );
}


number( fp, row, col, value ) /* put a double in the sheet */
FILE *fp;
int row, col;
double value;
{
union {
double value;
char bytes[8];
} data;

_123_hdr.type = 14; /* this is a DOUBLE */
_123_hdr.len = 13;

_123_Data[ 0] = 0xff;
_123_Data[ 1] = LOW(col);
_123_Data[ 2] = HIGH(col);
_123_Data[ 3] = LOW(row);
_123_Data[ 4] = HIGH(row);

/* this is how AZTEC (MANX) floats line up, AZTEC uses the IEEE floats
(IEEE is the same as the 80x87 uses), same as Lotus 1-2-3

other compilers may differ, so if it don't work... try another order
*/

data.value = value;

_123_Data[ 5] = data.bytes[0];
_123_Data[ 6] = data.bytes[1];
_123_Data[ 7] = data.bytes[2];
_123_Data[ 8] = data.bytes[3];
_123_Data[ 9] = data.bytes[4];
_123_Data[10] = data.bytes[5];
_123_Data[11] = data.bytes[6];
_123_Data[12] = data.bytes[7];

return wrt_record( fp );
}



name( fp, row1, col1, row2, col2, name ) /* Specify a NAMEed Range */
FILE *fp;
int row1, col1, row2, col2;
char *name; /* AT MOST 15 CHARICTORS!!!!!!! */
{
int x;

_123_hdr.type = 11;
_123_hdr.len = 24;

for( x = 0 ; x < 16 ; x++ )
_123_Data[x] = '\0'; /* NULL The Name */

for( x = 0 ; x < 16 ; x++ )
if( name[x] )
_123_Data[x] = toupper(name[x]);
else
break;

_123_Data[15] = '\0'; /* Insure NULL TERMINATED STRING! */

_123_Data[16] = LOW(col1);
_123_Data[17] = HIGH(col1);
_123_Data[18] = LOW(row1);
_123_Data[19] = HIGH(row1);

_123_Data[20] = LOW(col2);
_123_Data[21] = HIGH(col2);
_123_Data[22] = LOW(row2);
_123_Data[23] = HIGH(row2);

return wrt_record( fp );
}


label( fp, row, col, type, string )
FILE *fp;
int row, col;
char type; /* label type, ', ", or \ see 123 manual... */
char *string;
{
register int len;
register int x;

len = strlen(string);

_123_hdr.type = 15; /* this is a LABEL */
_123_hdr.len = 5+1+len+1; /*
format + Row + Col = 5
label prefix = 1
the string = len
the NULL = 1
*/

_123_Data[0] = 0x0f5; /* format Default */
_123_Data[1] = LOW(col);
_123_Data[2] = HIGH(col);
_123_Data[3] = LOW(row);
_123_Data[4] = HIGH(row);
_123_Data[5] = type; /* Left, Center, Right */
/* type is standard 123 label prefix */
/* ' is Left justify */

strcpy( &(_123_Data[6]), string );

return wrt_record( fp );

}

static
wrt_record( fp )
FILE *fp;
{
register int x;
register int y;

x=fwrite( &_123_hdr, sizeof( REC_HDR ), 1, fp );
if( x != 1 ){
if( errno )
fprintf(stderr, "Write Error %s\n", ERROR_TEXT );
else
fprintf(stderr, "Write Error Disk Full?\n");
exit(1);
}

y = _123_hdr.len;

if( y ){
x = fwrite( _123_Data, sizeof( char ), y, fp );
if( x != y ){
if( errno )
fprintf(stderr, "Write Error %s\n", ERROR_TEXT );
else
fprintf(stderr, "Write Error Disk Full?\n");
exit(1);
}
}

return 0;
}


#ifdef DEMO

main()
{
FILE *out, *fopen();
int x,y;

out = fopen( "myfile.wks", "w" );

if( !out ){
fprintf(stderr, "Can't Open Output, err is %s\n", ERROR_TEXT );
exit(1);
}

start_file( out );

label( out, 0, 0, '\'', "Multiplication Table" );
for( x = 0 ; x < 10 ; x++ ){
integer( out, 1, x+2, x );
integer( out, x+2, 0, x );
for( y = 0 ; y < 10 ; y++ )
integer( out, x+2, y+2, x * y );
}

name( out, 2, 2, 11, 11, "X_Table" );

/* by now you should be able to understand how to use the
number() routine... it's the same idea as integer() */

end_file(out);

fclose(out);

printf("Done.....\n\n");

}

#endif


  3 Responses to “Category : Lotus and other Spreadsheets
Archive   : WRT123.ZIP
Filename : WRT123.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/