PDA

View Full Version : Excel XML Creation with Qt's Dom classes



jpujolf
21st May 2007, 11:18
Hi all,

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

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 :



<?xml version="1.0"?>

<?mso-application progid="Excel.Sheet"?>

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"

xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"

xmlns:html="http://www.w3.org/TR/REC-html40">
...
</Workbook>



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.

wysota
21st May 2007, 11:46
These are called "processing instructions", so QDomDocument::createProcessingInstruction() should be the way to go.

patrik08
21st May 2007, 11:53
Hi all,

I'm trying to create an Excel XML workbook ( I didn't want, but it's strictly necessary ) :crying:
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/sourceforge/qtexcel-xslt/excel2003.xsl
xml direct to excel 95
http://kent.dl.sourceforge.net/sourceforge/qtexcel-xslt/xmlsql2excel.xsl
xml to fop pdf
http://kent.dl.sourceforge.net/sourceforge/qtexcel-xslt/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/albumshaper/wiki/index.php/Compiling_on_Windows#Compiling_libxml2

on Visual Studio i dont know....

jpujolf
21st May 2007, 12:00
I've been looking at the documentation, but I didn't see that ( I'm blind... )

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

patrik08
21st May 2007, 12:23
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..




QFile file("addressbook.csv");
if ( !file.open(QIODevice::ReadOnly|QIODevice::Text) )
return 1;
// Adressen auslesen und zeilenweise in Stringliste einlesen
QString addresses = QString::fromUtf8(file.readAll());
QStringList records = addresses.split('\n');

// Erste Zeile (Ãœberschriften) entnehmen und aufspalten
QString header = records.takeAt(0);
QStringList headers = splitCSVLine(header);

QStringList splitCSVLine(const QString& line)
{
int inItem = false;
QStringList items;
QString item;

for (int pos = 0; pos < line.length(); pos++)
{
QChar c = line.at(pos);
if ( c == '\"') {
if (inItem) {
items.append(item);
item = "";
}
inItem = !inItem;
}
else
if (inItem)
item += c;
}
return items;
}