Results 1 to 5 of 5

Thread: Excel XML Creation with Qt's Dom classes

  1. #1
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Excel XML Creation with Qt's Dom classes

    Hi all,

    I'm trying to create an Excel XML workbook ( I didn't want, but it's strictly necessary )

    I've to build an "export to Excel" option in my "very-fashioned-and-colored-grid" that runs on a linux machine, because all my users use windows as client and I have to allow them to manipulate data externally.

    I have made a "CSV-export" option, but they want too the colors and some other options and they don't like to import every time ( as csv forces them to do ).

    An Excel.xml file looks like this :

    Qt Code:
    1. &#65279;<?xml version="1.0"?>
    2.  
    3. <?mso-application progid="Excel.Sheet"?>
    4.  
    5. <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    6.  
    7. xmlns:o="urn:schemas-microsoft-com:office:office"
    8.  
    9. xmlns:x="urn:schemas-microsoft-com:office:excel"
    10.  
    11. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    12.  
    13. xmlns:html="http://www.w3.org/TR/REC-html40">
    14. ...
    15. </Workbook>
    To copy to clipboard, switch view to plain text mode 

    The ... zone is trivial ( simple sections easy to do with Qt's classes ), but I don't know how to generate the first 2 lines that begin with "<?".

    Any idea ?

    Thanks in advance,

    Jordi.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Excel XML Creation with Qt's Dom classes

    These are called "processing instructions", so QDomDocument::createProcessingInstruction() should be the way to go.

  3. The following user says thank you to wysota for this useful post:

    jpujolf (21st May 2007)

  4. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Excel XML Creation with Qt's Dom classes

    Quote Originally Posted by jpujolf View Post
    Hi all,

    I'm trying to create an Excel XML workbook ( I didn't want, but it's strictly necessary )
    I have made a "CSV-export" option, but they want too the colors and some other options and they don't like to import every time ( as csv forces them to do ).
    Any idea ?

    Jordi.
    have you see my first qt4 projekt...

    http://sourceforge.net/projects/qtexcel-xslt/ 4000 downloads...

    from xmlexcel 2003 to sqlite3
    http://kent.dl.sourceforge.net/sourc.../excel2003.xsl
    xml direct to excel 95
    http://kent.dl.sourceforge.net/sourc...lsql2excel.xsl
    xml to fop pdf
    http://kent.dl.sourceforge.net/sourc.../xmlsql2fo.xsl

    the fastet way is http://en.wikipedia.org/wiki/XSLT

    qt4 dom have trouble if file having more as 4-5 MB

    a good CSV to sqlite you can find on http://sqlitebrowser.sourceforge.net/ source...


    on http://sourceforge.net/projects/visual-xsltproc/ source, i think you find more ...

    lib xslt is easy on linux and mac ... on window on mingw minimal system
    http://www.complex-computer.de/album...piling_libxml2

    on Visual Studio i dont know....

  5. #4
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Excel XML Creation with Qt's Dom classes

    I've been looking at the documentation, but I didn't see that ( I'm blind... )

    Many thanks !!!! It works fine...

  6. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Excel XML Creation with Qt's Dom classes

    more simple .. you make to your client the csv export direct editable ... like the edit model tablelist from a qt book ... i attach ...

    its split the csv file and make direct on a table your own excel ...

    and run on all os..

    Qt Code:
    1. QFile file("addressbook.csv");
    2. if ( !file.open(QIODevice::ReadOnly|QIODevice::Text) )
    3. return 1;
    4. // Adressen auslesen und zeilenweise in Stringliste einlesen
    5. QString addresses = QString::fromUtf8(file.readAll());
    6. QStringList records = addresses.split('\n');
    7.  
    8. // Erste Zeile (Ãœberschriften) entnehmen und aufspalten
    9. QString header = records.takeAt(0);
    10. QStringList headers = splitCSVLine(header);
    11.  
    12. QStringList splitCSVLine(const QString& line)
    13. {
    14. int inItem = false;
    15. QStringList items;
    16. QString item;
    17.  
    18. for (int pos = 0; pos < line.length(); pos++)
    19. {
    20. QChar c = line.at(pos);
    21. if ( c == '\"') {
    22. if (inItem) {
    23. items.append(item);
    24. item = "";
    25. }
    26. inItem = !inItem;
    27. }
    28. else
    29. if (inItem)
    30. item += c;
    31. }
    32. return items;
    33. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.