Pergunta

I need to read the formatting information available in a cell in excel. The excel file might contain an cell with text like "Some sample text". Each word would have a different formatting information. Like word "Some" might be bold and have a different font color and size. The next word might have different one.

Can we read the individual formatting information set for a single cell value? if yes, please let me know how to do the same.

I had used NPOI and OpenXML SDK 2.5 and with no luck. Prefer not to use excel interop, since this would be processed in the server.

Foi útil?

Solução 2

You are talking about reading RichText value from Cell. It will be supported by NPOI 2.0 final release. The release will happen in the first quarter, 2014.

Outras dicas

Here is a complete "hacker's answer" to your question.

I made a small Excel file with a single cell like this:

screen shot of spreadsheet

I saved the file, and closed it. Next, I changed the extension of the file from .xlsx to .zip - this allows you to open it and look at the contents. In a subfolder named xl you find a file called "sharedStrings.xml" that contains all the strings in the workbook, and their formatting within the cell. This is a giant array - this is done so that if the same value is entered in multiple cells, it is stored only once. Work through this file to get all the strings in all the cells, and their format...

For this particular cell, the sharedStrings.xml file contents start out as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1">
<si>
<r>
<t xml:space="preserve">This </t>
</r>
<r>
<rPr>
<b/>
<sz val="11"/>
<color theme="1"/>
<rFont val="Calibri"/>
<family val="2"/>
<scheme val="minor"/>
</rPr>
<t>cell</t>
</r>
<r>
<rPr>
<sz val="11"/>
<color theme="1"/>
... etc

By reading this file you will be able to reconstruct all the strings with their formatting. There MUST be a better way...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top