Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default *Fast* way of extracting cell text formatting

Is there a pretty quick way to extract the formatting of text in a single
cell? For example, the cell may contain some text that is bold, superscript,
underline, or italic. I want to convert the text to HTML, so that I can
display it somewhere else.

So far, I have the following code:

int CharCount = Convert.ToString(Cell.Text).Length;
int UnderlineStyle =
(int)Microsoft.Office.Interop.Excel.XlUnderlineSty le.xlUnderlineStyleSingle;

for (int CharNum = 0; CharNum < CharCount; CharNum++)
{
Microsoft.Office.Interop.Excel.Characters Char =
Cell.get_Characters(CharNum + 1, 1);
bool IsCharBold = (bool)Char.Font.Bold;
bool IsCharUnderline = (int)Char.Font.Underline ==
UnderlineStyle;
bool IsCharItalic = (bool)Char.Font.Italic;
bool IsCharSuperScript = (bool)Char.Font.Superscript;

/** some other code here **//
}
}

However, the above code is extremely slow. I have some cells that contain
over 1000 characters, and it takes several minutes to execute the code for
the single cell. Does anyone know if there is a faster way to extract the
formatting info?

Thx,

Filip Stanek
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default *Fast* way of extracting cell text formatting

I believe what you have is pretty the only way to do it.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 15 Sep 2009 12:27:01 -0700, Filip Stanek
wrote:

Is there a pretty quick way to extract the formatting of text in a single
cell? For example, the cell may contain some text that is bold, superscript,
underline, or italic. I want to convert the text to HTML, so that I can
display it somewhere else.

So far, I have the following code:

int CharCount = Convert.ToString(Cell.Text).Length;
int UnderlineStyle =
(int)Microsoft.Office.Interop.Excel.XlUnderlineSt yle.xlUnderlineStyleSingle;

for (int CharNum = 0; CharNum < CharCount; CharNum++)
{
Microsoft.Office.Interop.Excel.Characters Char =
Cell.get_Characters(CharNum + 1, 1);
bool IsCharBold = (bool)Char.Font.Bold;
bool IsCharUnderline = (int)Char.Font.Underline ==
UnderlineStyle;
bool IsCharItalic = (bool)Char.Font.Italic;
bool IsCharSuperScript = (bool)Char.Font.Superscript;

/** some other code here **//
}
}

However, the above code is extremely slow. I have some cells that contain
over 1000 characters, and it takes several minutes to execute the code for
the single cell. Does anyone know if there is a faster way to extract the
formatting info?

Thx,

Filip Stanek

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default *Fast* way of extracting cell text formatting

On Tue, 15 Sep 2009 12:27:01 -0700, Filip Stanek
wrote:

Is there a pretty quick way to extract the formatting of text in a single
cell? For example, the cell may contain some text that is bold, superscript,
underline, or italic. I want to convert the text to HTML, so that I can
display it somewhere else.

So far, I have the following code:

int CharCount = Convert.ToString(Cell.Text).Length;
int UnderlineStyle =
(int)Microsoft.Office.Interop.Excel.XlUnderlineSt yle.xlUnderlineStyleSingle;

for (int CharNum = 0; CharNum < CharCount; CharNum++)
{
Microsoft.Office.Interop.Excel.Characters Char =
Cell.get_Characters(CharNum + 1, 1);
bool IsCharBold = (bool)Char.Font.Bold;
bool IsCharUnderline = (int)Char.Font.Underline ==
UnderlineStyle;
bool IsCharItalic = (bool)Char.Font.Italic;
bool IsCharSuperScript = (bool)Char.Font.Superscript;

/** some other code here **//
}
}

However, the above code is extremely slow. I have some cells that contain
over 1000 characters, and it takes several minutes to execute the code for
the single cell. Does anyone know if there is a faster way to extract the
formatting info?

Thx,

Filip Stanek


Perhaps is you SAVE'd the document in HTML (or even XML) format, you might be
able to extract the data that way more quickly.
--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default *Fast* way of extracting cell text formatting

I think I found a pretty fast way of doing it. There may be faster ways, but
where my code would take 30 minutes to execute before, it now takes about 15
seconds.

I wrote a little explanation of how I'm doing it on my blog if anyone else
has a need to quickly convert text in a cell to HTML or some other format.

http://www.bloodforge.com/post/Extra...ll-With-C.aspx

Thanks!

Filip Stanek

"Chip Pearson" wrote:

I believe what you have is pretty the only way to do it.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 15 Sep 2009 12:27:01 -0700, Filip Stanek
wrote:

Is there a pretty quick way to extract the formatting of text in a single
cell? For example, the cell may contain some text that is bold, superscript,
underline, or italic. I want to convert the text to HTML, so that I can
display it somewhere else.

So far, I have the following code:

int CharCount = Convert.ToString(Cell.Text).Length;
int UnderlineStyle =
(int)Microsoft.Office.Interop.Excel.XlUnderlineSt yle.xlUnderlineStyleSingle;

for (int CharNum = 0; CharNum < CharCount; CharNum++)
{
Microsoft.Office.Interop.Excel.Characters Char =
Cell.get_Characters(CharNum + 1, 1);
bool IsCharBold = (bool)Char.Font.Bold;
bool IsCharUnderline = (int)Char.Font.Underline ==
UnderlineStyle;
bool IsCharItalic = (bool)Char.Font.Italic;
bool IsCharSuperScript = (bool)Char.Font.Superscript;

/** some other code here **//
}
}

However, the above code is extremely slow. I have some cells that contain
over 1000 characters, and it takes several minutes to execute the code for
the single cell. Does anyone know if there is a faster way to extract the
formatting info?

Thx,

Filip Stanek


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting text from a cell jmberner Excel Worksheet Functions 4 December 31st 08 04:16 PM
Extracting text from a cell James Excel Worksheet Functions 3 December 10th 07 09:58 PM
Fast Formatting Devin[_2_] Excel Discussion (Misc queries) 3 November 5th 07 05:41 PM
Extracting text from a cell kfowlow Excel Discussion (Misc queries) 2 November 17th 06 06:58 PM
extracting text from within a cell - 'text to rows@ equivalent of 'text to columns' Dan E[_2_] Excel Programming 4 July 30th 03 06:43 PM


All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"