DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   Formatted cell in excel (http://www.daniweb.com/forums/thread166255.html)

purplegerbil Jan 5th, 2009 10:50 am
Formatted cell in excel
 
Hi,

I am wanting to get some data from an Excel spreadsheet. My problem is the data in the cell has been formatted.

i.e. This is sample text.

I want to be able to know which bits are made bold and create a string similar to: This is <b>sample<\b> text.

I canb get the text from the cell but lose the formatting.

Any ideas??

Happy New Year!

Pg

purplegerbil Jan 6th, 2009 9:29 am
Re: Formatted cell in excel
 
I worked out one solution - its a bit slow but works.


                myCell = "A3"
                OneChar = 0
                With objWorksheet.Range(myCell)
                    For i = 1 To .Characters.Count
 
                        With .Characters(i, 1).Font
                   
                            ' Add the start tag <b>
                            If .Bold = True And boldON = False Then
                                FullRecord = FullRecord & "<b>"
                                boldON = True
                            End If
 
                            ' Add the end tag <\b>
                            If .Bold = False And boldON = True Then
                                FullRecord = FullRecord & "<\b>"
                                boldON = False
                            End If
                        End With
 
                        ' Increment character counter
                        OneChar = OneChar + 1
                   
                        ' Add the character to the FullRecord variable
                        FullRecord = FullRecord & Mid$(.Characters.Text, OneChar, 1)
                    Next i
               
                    ' If all the cell is bold then the end tag needs to be added
                    If .Bold = True Then
                        FullRecord = FullRecord & "<\b>"
                        boldON = False
                    End If
                End With





pG

Comatose Jan 6th, 2009 10:29 am
Re: Formatted cell in excel
 
That's Really Great Work. Not only did you solve your own issue, but you also showed us a valid, and clean way to do it. Great Job pG.


All times are GMT -4. The time now is 10:58 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC