We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Saving A FlexGrid

clarwc
clarwc asked
on
Medium Priority
867 Views
Last Modified: 2011-10-03
 I have a Flex grid displaying an Access Query.  I have read the contents and replaced certain text with graphics ("red" = red.gif).  Does anyone have
        any code that would allow the user to save this display in a format that could be brought into other MS products as a table with complete editing
        capability.
Comment
Watch Question

Commented:
to get this strait,

You want to be able to port this flexigrid, with graphics, as a table to other apps such as work and excel, or just to a specific app , such as excel.

Also do you know how many (or at least a maximum value) of records you would be looking at?

Commented:
One solution that comes to mind is to implement a function that parses the entire flexgrid and returns rich text (RTF). Rich text has rtf-codes for tables (Like word tables), and pictures.
Word/Excel/WP and other applications will be able to read that.

Good luck!

Author

Commented:
wford,

The ultimate goal for the table would be Powerpoint.  I just figured that if I were able to get it into Word or Excel that dropping it onto a Powerpoint slide would be easy.  As far as records are concerned, I will have seven fields and probably no more than 250-300 records.


mtoft,

I have no idea how to parse the flexgrid and return RTF with my tables.  It sounds like something that might work because I could use an OLE object to open the file in Word or Excel.  Any suggestions as to how to do it???

Commented:
Hmmm, just of the top of my head..

two ideas come to mind
1.
Have you considered using VB for applications, I find it a bit clunky, but you can open word, create a table with the dimensions of your flexigrid, then scan through the flexigrid and copy that text or images into the equivilent cell, then you can save, or select the table and export.

This is normaly slow and painful,but may be just the thing if you do this operation rarely and mostly on you own computer.

2.
Parse the stuff into HTML, it's a little bit more forgiving than RTF and ofice 97 and onwards will support it, or at least do the HTML to RTF translation for you.

This is a little better, not as slow,but  less automated.

Author

Commented:
HTML sunds like the best bet but I have no idea how to do that.  The code I am using to populate the Flexgrid is:




Private Sub CmdBack_Click()
    FrmProgData.Hide

   
End Sub



Private Sub FG1_GotFocus()
   
    FG1.Font.Name = "arial"
    FG1.Font.Size = "8"
    FG1.Font.Bold = True
    FG1.Cols = 8
    s$ = "          |<Code                   |<Program Title                                           |<Cost      |<Sched |<Perf       |<Remarks                                                     |<Updated      "
    FG1.FormatString = s$
    FG1.WordWrap = True
   
   
   
    For nCnt1 = 1 To FG1.Rows - 1
        For nColNum = 3 To 5
          Select Case FG1.TextMatrix(nCnt1, nColNum)
            Case "Red"
              FG1.CellPictureAlignment = flexAlignCenterCenter
              sPicFile = "c:\205gui\YelRed.gif"
            Case "Green"
              FG1.CellPictureAlignment = flexAlignCenterCenter
              sPicFile = "c:\205gui\Grnball.gif"
            Case "Yellow"
              FG1.CellPictureAlignment = flexAlignCenterCenter
              sPicFile = "c:\205gui\Yellball.gif"
            Case Else
              sPicFile = ""
          End Select
          If sPicFile <> "" Then
            FG1.Col = nColNum
            FG1.Row = nCnt1
            Set FG1.CellPicture = LoadPicture(sPicFile)
            FG1.TextMatrix(nCnt1, nColNum) = ""
          End If
        Next nColNum
      Next nCnt1

    Call fixflex
   

End Sub

Private Sub fixflex()
    Dim nrow As Integer
   
    LblCellText.Width = FG1.ColWidth(6)
   
    For nrow = 1 To FG1.Rows - 1
        LblCellText.Caption = FG1.TextMatrix(nrow, 6)
        FG1.RowHeight(nrow) = LblCellText.Height + 240
    Next nrow
    End Sub
   

Any help you can give would be greatly appreciated...

Warren

Commented:
OK, well, I will not submit this as an answer cause I have not yet finished it, but on the 1st solution, I have this so far. Keep in mind,It seems to work, but I am missing the the picture insert syntax. I'll post as far as I'ive got today, so that you, or others can move ahead, (I have to sleep, and do some work, I know not why!)

Dim WordX As Object
Dim TblRow As Integer, TblCol As Integer
dim nC as integer, nR as integer

