tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.5k stars 423 forks source link

xlsx Cell with more than one font will not handled correctly. #44

Closed xpol closed 8 years ago

xpol commented 8 years ago

I have a LibreOffice edited xlsx having cells with both English and Chinese characters.

English characters are have Arial font. Chinese characters are have Microsoft Yahei font.

When I print the cell using follow code, I only get the first part of the full cell.

    xlnt::workbook wb;
    wb.load(filename);

    for(auto row : wb[sheet].rows())
    {
        for(auto cell : row)
        {
            std::cout << cell << std::endl;
        }
    }

As in follow image:

image

Attachment: bug.xlsx.

xpol commented 8 years ago

Its due to reading of shared strings. I can make a PR to fix it.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2">
  <si>
    <r>
      <rPr><sz val="10"/><color rgb="FF000000"/><rFont val="Arial"/><family val="2"/><charset val="1"/></rPr>
      <t>abc</t>
    </r>
    <r>
      <rPr><sz val="10"/><color rgb="FF000000"/><rFont val="微软雅黑"/><family val="2"/><charset val="134"/></rPr>
      <t>中文</t>
    </r>
  </si>
  <si>
    <r>
      <rPr><sz val="10"/><rFont val="微软雅黑"/><family val="2"/><charset val="134"/></rPr>
      <t>汉字</t>
    </r>
    <r>
      <rPr><sz val="10"/><rFont val="Arial"/><family val="2"/><charset val="134"/></rPr>
      <t>def</t>
    </r>
  </si>
</sst>
tfussell commented 8 years ago

This is great. Thanks for your contribution xpol. My support for non-ascii characters could certainly use some work. I'm planning to commit some improvements to string handling soon. I'll merge your work in at that time!

tfussell commented 8 years ago

I've implemented text runs and loading/saving workbooks containing cells with character-level formatting looks to be working. Going to call this closed.