*Fast* way of extracting cell text formatting

F

Filip Stanek

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.XlUnderlineStyle.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
 
C

Chip Pearson

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)
 
R

Ron Rosenfeld

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.XlUnderlineStyle.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top