Set WordX = GetObject(, "Word.Application")
    If Err.Number <> 0 Then                             'Error case, no current Word app
        Err.Clear                                       'Clear Err object
        RetVal = Shell("Your path for Word", 6)       'start word in shell
        If RetVal = 0 Then MsgBox "MS Word not installed": Exit Sub    'if shell command not successful exit print
        Set WordX = GetObject(, "Word.Application")                 'get control of new word application
    End If
    WordX.Documents.Add 'open new document
    'look for dimensions of your flexigrid
    TblRow = MSFlexGrid1.Rows
    'watch for hidden columns, or ones with no width
    TblCol = MSFlexGrid1.Cols
    'create the table as you want it
    With WordX.Activedocument
        Set myRange = .Range(Start:=0, End:=0)
        .Tables.Add Range:=myRange, NumRows:=TblRow, NumColumns:=TblCol
        'setup col widths. Note: tables are 1 based and flexi grids are 0 based
        For n = 1 To tblcols
            ColWdth = MSFlexGrid1.ColWidth(n - 1)
            .Tables(1).Columns(n).SetWidth ColumnWidth:=ColWdth, RulerStyle:=wdAdjustNone
        Next n
        'you can setup rows, styles etc... here
        'Now just fill in your data
        For nC = 1 To TblCol
            'set cell contents
            MSFlexGrid1.Col = nC - 1
            For nR = 1 To TblRow
                MSFlexGrid1.Col = nC - 1
                'See if there is a picture
                If MSFlexGrid1.CellPicture = 0 Then
                    .Tables(1).cell(nR, nC).Range.Text = Trim(MSFlexGrid1.Text)
                Else
                    'Its only this that does not work so far
                    'Set .Tables(1).cell(nR, nC). =MSFlexGrid1.CellPicture
                End If
            Next nR
        Next nC
    End With

Pop this into a sub or command button and haveMS Word open and it should work, except for inserting the  pictures. I stress, this is just a rough go at the problem, I have not tested it much, and there are many refinements to be made on the layout of the table, style and font, scaleing to fit the page etc... If this looks like what you want, leave a message and I will post the finish version tomorrow (my time) :>

Hope it helps
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
mtoft,

Looks like just what I need.  A couple of questions though.  I added a "Save" command button to my flexgrid and inserted the code from the save function in your code example.  When I try to execute I get an error message saying "Object Required and the debugger takes me to the line that says    

Author

Commented:
mtoft,

Looks like just what I need.  A couple of questions though.  I added a "Save" command button to my flexgrid and inserted the code from the save function in your code example.  When I try to execute I get an error message saying "Object Required and the debugger takes me to the line that says

SaveFlexgridAsHTML FlexGrid

Also when I inserted the code into my application the following line was red:

COLOR=""#" & GetHexicColorCode(FlexGrid.CellForeColor) & """>"

I think that means there is something missing.

If I attach the save function to a Save button then when would I call the code for the function SaveFlexgridAsHTML?

Thanks so much for all you have done to help me out.....

Warren

Commented:
I can help with the line it should be

COLOR= "#" & GetHexicColorCode(FlexGrid.CellForeColor) & ">"

But this is only for the syntax

I will not bother with my completed solution, unless you realy want it

Good luck

Author

Commented:
wford,

I am desperate for ANY solution to my problem.  If you are both working on it for me I could split the points.

Commented:
Hmm, the line looks OK to me...
Did you insert the function GetHexicColorCode ?

If you wish, I can email you the project.



The correct syntax is:

If (CLng(FlexGrid.CellBackColor) <> CLng(FlexGrid.BackColor)) And Len(FlexGrid.Text) <> 0 Then
    sHTML = sHTML & " BGCOLOR=""#" & GetHexicColorCode(FlexGrid.CellBackColor) & """ >"
Else
    sHTML = sHTML & ">"
End If

Author

Commented:
Was I correct in creating the Save button and moving the code for  the save function there???

Also why do I get an error message saying "Object Required and the debugger takes me to the line that says

       SaveFlexgridAsHTML FlexGrid

If you want to E-Mail me your code my address is clarwc@ispec.com  I would love to try ANYTHING that might work for me.....


Thanks again

Warren

Commented:
Ok, i mailed u the project...
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.