Menu

chinese is error on my linux.

Help
scofiy
2014-04-28
2016-01-15
  • scofiy

    scofiy - 2014-04-28

    i have a problem,list is my code
    void test(void)
    {
    workbook swb;
    xf_t sxf1 = swb.xformat();
    worksheet
    ssh;
    ssh = swb.sheet("sheet_1");
    string snamelabel = "中文";
    ssh->label(1,2,snamelabel,sxf1);
    swb.Dump("workbook.xls");
    }
    create the workbook.xls exactly, but the cell value is "iconv failed!". it is convert error, so what should i do,this is a matter of great urgency for me,who can help me ,thanks!

     
  • David Hoerl

    David Hoerl - 2014-04-28

    So you create an ascii string (string type) and then pass it to xlslib, which looks at all the characters and sees its UTF8. It wants to try and help, but it doesn't know the encoding of the characters, so it guesses UTF-8, but for some reason that fails.

    If at all possible pass the strings to xlslib as "wstrings" (wide strings), or even string16type (you'd probably have to set each character in this mode). Look at the headers and you will see the options.

    In the workbook header there is some way to set the iconv encoding I recall - don't have time to look for it now - but then you'd have to figure out what your system is doing when you set a "string" to a non-ascii value.

     

    Last edit: David Hoerl 2014-04-28
  • Snailman

    Snailman - 2016-01-15

    I have write a func to code and it works.
    Add this func to xlslib/src/sheetrec.cpp file and recompile the xlslib src code.
    cell_t worksheet::label(int code, unsigned16_t row, unsigned16_t col,
    const char
    strlabel, xf_t pxformat)
    {
    enum { UTF8, GBK };
    unsigned16_t u16;
    u16string str16;
    label_t
    lbl;
    wstring::const_iterator wbegin, wend;
    size_t len;

        if (code == UTF8) {
                if (strlabel == NULL) {
                        return NULL;
                } else {
                        len = strlen(strlabel);
                        wchar_t wcs[len+1];
                        mbstowcs(wcs, strlabel, len+1);
                        len = wcslen(wcs);
                        for (int i = 0; i < len; i++) {
                                u16 = wcs[i];
                                str16.push_back(u16);
                        }
                }
                lbl = new label_t(m_GlobalRecords, row, col, str16, pxformat);
                AddCell((cell_t*)lbl);
                return (cell_t*)lbl;
        } else {
                return NULL;
        }
    
        And use it like this :
        wb1sh1->label(UTF8, row, coloumn,        OCI_GetString(rs, 1));
    
     

Log in to post a comment.