Save and Load (New to 2.06)

Top  Previous  Next

Save

The ability to save a sheet's data with much of it's formatting (excluding objects such a merged cells and splitter configurations).  Below is a framework on how to save a sheet.

 

             title$ = "Save File As"

             folder$ = "c:\data"

             filter$ = CHR$("MLG Sheet (*.mlg)", 0)

             start$ = ""

             defaultext$ = "mlg"

             flags = %OFN_PATHMUSTEXIST OR %OFN_EXPLORER OR %OFN_OVERWRITEPROMPT

            DISPLAY SAVEFILE ,,,"Save File", folder, filter, start, defaultext, flags TO filevar

            IF LEN(filevar) THEN

                 zstr = TRIM$(filevar)

                 SendMessage hGrid1,%MLG_SAVESHEET,0,VARPTR(zstr)

              ELSE

                'no action  'ESC or Cancel

            END IF

 

The wParam in the %MLG_SAVESHEET  can be set to 1 to only save cells with cell data or cell formatting data to "knock the air" out of a larger but sparsely populated grid. The currently active sheet is the one saved.  The internal file version is stamped into the file so if MLG changes how files are handled an outdated file structure can to identified.

 

Load

All or portions of a saved sheet file can be reloaded on to a sheet.  The currently active sheet can be loaded with the following framework code.

 

             title$ = "Open File"

             folder$ = "c:\data"

             filter$ = CHR$("MLG Sheet (*.mlg)", 0)

             start$ = ""

             defaultext$ = "mlg"

             flags = %OFN_PATHMUSTEXIST OR %OFN_EXPLORER OR %OFN_OVERWRITEPROMPT

            DISPLAY OPENFILE ,,,"Save File", folder, filter, start, defaultext, flags TO filevar

            IF LEN(filevar) THEN

                 zstr = TRIM$(filevar)

                 I=SendMessage (hGrid1,%MLG_LOADSHEET,0,VARPTR(zstr))

            ELSE

                'no action  'ESC or Cancel

            END IF

 

Potentially there is a lot more care needs to be taken on the load.  You must make sure the grid is dimensioned big enough though if a grid is to small, MLG will load what it can and leave an error could indicating the problem.  If a file version is outdated then the file will abort the load and return an error.  Loading a file may work in concert with the %MLG_CLEARGRID message since cell data and cell formatting is only loaded if present in the saved file.  So if a file was only cell selectively saved (with wParam set to 1) then if you are loading onto a presently populated grid, so could have potentially a mix of old and new cell data.  This may or may not be what you desired.  I kept the Load message pretty low level to give the programmer maximum flexibility.

 

The wParam parameter of the SendMessage call directs the action.

 

wParam = -1 asks for row dimensioning data.  The returned value is the needed row in the grid

wParam = -2 asks for col dimensioning data.  The absolute value of returned value is the needed cols in the grid.  If the value is negative then the file has cell formatting data in it but your current sheet does not have a cell format array set up (format override).  Recommend procedure is to retrieve this dimensioning data unless you know for sure what the files dimensions are.

wParam = 0 loads everything which is cell data, cell formatting, row headers data, and column header data.

wParam = 1 loads everything but skips cell data.

wParam = 2 loads everything but skips cell formatting.

wParam = 3 loads everything but skip the row and column headers (the headers may include some data needed by cell formatted comoboxes).

wParam = 4 loads only cell data.

 

 

 

When finished, MLG will set the grid to the view rows and cols as saved in the file.  The dimensions can be larger than the viewing area.