home *** CD-ROM | disk | FTP | other *** search
- {$N+}
- {$E+}
-
- { This Unit will help you create simple Lotus Worksheet files (WKS).
- To use this unit your main program file must be compiled with these
- compiler directives $N+ and $E+. This allows Turpo Pascal to write
- to the file the IEEE reals that 1-2-3 expects to find in its WKS files.
-
-
- Written by Cody Laird, Atlanta, Ga. (CompuServe# 70033,765)
-
- Many thanks to Jeff Walden, Author of "File Formats For Popular PC Software",
- without his book this would not have been possible.
-
-
- To use this unit correctly you must follow the following procedure calling
- order to ensure that you create a file that Lotus can read:
-
- 1) Call open_wks_file(Lotus_File_Name,Version)
-
- were Lotus_File_Name is the full file name
- (example: C:\TURBO\TEMP123.WKS ), and Version
- is the number that corresponds to the following numbers:
-
- 1028 = Version 1A and 1.0
- 1030 = Version 2.0
-
- 2) Set up all of the column widths (if you want to define any other than
- the default width of 9) by calling this sequence for each column:
-
- a) set_column_width(c,w);
- b) write_lotus_rec;
-
- Then once your finished setting up all of the column widths, you
- MUST call
-
- write_required_records;
-
- This writes 16 required records for the file. There all are default
- values and should only be changes if you have a copy of the book
- mentioned above. If you do not call this procedure Lotus will give
- you an error message saying that part of the file is missing and
- will not load any of the data.
-
-
- 3) Then repeat the following calls until your finished writing you data:
-
- a) set_????_fields(parameters)
- b) write_lotus_rec;
-
- were ???? equals the basic type your placing in the cell, and
- the parameters are the associated list for that type, as described
- below.
-
- 4) Call close_wks_file to close the Lotus WKS file. Your finished.
-
-
- ********************************************************************
- IMPORTANT NOTE: All of the records written to the file must have the
- Least Significant Byte FIRST. This includes OpCodes,
- Length Descriptors, and Data (except for characters)
-
- This means that when you pass parameters to any of
- the set_????_fields procedures you must do so as
- follows:
-
- Example: set_blank_fields(SWAP(c),SWAP(r),f);
-
- This only applies if the c or r varialbles are NOT
- hexadecimal constants. If you do not call SWAP(var)
- then your column or row numbers will be written in the
- wrong order for the file.
-
- I do not understand why this happens but it does.
- This generally applies to all numbers that are passed
- to the procedures that are of type WORD.
- (ALL COLUMN and ROW NUMBERS, especially)
-
- *********************************************************************
-
- Notes to the set_????_fields procedures:
-
- In the following procedures, the following parameters have these
- meanings:
-
- c = the column number (0 = A, 1 = B, 2 = C, etc...)
- r = the row number (0 = 1, 1 = 2, 2 = 3, etc...)
- v = the value for the cell specified by (c,r)
- f = the format for the cell (date,currency,percent,general, etc...)
- s = the text for that cell (Label = Text)
- lf= the alignment character for the text (Left,Centered,Right)
- w = the width of the cell (1 to 255)
-
- These are specific to the set_window_fields procedure:
-
- cw = column width
- co = columns on the screen
- ro = rows on the screen
- lc = leftmost column
- tr = top row
- ntc = number of title columns
- ntr = number of title rows
- ltc = left title column
- ttr = top title column
- bc = border column width
- br = border row width
- ww = window width
-
- Lotus_File_Name = the name of the file your creating
- version = the version of the worksheet file (1028 or 1030)
-
- These are the set_????_fields procedures:
-
- 1) set_real_fields(c,r:word;v:double;f:byte); For REAL numbers
-
- 2) set_int_fields(c,r:word;v:integer;f:byte); For INTEGER numbers
-
- 3) set_date_fields(c,r:word;date:str8); For DATES (str8 = mm-dy-yr)
-
- 4) set_label_fields(c,r:word;s:string;f:byte;lf:char); For LABELS, TEXT
-
- 5) set_column_width(c:word;w:byte); For setting the column widths
-
- 6) set_blank_fields(c,r:word;f:byte); For setting up BLANK cells
-
- 7) procedure set_window_fields
- (c,r:word;f:byte;cw,co,ro,lc,tr,ntc,ntr,ltc,ttr,bcbr,ww:word);
-
- For setting up Window1
-
- *********************************************************************}
-
-
- unit Unit123;
- interface
- uses crt,dos;
-
- const
- Default_Format = 127; {01111111 = Special, Default}
- Date_Format = 114; {01110010 = Special, dy-mth-yr format}
- Currency_Format = 34; {00100010 = Currency, 2 decimal places}
- Percent_Format = 50; {00110010 = Percent, 2 decimal places}
- Text_Format = 117; {01110101 = Special, Text}
- General_Format = 113; {01110001 = Special, General}
-
- {Add 128 to the above numbers to protect a cell}
-
- Label_Left = #39; {'}
- Label_Center = #94; {^}
- Label_Right = #34; {"}
-
- Label_Length = 32; {see end of file on limits on these two lengths}
- Formula_Length = 30;
-
-
- type
-
- BOF_Rec = record
- Ver_Lo : byte;
- Ver_Hi : byte; {Least significant byte FIRST!!}
- end;
-
- EOF_Rec = record {0 bytes end of file record}
- end;
-
- Blank_Rec = record
- Fmt : byte;
- Col_Lo : byte;
- Col_Hi : byte;
- {only for formatted blank cells,
- empty cells are not saved by Lotus}
- Row_Lo : byte;
- Row_Hi : byte;
- end;
-
- ColW1_Rec = record
- CNum_Lo : byte;
- CNum_Hi : byte;
- Cwth : byte;
- end;
-
- Byte_Rec = record
- Byt : byte;
- end;
-
- Range_Rec = record
- S_Col_Lo : byte;
- S_Col_Hi : byte;
- S_Row_Lo : byte;
- S_Row_Hi : byte;
- E_Col_Lo : byte;
- E_Col_Hi : byte;
- E_Row_Lo : byte;
- E_Row_Hi : byte;
- end;
-
- Int_Rec = record
- Fmt : byte; {Format for the cell}
- Col_Lo : byte;
- Col_Hi : byte; {Column number for the cell}
- Row_Lo : byte;
- Row_Hi : byte; {Row number for the cell}
- Val : integer; {Value that goes in the cell}
- end;
-
- Real_Rec = record
- Fmt : byte;
- Col_Lo : byte;
- Col_Hi : byte;
- Row_Lo : byte;
- Row_Hi : byte;
- Val : double; {must use the $N+,$E+ compiler directives}
- end;
-
- Label_Rec = record
- Fmt : byte;
- Col_Lo : byte;
- Col_Hi : byte;
- Row_Lo : byte;
- Row_Hi : byte;
- Val : array[0..Label_Length] of char;
- {245 is the maximum length of a label string,
- this is variable, change as needed}
- end;
-
- Formula_Rec = record
- Fmt : byte;
- Col_Lo : byte;
- Col_Hi : byte;
- Row_Lo : byte;
- Row_Hi : byte;
- Val : double;
- F_Size_Lo : byte;
- F_Size_Hi : byte;
- FArray : array[0..Formula_Length] of byte;
- end;
-
- Window_Rec = record
- Cur_Col_Lo : byte;
- Cur_Col_Hi : byte; {current cursor column}
- Cur_Row_Lo : byte;
- Cur_Row_Hi : byte; {current cursor row}
- Fmt : byte; {cell format}
- Null1 : byte; {unused but must be = to 0}
- Col_Wth_Lo : byte; {column width}
- Col_Wth_Hi : byte; {column width}
- Col_On_Lo : byte; {number of columns on screen}
- Col_On_Hi : byte; {number of columns on screen}
- Row_On_Lo : byte; {number of rows on screen}
- Row_On_Hi : byte; {number of rows on screen}
- L_Col_Lo : byte; {leftmost column}
- L_Col_Hi : byte; {leftmost column}
- T_Row_Lo : byte; {top row}
- T_Row_Hi : byte; {top row}
- NT_Col_Lo : byte; {number of title columns}
- NT_Col_Hi : byte; {number of title columns}
- NT_Row_Lo : byte; {number of title rows}
- NT_Row_Hi : byte; {number of title rows}
- LT_Col_Lo : byte; {left title column}
- LT_Col_Hi : byte; {left title column}
- TT_Row_Lo : byte; {top title row}
- TT_Row_Hi : byte; {top title row}
- BW_Col_Lo : byte; {border width column}
- BW_Col_Hi : byte; {border width column}
- BW_Row_Lo : byte; {border width row}
- BW_Row_Hi : byte; {border width row}
- Wdw_Wth_Lo : byte; {window width}
- Wdw_Wth_Hi : byte; {window width}
- Null2 : byte; {unused but must be = to 0}
- end;
-
- {Required Records}
- Graph_Rec = record
- temp : array[0..436] of byte;
- end;
- Table_Rec = record
- Fmt : byte;
- temp : array[1..24] of byte;
- end;
- QRange_Rec = record
- temp : array[0..23] of byte;
- Fmt : byte;
- end;
- HRange_Title_Rec = record
- temp : array[0..15] of byte;
- end;
- KRange_Rec = record
- temp : array[0..8] of byte;
- end;
- Footer_Header_Rec = record
- temp : array[0..241] of byte;
- end;
- SetUp_Rec = record
- temp : array[0..39] of byte;
- end;
- Margin_Rec = record
- temp : array[0..9] of byte;
- end;
-
-
- Lotus_Rec = record
- OP_Lo : byte;
- OP_Hi : byte; {Least Significant Byte First!}
- Len_Lo : byte;
- Len_Hi : byte;
- end;
-
- Temp_Rec = record
- Hi : byte; {used to cast a word onto}
- Lo : byte;
- end;
-
- str8 = string[8]; {used for date string}
-
- var
- ColNum,
- RowNum : word; {column and row number used globally}
- Lotus_File : File; {untyped file for Blockwrite}
- S : string; {for the Labels or Text}
- Lotus_Cell : Lotus_Rec; {OpCode and Record Length settings for one
- of the following record types:}
- Lotus_Real : Real_Rec;
- Lotus_Int : Int_Rec;
- Lotus_Label : Label_Rec;
- Lotus_Col : ColW1_Rec;
- Lotus_Window : Window_Rec;
- Lotus_Formula : Formula_Rec;
- Lotus_BOF : BOF_Rec;
- Lotus_EOF : EOF_Rec;
- Lotus_Blank : Blank_Rec;
- Lotus_Range : Range_Rec;
-
- {
- Lotus_PRange : Range_Rec;
- Lotus_FRange : Range_Rec; All 8 bytes, same format, handled by one Record
- Lotus_SRange : Range_Rec;
- }
-
- Lotus_Byte : Byte_Rec;
-
- {
- Lotus_CalcC : Byte_Rec;
- Lotus_CalcM : Byte_Rec;
- Lotus_CalcO : Byte_Rec; these are all the same size and can be handled
- Lotus_Split : Byte_Rec; by one set_byte_fields procedure;
- Lotus_Sync : Byte_Rec;
- Lotus_Protect : Byte_Rec;
- Lotus_UnFmt : Byte_Rec;
- }
- Lotus_Table : Table_Rec;
- Lotus_QRange : QRange_Rec;
- Lotus_KRange : KRange_Rec;
- Lotus_HdFt : Footer_Header_Rec;
- Lotus_SetUp : SetUp_Rec;
- Lotus_Margin : Margin_Rec;
- Lotus_HrgTitle : HRange_Title_Rec;
- Lotus_Graph : Graph_Rec;
-
-
-
- BOF_Type, {= $0000; OpCode for the Begining of File record}
- EOF_Type, {= $0100; {OpCode for the End of File record}
- Formula_Type, {= $1000; {OpCode for the Formula record}
- CalcM_Type, {= $0200; {OpCode for the Calcmode record}
- CalcO_Type, {= $0300; {OpCode for the Calcorder record}
- Split_Type, {= $0400; {OpCode for the Split record}
- Sync_Type, {= $0500; {OpCode for the Sync record}
- Range_Type, {= $0600; {OpCode for the Range record}
- Window_Type, {= $0700; {OpCode for the Window record}
- ColW1_Type, {= $0800; {OpCode for the Column width record}
- Blank_Type, {= $0C00; {OpCode for the Blank record}
- Integer_Type, {= $0D00; {OpCode for the integer record}
- Real_Type, {= $0E00; {OpCode for the real record}
- Label_Type, {= $0F00}
- Table_Type, {= $1800}
- QRange_Type, {= $1900}
- PRange_Type, {= $1A00}
- SRange_Type, {= $1B00}
- FRange_Type, {= $1C00}
- KRange_Type, {= $1D00}
- HRange_Type, {= $2000}
- KRange2_Type, {= $2300}
- Protect_Type, {= $2400}
- Footer_Type, {= $2500}
- Header_Type, {= $2600}
- Setup_Type, {= $2700}
- Margin_Type, {= $2800}
- LabelFmt_Type, {= $2900}
- Title_Type, {= $2A00}
- Graph_Type, {= $2D00}
- CalcC_Type, {= $2F00; {OpCode for the Calc count record}
- UnFormat_Type:word; {= $3000}
-
- BOF_Len, {= $0200; {Length of the Begining of File record}
- EOF_Len, {= $0000; {Length of the End of File record}
- CalcM_Len, {= $0100; {Length of the Calcmode record}
- CalcO_Len, {= $0100; {Length of the Calcorder record}
- Split_Len, {= $0100; {Length of the Split record}
- Sync_Len, {= $0100; {Length of the Sync record}
- Range_Len, {= $0800; {Length of the Range record}
- Window_Len, {= $1F00; {Length of the Window record}
- ColW1_Len, {= $0300; {Length of the Column width record}
- Blank_Len, {= $0500; {Length of the Blank record}
- Integer_Len, {= $0700; {Length of the integer record}
- Real_Len, {= $0D00; {Length of the real record}
- Label_Len, {= Label_Length}
- Formula_Len, {= Formula_Length}
- CalcC_Len, {= $0100; {Length of the Calc Count Record}
- Table_Len,
- QRange_Len,
- PRange_Len,
- SRange_Len,
- FRange_Len,
- KRange_Len, {for these lengths see the end of this unit}
- KRange2_Len,
- Protec_Len,
- Footer_Len, {Header_Len = same}
- Setup_Len,
- Margin_Len,
- LabelFmt_Len,
- Title_Len, {HRange = same}
- Graph_Len : word;
-
- procedure open_wks_file
- (Lotus_File_Name:PathStr;version,NumofCol,NumofRow:word); {call first}
-
- procedure write_required_records; {call after setting up the column widths}
-
- procedure close_wks_file; {call last}
-
-
- {call as many of these as required AFTER calling write_required_records}
-
- procedure set_real_fields(c,r:word;v:double;f:byte);
- procedure set_int_fields(c,r:word;v:integer;f:byte);
- procedure set_date_fields(c,r:word;date:str8);
- procedure set_label_fields(c,r:word;s:string;f:byte;lf:char);
- procedure set_column_width(c:word;w:byte);
- procedure set_blank_fields(c,r:word;f:byte);
- procedure set_window_fields
- (c,r:word;f:byte;cw,co,ro,lc,tr,ntc,ntr,ltc,ttr,bc,br,ww:word);
- procedure set_byte_fields(OpCode:word);
- procedure set_range_fields(c,r:word);
- procedure write_lotus_rec;
-
- implementation
-
- procedure set_bof_rec(version:word);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(BOF_Type).Lo;
- OP_Hi := Temp_Rec(BOF_Type).Hi;
- Len_Lo := Temp_Rec(BOF_Len).Lo;
- Len_Hi := Temp_Rec(BOF_Len).Hi;
- end;
- with Lotus_BOF do begin
- Ver_Lo := Temp_Rec(version).Lo;
- Ver_Hi := Temp_Rec(version).Hi;
- end;
- end;
-
- procedure set_eof_rec;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(EOF_Type).Lo;
- OP_Hi := Temp_Rec(EOF_Type).Hi;
- Len_Lo := Temp_Rec(EOF_Len).Lo;
- Len_Hi := Temp_Rec(EOF_Len).Hi;
- end;
- end;
-
- function Cal_julian(date:str8):real; {date is in the format mm/dd/yr}
- var ercode:integer;
- mth,yr,day,y1,pv:real;
- begin
- val(copy(date,7,2),yr,ercode); {get the value of the year}
- val(copy(date,4,2),day,ercode); {get the value of the day}
- val(copy(date,1,2),mth,ercode); {get the value of the month}
- pv := 7.5/12;
- yr := yr + 1900; {convert to 19XX format}
- y1 := yr + (mth - 2.85)/12;
- Cal_Julian := int(int(int(367.0 * y1) - int(y1) - 0.75 * int(y1) + day) - 0.75 *2.0) + 1721115.0 + 9800;
- end;
-
- procedure set_date_fields(c,r:word;date:str8);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Real_Type).Lo;
- OP_Hi := Temp_Rec(Real_Type).Hi;
- Len_Lo := Temp_Rec(Real_Len).Lo;
- Len_Hi := Temp_Rec(Real_Len).Hi;
- end;
- with Lotus_Real do begin
- Fmt := Date_Format;
- Col_Hi := Temp_Rec(c).Hi;
- Col_Lo := Temp_Rec(c).Lo;
- Row_Hi := Temp_Rec(r).Hi;
- Row_Lo := Temp_Rec(r).Lo;
- Val := (Cal_Julian(date)-2424832); {this converts the date to
- a Lotus date number}
- end;
- end;
-
- procedure set_int_fields(c,r:word;v:integer;f:byte);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Integer_Type).Lo;
- OP_Hi := Temp_Rec(Integer_Type).Hi;
- Len_Lo := Temp_Rec(Integer_Len).Lo;
- Len_Hi := Temp_Rec(Integer_Len).Hi;
- end;
- with Lotus_Int do begin
-
- Fmt := f;
- Col_Lo := Temp_Rec(c).Lo;
- Col_Hi := Temp_Rec(c).Hi;
- Row_Hi := Temp_Rec(r).Hi;
- Row_Lo := Temp_Rec(r).Lo;
- Val := v;
- end;
- end;
-
- procedure set_real_fields(c,r:word;v:double;f:byte);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Real_Type).Lo;
- OP_Hi := Temp_Rec(Real_Type).Hi;
- Len_Lo := Temp_Rec(Real_Len).Lo;
- Len_Hi := Temp_Rec(Real_Len).Hi;
- end;
- with Lotus_Real do begin
- Fmt := f;
- Col_Lo := Temp_Rec(c).Lo;
- Col_Hi := Temp_Rec(c).Hi;
- Row_Hi := Temp_Rec(r).Hi;
- Row_Lo := Temp_Rec(r).Lo;
- Val := v;
- end;
- end;
-
- procedure set_label_fields(c,r:word;s:string;f:byte;lf:char);
- var i : byte; l : word;
- begin
- s := s + #0;
- l := Length(s);
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Label_Type).Lo;
- OP_Hi := Temp_Rec(Label_Type).Hi;
- Len_Lo := Temp_Rec(Label_len).hi;
- Len_Hi := Temp_Rec(Label_len).lo;
- end;
- with Lotus_Label do begin
- Fmt := f;
- Col_Lo := Temp_Rec(c).Lo;
- Col_Hi := Temp_Rec(c).Hi;
- Row_Hi := Temp_Rec(r).Hi;
- Row_Lo := Temp_Rec(r).Lo;
- Val[0] := lf;
- for i := 1 to Label_Length do
- Val[i] := #0;
- for i := 1 to l do
- Val[i] := s[i];
- end;
- end;
-
- procedure set_column_width(c:word;w:byte);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(ColW1_Type).Lo;
- OP_Hi := Temp_Rec(ColW1_Type).Hi;
- Len_Lo := Temp_Rec(ColW1_Len).Lo;
- Len_Hi := Temp_Rec(ColW1_Len).Hi;
- end;
- with Lotus_Col do begin
- CNum_Lo := Temp_Rec(c).Lo;
- CNum_Hi := Temp_Rec(c).Hi;
- Cwth := w;
- end;
- end;
-
- procedure set_window_fields
- (c,r:word;f:byte;cw,co,ro,lc,tr,ntc,ntr,ltc,ttr,bc,br,ww:word);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Window_Type).Lo;
- OP_Hi := Temp_Rec(Window_Type).Hi;
- Len_Lo := Temp_Rec(Window_Len).Lo;
- Len_Hi := Temp_Rec(Window_Len).Hi;
- end;
- with Lotus_Window do begin
- Fmt := f;
- Null1 := $00;
- Null2 := $00;
- Cur_Col_Lo := Temp_Rec(c).Lo;
- Cur_Col_Hi := Temp_Rec(c).Hi;
- Cur_Row_Lo := Temp_Rec(r).Lo;
- Cur_Row_Hi := Temp_Rec(r).Hi;
- Col_Wth_Lo := Temp_Rec(cw).Lo;
- Col_Wth_Hi := Temp_Rec(cw).Hi;
- Col_On_Lo := Temp_Rec(co).Lo;
- Col_On_Hi := Temp_Rec(co).Hi;
- Row_On_Lo := Temp_Rec(ro).Lo;
- Row_On_Hi := Temp_Rec(ro).Hi;
- L_Col_Lo := Temp_Rec(lc).Lo;
- L_Col_Hi := Temp_Rec(lc).Hi;
- T_Row_Lo := Temp_Rec(tr).Lo;
- T_Row_Hi := Temp_Rec(tr).Hi;
- NT_Col_Lo := Temp_Rec(ntc).Lo;
- NT_Col_Hi := Temp_Rec(ntc).Hi;
- NT_Row_Lo := Temp_Rec(ntr).Lo;
- NT_Row_Hi := Temp_Rec(ntr).Hi;
- LT_Col_Lo := Temp_Rec(ltc).Lo;
- LT_Col_Hi := Temp_Rec(ltc).Hi;
- TT_Row_Lo := Temp_Rec(ttr).Lo;
- TT_Row_Hi := Temp_Rec(ttr).Hi;
- BW_Col_Lo := Temp_Rec(bc).Lo;
- BW_Col_Hi := Temp_Rec(bc).Hi;
- BW_Row_Lo := Temp_Rec(br).Lo;
- BW_Row_Hi := Temp_Rec(br).Hi;
- Wdw_Wth_Lo := Temp_Rec(ww).Lo;
- Wdw_Wth_Hi := Temp_Rec(ww).Hi;
- end;
- end;
-
- procedure set_blank_fields(c,r:word;f:byte);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Blank_Type).Lo;
- OP_Hi := Temp_Rec(Blank_Type).Hi;
- Len_Lo := Temp_Rec(Blank_Len).Lo;
- Len_Hi := Temp_Rec(Blank_Len).Hi;
- end;
- with Lotus_Blank do begin
- Fmt := f;
- Col_Lo := Temp_Rec(c).Lo;
- Col_Hi := Temp_Rec(c).Hi;
- Row_Lo := Temp_Rec(r).Lo;
- Row_Hi := Temp_Rec(r).Hi;
- end;
- end;
-
- procedure set_byte_fields(OpCode:word);
- var l : word;
- begin
- l := $0100;
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(OpCode).Lo;
- OP_Hi := Temp_Rec(OpCode).Hi;
- Len_Lo := Temp_Rec(l).Lo;
- Len_Hi := Temp_Rec(l).Hi;
- end;
- case OpCode of
- $0200, $0500 : Lotus_Byte.Byt := $FF; {'$00 is Manual Recalc, Window
- not syncronized}
- $0300, $0400,
- $2400, $2F00,
- $3000 : Lotus_Byte.Byt := $00; {'$01 is Recalc by Col and
- Split Vertically,
- '$FF is Recalc by Row and
- Split Horizontally}
- $2900 : Lotus_Byte.Byt := $27;
- end;
- end;
-
- procedure set_range_fields(c,r:word);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Range_Type).Lo;
- OP_Hi := Temp_Rec(Range_Type).Hi;
- Len_Lo := Temp_Rec(Range_Len).Lo;
- Len_Hi := Temp_Rec(Range_Len).Hi;
- end;
- with Lotus_Range do begin
- S_Col_Lo := $00; {Column A, Row 1}
- S_Col_Hi := $00; {Column A, Row 1}
- S_Row_Lo := $00;
- S_Row_Hi := $00;
- E_Col_Lo := Temp_Rec(c).Lo;
- E_Col_Hi := Temp_Rec(c).Hi;
- E_Row_Lo := Temp_Rec(r).Lo;
- E_Row_Hi := Temp_Rec(r).Hi;
- end;
- end;
-
- procedure set_PFSranges_fields(OpCode:word);
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(OpCode).Lo;
- OP_Hi := Temp_Rec(OpCode).Hi;
- Len_Lo := Temp_Rec(Range_Len).Lo;
- Len_Hi := Temp_Rec(Range_Len).Hi;
- end;
- with Lotus_Range do begin
- S_Col_Lo := $FF;
- S_Col_Hi := $FF;
- S_Row_Lo := $00;
- S_Row_Hi := $00; {Default settings}
- E_Col_Lo := $FF;
- E_Col_Hi := $FF;
- E_Row_Lo := $00;
- E_Row_Hi := $00;
- end;
- end;
-
- procedure set_table_fields;
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Table_Type).Lo;
- OP_Hi := Temp_Rec(Table_Type).Hi;
- Len_Lo := Temp_Rec(Table_Len).Lo;
- Len_Hi := Temp_Rec(Table_Len).Hi;
- end;
- with Lotus_Table do begin
- Fmt := $00;
- i := 1;
- while i < 22 do begin
- temp[i] := $FF;
- temp[i+1] := $FF;
- i := i + 4;
- end;
- i := 3;
- while i < 24 do begin
- temp[i] := $00;
- temp[i+1] := $00;
- i := i + 4;
- end;
- end;
- end;
-
- procedure set_qrange_fields;
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(QRange_Type).Lo;
- OP_Hi := Temp_Rec(QRange_Type).Hi;
- Len_Lo := Temp_Rec(QRange_Len).Lo;
- Len_Hi := Temp_Rec(QRange_Len).Hi;
- end;
- with Lotus_QRange do begin
- i := 0;
- while i < 21 do begin
- temp[i] := $FF;
- temp[i+1] := $FF;
- i := i + 4;
- end;
- i := 2;
- while i < 23 do begin
- temp[i] := $00;
- temp[i+1] := $00;
- i := i + 4;
- end;
- Fmt := $00;
- end;
- end;
-
- procedure set_Kranges_fields(OpCode:word);
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(OpCode).Lo;
- OP_Hi := Temp_Rec(OpCode).Hi;
- Len_Lo := Temp_Rec(KRange_Len).Lo;
- Len_Hi := Temp_Rec(KRange_Len).Hi;
- end;
- with Lotus_KRange do begin
- i := 0;
- while i < 5 do begin
- temp[i] := $FF;
- temp[i+1] := $FF;
- i := i + 4;
- end;
- i := 2;
- while i < 7 do begin
- temp[i] := $00;
- temp[i+1] := $00;
- i := i + 4;
- end;
- temp[8] := $27;
- end;
- end;
-
- procedure set_HrgTitle_fields(OpCode:word);
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(OpCode).Lo;
- OP_Hi := Temp_Rec(OpCode).Hi;
- Len_Lo := Temp_Rec(Title_Len).Lo; {doubles for HRange_Len also}
- Len_Hi := Temp_Rec(Title_Len).Hi;
- end;
- with Lotus_HRgTitle do begin
- i := 0;
- while i < 13 do begin
- temp[i] := $FF;
- temp[i+1] := $FF;
- i := i + 4;
- end;
- i := 2;
- while i < 15 do begin
- temp[i] := $00;
- temp[i+1] := $00;
- i := i + 4;
- end;
- end;
- end;
-
- procedure set_footer_header_fields(OpCode:word);
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(OpCode).Lo;
- OP_Hi := Temp_Rec(OpCode).Hi;
- Len_Lo := Temp_Rec(Footer_len).Lo;
- Len_Hi := Temp_Rec(Footer_Len).Hi;
- end;
- with Lotus_HdFt do
- for i := 0 to 241 do
- temp[i] := $00;
- end;
-
- procedure set_setup_fields;
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(SetUp_Type).Lo;
- OP_Hi := Temp_Rec(SetUp_Type).Hi;
- Len_Lo := Temp_Rec(SetUp_Len).Lo;
- Len_Hi := Temp_Rec(SetUp_Len).Hi;
- end;
- with Lotus_SetUp do begin
- temp[0] := $00;
- for i := 1 to 39 do
- temp[i] := $20;
- end;
- end;
-
- procedure set_margin_fields;
- var i : byte;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Margin_Type).Lo;
- OP_Hi := Temp_Rec(Margin_Type).Hi;
- Len_Lo := Temp_Rec(Margin_Len).Lo;
- Len_Hi := Temp_Rec(Margin_Len).Hi;
- end;
- with Lotus_Margin do begin
- for i := 0 to 9 do
- temp[i] := $00;
- temp[0] := $04;
- temp[2] := $4C;
- temp[4] := $42;
- temp[6] := $02;
- temp[8] := $02;
- end;
- end;
-
- procedure set_graph_fields;
- var i : integer;
- begin
- with Lotus_Cell do begin
- OP_Lo := Temp_Rec(Graph_Type).Lo;
- OP_Hi := Temp_Rec(Graph_Type).Hi;
- Len_Lo := Temp_Rec(Graph_Len).Lo;
- Len_Hi := Temp_Rec(Graph_Len).Hi;
- end;
- with Lotus_Graph do begin
- i := 0;
- while i < 101 do begin
- temp[i] := $FF;
- temp[i+1] := $FF;
- i := i + 4;
- end;
- i := 2;
- while i < 103 do begin
- temp[i] := $00;
- temp[i+1] := $00;
- i := i + 4;
- end;
- temp[104] := $04;
- temp[105] := $00;
- temp[106] := $00;
- for i := 107 to 112 do
- temp[i] := $03;
- for i := 113 to 432 do
- temp[i] := $00;
- temp[433] := $71;
- temp[434] := $71;
- temp[435] := $01;
- temp[436] := $00;
- end;
- end;
-
- procedure write_graph_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Graph,437);
- end;
-
- procedure write_margin_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Margin,10);
- end;
-
- procedure write_setup_rec;
- begin
- BlockWrite(Lotus_File,Lotus_SetUp,40);
- end;
-
- procedure write_footer_header_rec;
- begin
- BlockWrite(Lotus_File,Lotus_HdFt,242);
- end;
-
- procedure write_table_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Table,25);
- end;
-
- procedure write_qrange_rec;
- begin
- BlockWrite(Lotus_File,Lotus_QRange,25);
- end;
-
- procedure write_Krange_rec;
- begin
- BlockWrite(Lotus_File,Lotus_KRange,9);
- end;
-
- procedure write_HrgTitle_rec;
- begin
- BlockWrite(Lotus_File,Lotus_HRgTitle,16);
- end;
-
- procedure write_bof_rec;
- begin
- BlockWrite(Lotus_File,Lotus_BOF,2);
- end;
-
- procedure write_eof_rec;
- begin
- BlockWrite(Lotus_File,Lotus_EOF,0);
- end;
-
- procedure write_int_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Int,7);
- end;
-
- procedure write_real_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Real,13);
- end;
-
- procedure write_label_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Label,Label_length);
- end;
-
- procedure write_column_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Col,3);
- end;
-
- procedure write_blank_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Blank,5);
- end;
-
- procedure write_window_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Window,31);
- end;
-
- procedure write_formula_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Formula,(Formula_Length+15));
- end;
-
- procedure write_byte_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Byte,1);
- end;
-
- procedure write_range_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Range,8);
- end;
-
- procedure write_lotus_rec;
- begin
- BlockWrite(Lotus_File,Lotus_Cell,4);
- case Lotus_Cell.Op_Lo of
- $00 : write_bof_rec;
- $01 : write_eof_rec;
- $02,
- $03,
- $04,
- $05,
- $24,
- $29,
- $2F,
- $30 : write_byte_rec;
- $1A,
- $1B,
- $1C,
- $06 : write_range_rec;
- $07 : write_window_rec;
- $08 : write_column_rec;
- $0C : write_blank_rec;
- $0D : write_int_rec;
- $0E : write_real_rec;
- $0F : write_label_rec;
- $10 : write_formula_rec;
- $18 : write_table_rec;
- $19 : write_qrange_rec;
- $1D,
- $23 : write_Krange_rec;
- $25,
- $26 : write_footer_header_rec;
- $27 : write_setup_rec;
- $28 : write_margin_rec;
- $2A,
- $20 : write_HrgTitle_rec;
- $2D : write_graph_rec;
- end;
- end;
-
- procedure open_wks_file(Lotus_File_Name:PathStr;version,NumofCol,NumofRow:word);
- begin
- assign(Lotus_File,Lotus_File_Name);
- rewrite(Lotus_File,1);
- set_bof_rec(version);
- write_lotus_rec;
- set_range_fields(NumofCol,NumofRow);
- write_lotus_rec;
- set_byte_fields(CalcC_Type);
- write_lotus_rec;
- set_byte_fields(CalcM_Type); {calmode}
- write_lotus_rec;
- set_byte_fields(CalcO_Type); {calcorder}
- write_lotus_rec;
- set_byte_fields(Split_Type); {split}
- write_lotus_rec;
- set_byte_fields(Sync_Type); {sync}
- write_lotus_rec;
-
- {The following is a default window setting. To set your own window
- settings remove the next three lines and make your own calls to
- set_window_fields and write_lotus_rec from within your program}
-
- set_window_fields($0000,$0000,$71,$0900,$0600,$1400,$0000,$0000,$0000,
- $0000,$0000,$0000,$0400,$0400,$4800);
- write_lotus_rec;
-
- end;
-
- procedure write_required_records;
- begin
- set_table_fields;
- write_lotus_rec;
- set_Qrange_fields;
- write_lotus_rec;
- set_pfsranges_fields(PRange_Type);
- write_lotus_rec;
- set_byte_fields(UnFormat_Type);
- write_lotus_rec;
- set_pfsranges_fields(FRange_Type);
- write_lotus_rec;
- set_pfsranges_fields(SRange_Type);
- write_lotus_rec;
- set_Kranges_fields(KRange_Type);
- write_lotus_rec;
- set_Kranges_fields(KRange2_Type);
- write_lotus_rec;
- set_HRgTitle_fields(HRange_Type);
- write_lotus_rec;
- set_byte_fields(Protect_Type);
- write_lotus_rec;
- set_footer_header_fields(Footer_Type);
- write_lotus_rec;
- set_footer_header_fields(Header_Type);
- write_lotus_rec;
- set_setup_fields;
- write_lotus_rec;
- set_margin_fields;
- write_lotus_rec;
- set_byte_fields(LabelFmt_Type);
- write_lotus_rec;
- set_HRgTitle_fields(Title_Type);
- write_lotus_rec;
- set_graph_fields;
- write_lotus_rec;
- end;
-
-
- procedure close_wks_file;
- begin
- set_eof_rec;
- write_lotus_rec;
- close(Lotus_File);
- end;
-
- begin
- BOF_Type := $0000; {OpCode for the Begining of File record}
- EOF_Type := $0100; {OpCode for the End of File record}
- Formula_Type := $1000; {OpCode for the Formula record}
- CalcM_Type := $0200; {OpCode for the Calcmode record}
- CalcO_Type := $0300; {OpCode for the Calcorder record}
- Split_Type := $0400; {OpCode for the Split record}
- Sync_Type := $0500; {OpCode for the Sync record}
- Range_Type := $0600; {OpCode for the Range record}
- Window_Type := $0700; {OpCode for the Window record}
- ColW1_Type := $0800; {OpCode for the Column width record}
- Blank_Type := $0C00; {OpCode for the Blank record}
- Integer_Type := $0D00; {OpCode for the integer record}
- Real_Type := $0E00; {OpCode for the real record}
- Label_Type := $0F00; {OpCode for the label record}
- CalcC_Type := $2F00; {OpCode for the Calc count record}
- Table_Type := $1800;
- QRange_Type := $1900;
- PRange_Type := $1A00;
- SRange_Type := $1B00;
- FRange_Type := $1C00;
- KRange_Type := $1D00;
- HRange_Type := $2000;
- KRange2_Type := $2300;
- Protect_Type := $2400;
- Footer_Type := $2500;
- Header_Type := $2600;
- Setup_Type := $2700;
- Margin_Type := $2800;
- LabelFmt_Type := $2900;
- Title_Type := $2A00;
- Graph_Type := $2D00;
- UnFormat_Type := $3000;
-
- BOF_Len := $0200; {Length of the Begining of File record}
- EOF_Len := $0000; {Length of the End of File record}
- CalcM_Len := $0100; {Length of the Calcmode record}
- CalcO_Len := $0100; {Length of the Calcorder record}
- CalcC_Len := $0100; {Length of the CalcCount record}
- Split_Len := $0100; {Length of the Split record}
- Sync_Len := $0100; {Length of the Sync record}
- Range_Len := $0800; {Length of the Range record}
- Window_Len := $1F00; {Length of the Window record}
- ColW1_Len := $0300; {Length of the Column width record}
- Blank_Len := $0500; {Length of the Blank record}
- Integer_Len := $0700; {Length of the integer record}
- Real_Len := $0D00; {Length of the real record}
-
- Table_Len := $1900;
- QRange_Len := $1900;
- PRange_Len := $0800;
- SRange_Len := $0800;
- FRange_Len := $0800;
- KRange_Len := $0900;
- { HRange_Len := $1000; }
- KRange2_Len := $0900;
- Protec_Len := $0100;
- Footer_Len := $F200;
- { Header_Len := $F200; }
- Setup_Len := $2800;
- Margin_Len := $0A00;
- LabelFmt_Len := $0100;
- Title_Len := $1000;
- Graph_Len := $B501;
-
- {
- Label_Length = 32;
- maximum length for a label string is 245, change as needed
- Formula_Length = 30;
- maximum length for a formula series is 2047, change as needed
- }
- Label_Len := Label_Length;
- Formula_Len := Formula_Length;
-
- end.