Formatted cell in excel

Thread Solved

Join Date: Apr 2005
Posts: 75
Reputation: purplegerbil is an unknown quantity at this point 
Solved Threads: 6
purplegerbil's Avatar
purplegerbil purplegerbil is offline Offline
Junior Poster in Training

Formatted cell in excel

 
0
  #1
Jan 5th, 2009
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
Last edited by purplegerbil; Jan 5th, 2009 at 10:52 am.
purpleGERBIL
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 75
Reputation: purplegerbil is an unknown quantity at this point 
Solved Threads: 6
purplegerbil's Avatar
purplegerbil purplegerbil is offline Offline
Junior Poster in Training

Re: Formatted cell in excel

 
1
  #2
Jan 6th, 2009
I worked out one solution - its a bit slow but works.


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. myCell = "A3"
  2. OneChar = 0
  3. With objWorksheet.Range(myCell)
  4. For i = 1 To .Characters.Count
  5.  
  6. With .Characters(i, 1).Font
  7.  
  8. ' Add the start tag <b>
  9. If .Bold = True And boldON = False Then
  10. FullRecord = FullRecord & "<b>"
  11. boldON = True
  12. End If
  13.  
  14. ' Add the end tag <\b>
  15. If .Bold = False And boldON = True Then
  16. FullRecord = FullRecord & "<\b>"
  17. boldON = False
  18. End If
  19. End With
  20.  
  21. ' Increment character counter
  22. OneChar = OneChar + 1
  23.  
  24. ' Add the character to the FullRecord variable
  25. FullRecord = FullRecord & Mid$(.Characters.Text, OneChar, 1)
  26. Next i
  27.  
  28. ' If all the cell is bold then the end tag needs to be added
  29. If .Bold = True Then
  30. FullRecord = FullRecord & "<\b>"
  31. boldON = False
  32. End If
  33. End With





pG
purpleGERBIL
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Formatted cell in excel

 
0
  #3
Jan 6th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC