diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /filters/kspread/html | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'filters/kspread/html')
-rw-r--r-- | filters/kspread/html/CHANGELOG | 11 | ||||
-rw-r--r-- | filters/kspread/html/Makefile.am | 18 | ||||
-rw-r--r-- | filters/kspread/html/exportdialog.cc | 113 | ||||
-rw-r--r-- | filters/kspread/html/exportdialog.h | 63 | ||||
-rw-r--r-- | filters/kspread/html/exportwidget.ui | 310 | ||||
-rw-r--r-- | filters/kspread/html/htmlexport.cc | 475 | ||||
-rw-r--r-- | filters/kspread/html/htmlexport.h | 81 | ||||
-rw-r--r-- | filters/kspread/html/kspread_html_export.desktop | 72 | ||||
-rw-r--r-- | filters/kspread/html/status.html | 173 |
9 files changed, 1316 insertions, 0 deletions
diff --git a/filters/kspread/html/CHANGELOG b/filters/kspread/html/CHANGELOG new file mode 100644 index 00000000..0147160f --- /dev/null +++ b/filters/kspread/html/CHANGELOG @@ -0,0 +1,11 @@ +=== KOffice 1.4 === +- New configuration dialog to tweak HTML export +- Make borders optional +- Ability to select which sheets to be exported. +- Ability to write each table to a new page. +- A Table Of Contents is generated on top of each page. +- Choose the number of pixels between cells. +- Don't add one column and row too much. +- Don't export empty sheets. +- Let the user choose encoding. +- Linkage of external stylesheets.
\ No newline at end of file diff --git a/filters/kspread/html/Makefile.am b/filters/kspread/html/Makefile.am new file mode 100644 index 00000000..87018feb --- /dev/null +++ b/filters/kspread/html/Makefile.am @@ -0,0 +1,18 @@ +####### General stuff + +INCLUDES= -I$(srcdir) -I$(top_srcdir)/kspread $(KOFFICE_INCLUDES) \ + $(KOTEXT_INCLUDES) $(all_includes) + +####### Files + +kde_module_LTLIBRARIES = libkspreadhtmlexport.la + +libkspreadhtmlexport_la_SOURCES = htmlexport.cc exportdialog.cc exportwidget.ui +libkspreadhtmlexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +libkspreadhtmlexport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la + +METASOURCES = AUTO + +service_DATA = kspread_html_export.desktop + +servicedir = $(kde_servicesdir) diff --git a/filters/kspread/html/exportdialog.cc b/filters/kspread/html/exportdialog.cc new file mode 100644 index 00000000..78276def --- /dev/null +++ b/filters/kspread/html/exportdialog.cc @@ -0,0 +1,113 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Bram Schoenmakers <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <qcheckbox.h> +#include <qcombobox.h> +#include <qlistbox.h> +#include <qradiobutton.h> +#include <qspinbox.h> +#include <qtextcodec.h> + +#include <kapplication.h> +#include <kglobal.h> +#include <klocale.h> +#include <kurlrequester.h> + +#include <exportdialog.h> +#include <exportwidget.h> + +ExportDialog::ExportDialog( QWidget *parent, const char *name ) + : KDialogBase( parent, name, true, i18n("Export Sheet to HTML"), Ok|Cancel, No, true ), m_mainwidget( new ExportWidget( this ) ) +{ + kapp->restoreOverrideCursor(); + + connect( m_mainwidget->mCustomButton, SIGNAL( toggled( bool ) ), + m_mainwidget->mCustomURL, SLOT( setEnabled( bool ) ) ); + connect( m_mainwidget->mSelectAllButton, SIGNAL( clicked() ), SLOT( selectAll() ) ); + connect( m_mainwidget->mDeselectAllButton, SIGNAL( clicked() ), + m_mainwidget->mSheets, SLOT( clearSelection() ) ); + + m_mainwidget->mEncodingBox->insertItem( i18n( "Recommended: UTF-8" ) ); + m_mainwidget->mEncodingBox->insertItem( i18n( "Locale (%1)" ).arg( KGlobal::locale()->codecForEncoding()->name() ) ); + + m_mainwidget->mCustomURL->setMode( KFile::ExistingOnly ); + + setMainWidget( m_mainwidget ); +} + +void ExportDialog::selectAll() +{ + m_mainwidget->mSheets->selectAll( true ); +} + +ExportDialog::~ExportDialog() +{ + kapp->setOverrideCursor(Qt::waitCursor); +} + +QTextCodec *ExportDialog::encoding() const +{ + if( m_mainwidget->mEncodingBox->currentItem() == 1 ) // locale selected + return KGlobal::locale()->codecForEncoding(); + + return QTextCodec::codecForName( "utf8" ); // utf8 is default +} + +bool ExportDialog::useBorders() const +{ + return m_mainwidget->mUseBorders->isChecked(); +} + +bool ExportDialog::separateFiles() const +{ + return m_mainwidget->mSeparateFiles->isChecked(); +} + +QString ExportDialog::customStyleURL() const +{ + QString url = m_mainwidget->mCustomURL->url(); + if( m_mainwidget->mCustomButton->isChecked() && KURL( url ).isValid() ) + return url; + + return QString::null; +} + +void ExportDialog::setSheets( const QStringList &list ) +{ + m_mainwidget->mSheets->insertStringList( list ); + selectAll(); +} + +QStringList ExportDialog::sheets() const +{ + QStringList list; + for( uint i = 0; i < m_mainwidget->mSheets->count() ; i++ ) + { + if( m_mainwidget->mSheets->isSelected( i ) ) + list.append( m_mainwidget->mSheets->text( i ) ); + } + return list; +} + +int ExportDialog::pixelsBetweenCells() const +{ + return m_mainwidget->mPixelsBetweenCells->value(); +} + +#include <exportdialog.moc> diff --git a/filters/kspread/html/exportdialog.h b/filters/kspread/html/exportdialog.h new file mode 100644 index 00000000..4a460554 --- /dev/null +++ b/filters/kspread/html/exportdialog.h @@ -0,0 +1,63 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Bram Schoenmakers <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef EXPORTDIALOG_H +#define EXPORTDIALOG_H + +#include <kdialogbase.h> + +class ExportWidget; + +class ExportDialog : public KDialogBase +{ + Q_OBJECT + public: + ExportDialog( QWidget *parent = 0, const char *name = 0 ); + ~ExportDialog(); + + void setSheets( const QStringList & ); + QStringList sheets() const; + + /** + Returns preferred encoding. Defaults to UTF-8. + */ + QTextCodec *encoding() const; + + /** + Returns a valid URL if the custom button was selected. + Else, it will return QString::null. + */ + QString customStyleURL() const; + + /** + Returns true if borders should be shown, false if borders + should be hidden. + */ + bool useBorders() const; + + bool separateFiles() const; + + int pixelsBetweenCells() const; + protected slots: + void selectAll(); + private: + ExportWidget *m_mainwidget; +}; + +#endif diff --git a/filters/kspread/html/exportwidget.ui b/filters/kspread/html/exportwidget.ui new file mode 100644 index 00000000..d81ef40b --- /dev/null +++ b/filters/kspread/html/exportwidget.ui @@ -0,0 +1,310 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>ExportWidget</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ExportWidget</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>256</width> + <height>413</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>En&coding:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mEncodingBox</cstring> + </property> + </widget> + <widget class="QComboBox"> + <property name="name"> + <cstring>mEncodingBox</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string>With this option you can define the encoding of the HTML file. The recommended encoding (UTF8) is selected as default.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox3</cstring> + </property> + <property name="title"> + <string>Sheet Selection</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QListBox"> + <property name="name"> + <cstring>mSheets</cstring> + </property> + <property name="selectionMode"> + <enum>Multi</enum> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>mSelectAllButton</cstring> + </property> + <property name="text"> + <string>Select &All</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to select all sheets in the list.</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>mDeselectAllButton</cstring> + </property> + <property name="text"> + <string>Desele&ct All</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to select all sheets in the list.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>330</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>mSeparateFiles</cstring> + </property> + <property name="text"> + <string>Use &separate files for each table</string> + </property> + <property name="whatsThis" stdset="0"> + <string>This option will make the HTML export filter generate a new page for each sheet. If you disable this option, all sheets are written on one page.</string> + </property> + </widget> + </vbox> + </widget> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>buttonGroup4</cstring> + </property> + <property name="title"> + <string>Style</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>mDefaultButton</cstring> + </property> + <property name="text"> + <string>Use &default style</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="whatsThis" stdset="0"> + <string>Select this option to use the default fonts and colors for the HTML page.</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>mCustomButton</cstring> + </property> + <property name="text"> + <string>Use &external stylesheet:</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Select this option to specify a separate stylesheet for the HTML page. You can select or type on in the field below.</string> + </property> + </widget> + <widget class="KURLRequester"> + <property name="name"> + <cstring>mCustomURL</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="whatsThis" stdset="0"> + <string>In this field you can enter an URL for your stylesheet. It is possible to point to a stylesheet on disk, or to somewhere on the Internet.</string> + </property> + </widget> + </vbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox2</cstring> + </property> + <property name="title"> + <string>Layout</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>mUseBorders</cstring> + </property> + <property name="text"> + <string>Use &borders</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="whatsThis" stdset="0"> + <string>Use this option to enable or disable borders around the cells.</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="text"> + <string>Pi&xels between cells:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mPixelsBetweenCells</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string>Use this option to define how many pixels there should be between the cells. This effect is better visible if you check <b>Use borders</b> too.</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>mPixelsBetweenCells</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maxValue"> + <number>25</number> + </property> + <property name="whatsThis" stdset="0"> + <string>Use this option to define how many pixels there should be between the cells. This effect is better visible if you check <b>Use borders</b> too.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer5_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer5</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kurlrequester.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/filters/kspread/html/htmlexport.cc b/filters/kspread/html/htmlexport.cc new file mode 100644 index 00000000..76c6ee83 --- /dev/null +++ b/filters/kspread/html/htmlexport.cc @@ -0,0 +1,475 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Eva Brucherseifer <[email protected]> + Copyright (C) 2005 Bram Schoenmakers <[email protected]> + based on kspread csv export filter by David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <htmlexport.h> +#include <exportdialog.h> + +#include <qfile.h> +#include <qtextcodec.h> + +#include <kdebug.h> +#include <kgenericfactory.h> +#include <KoFilterChain.h> +#include <KoDocumentInfo.h> +#include <kofficeversion.h> + +#include <kspread_map.h> +#include <kspread_sheet.h> +#include <kspread_doc.h> +#include <kspread_util.h> + +using namespace KSpread; + +typedef KGenericFactory<HTMLExport, KoFilter> HTMLExportFactory; +K_EXPORT_COMPONENT_FACTORY( libkspreadhtmlexport, HTMLExportFactory( "kofficefilters" ) ) + +const QString html_table_tag = "table"; +const QString html_table_options = QString(" border=\"%1\" cellspacing=\"%2\""); +const QString html_row_tag = "tr"; +const QString html_row_options = ""; +const QString html_cell_tag = "td"; +const QString html_cell_options = ""; +const QString html_bold = "b"; +const QString html_italic = "i"; +const QString html_underline = "u"; +const QString html_right= "right"; +const QString html_left= "left"; +const QString html_center= "center"; +const QString html_top="top"; +const QString html_bottom="bottom"; +const QString html_middle="middle"; +const QString html_h1="h1"; + +HTMLExport::HTMLExport(KoFilter *, const char *, const QStringList&) : + KoFilter(), m_dialog( new ExportDialog() ) +{ +} + +HTMLExport::~HTMLExport() +{ + delete m_dialog; +} + +// HTML enitities, AFAIK we don't need to escape " to " (dnaber): +const QString strAmp ("&"); +const QString nbsp (" "); +const QString strLt ("<"); +const QString strGt (">"); + +// The reason why we use the KoDocument* approach and not the QDomDocument +// approach is because we don't want to export formulas but values ! +KoFilter::ConversionStatus HTMLExport::convert( const QCString& from, const QCString& to ) +{ + if(to!="text/html" || from!="application/x-kspread") + { + kdWarning(30501) << "Invalid mimetypes " << to << " " << from << endl; + return KoFilter::NotImplemented; + } + + KoDocument* document = m_chain->inputDocument(); + + if ( !document ) + return KoFilter::StupidError; + + if( !::qt_cast<const KSpread::Doc *>( document ) ) // it's safer that way :) + { + kdWarning(30501) << "document isn't a KSpread::Doc but a " << document->className() << endl; + return KoFilter::NotImplemented; + } + + const Doc * ksdoc=static_cast<const Doc *>(document); + + if( ksdoc->mimeType() != "application/x-kspread" ) + { + kdWarning(30501) << "Invalid document mimetype " << ksdoc->mimeType() << endl; + return KoFilter::NotImplemented; + } + + Sheet *sheet = ksdoc->map()->firstSheet(); + QString filenameBase = m_chain->outputFile(); + filenameBase = filenameBase.left( filenameBase.findRev( '.' ) ); + + QStringList sheets; + while( sheet != 0 ) + { + int rows = 0; + int columns = 0; + detectFilledCells( sheet, rows, columns ); + m_rowmap[ sheet->sheetName() ] = rows; + m_columnmap[ sheet->sheetName() ] = columns; + + if( rows > 0 && columns > 0 ) + { + sheets.append( sheet->sheetName() ); + } + sheet = ksdoc->map()->nextSheet(); + } + m_dialog->setSheets( sheets ); + + if( m_dialog->exec() == QDialog::Rejected ) + return KoFilter::UserCancelled; + + sheets = m_dialog->sheets(); + QString str; + for( uint i = 0; i < sheets.count() ; ++i ) + { + sheet = ksdoc->map()->findSheet( sheets[i] ); + + QString file = fileName( filenameBase, sheet->sheetName(), sheets.count() > 1 ); + + if( m_dialog->separateFiles() || sheets[i] == sheets.first() ) + { + str = QString::null; + openPage( sheet, document, str ); + writeTOC( sheets, filenameBase, str ); + } + + convertSheet( sheet, str, m_rowmap[ sheet->sheetName() ], m_columnmap[ sheet->sheetName() ] ); + + if( m_dialog->separateFiles() || sheets[i] == sheets.last() ) + { + closePage( str ); + QFile out(file); + if(!out.open(IO_WriteOnly)) { + kdError(30501) << "Unable to open output file!" << endl; + out.close(); + return KoFilter::FileNotFound; + } + QTextStream streamOut(&out); + streamOut.setCodec( m_dialog->encoding() ); + streamOut << str << endl; + out.close(); + } + + if( !m_dialog->separateFiles() ) + { + createSheetSeparator( str ); + } + + } + + emit sigProgress(100); + return KoFilter::OK; +} + +void HTMLExport::openPage( Sheet *sheet, KoDocument *document, QString &str ) +{ + QString title; + KoDocumentInfo *info = document->documentInfo(); + KoDocumentInfoAbout *aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" )); + if ( aboutPage && !aboutPage->title().isEmpty() ) + title = aboutPage->title() + " - "; + + title += sheet->sheetName(); + + // header + str = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "; + str += " \"http://www.w3.org/TR/html4/loose.dtd\"> \n"; + str += "<html>\n"; + str += "<head>\n"; + str += "<meta http-equiv=\"Content-Type\" "; + str += QString("content=\"text/html; charset=%1\">\n").arg( m_dialog->encoding()->mimeName() ); + str += "<meta name=\"Generator\" "; + str += "content=\"KSpread HTML Export Filter Version = "; + str += KOFFICE_VERSION_STRING; + str += "\">\n"; + + // Insert stylesheet + if( !m_dialog->customStyleURL().isEmpty() ) + { + str += "<link ref=\"stylesheet\" type=\"text/css\" href=\""; + str += m_dialog->customStyleURL(); + str += "\" title=\"Style\" >\n"; + } + + str += "<title>" + title + "</title>\n"; + str += "</head>\n"; + str += QString("<body bgcolor=\"#FFFFFF\" dir=\"%1\">\n").arg( + sheet->isRightToLeft()?"rtl":"ltr"); + + str += "<a name=\"__top\">\n"; +} + +void HTMLExport::closePage( QString &str ) +{ + str += "<p align=\"" + html_center + "\"><a href=\"#__top\">" + i18n("Top") + "</a></p>\n"; + str += "</body>\n"; + str += "</html>\n\n"; +} + +void HTMLExport::convertSheet( Sheet *sheet, QString &str, int iMaxUsedRow, int iMaxUsedColumn ) +{ + QString emptyLines; + + // Either we get hold of KSpreadTable::m_dctCells and apply the old method below (for sorting) + // or, cleaner and already sorted, we use KSpreadTable's API (slower probably, though) + int iMaxRow = sheet->maxRow(); + + if( !m_dialog->separateFiles() ) + str += "<a name=\"" + sheet->sheetName().lower().stripWhiteSpace() + "\">\n"; + + str += ("<h1>" + sheet->sheetName() + "</h1><br>\n"); + + // this is just a bad approximation which fails for documents with less than 50 rows, but + // we don't need any progress stuff there anyway :) (Werner) + int value=0; + int step=iMaxRow > 50 ? iMaxRow/50 : 1; + int i=1; + + str += "<" + html_table_tag + html_table_options.arg( m_dialog->useBorders() ? "1" : "0" ).arg( m_dialog->pixelsBetweenCells() ) + + QString("dir=\"%1\">\n").arg(sheet->isRightToLeft()?"rtl":"ltr"); + + unsigned int nonempty_cells_prev=0; + + for ( int currentrow = 1 ; currentrow <= iMaxUsedRow ; ++currentrow, ++i ) + { + if(i>step) { + value+=2; + emit sigProgress(value); + i=0; + } + + QString separators; + QString line; + unsigned int nonempty_cells=0; + unsigned int colspan_cells=0; + + for ( int currentcolumn = 1 ; currentcolumn <= iMaxUsedColumn ; currentcolumn++ ) + { + Cell * cell = sheet->cellAt( currentcolumn, currentrow, false ); + colspan_cells=cell->extraXCells(); + if (cell->needsPrinting()) + nonempty_cells++; + QString text; + QColor bgcolor = cell->bgColor(currentcolumn,currentrow); + // FIXME: some formatting seems to be missing with cell->text(), e.g. + // "208.00" in KSpread will be "208" in HTML (not always?!) + bool link = false; + + if ( !cell->link().isEmpty() ) + { + if ( localReferenceAnchor(cell->link()) ) + { + text = cell->text(); + } + else + { + text = " <A href=\"" + cell->link() + "\">" + cell->text() + "</A>"; + link = true; + } + } + else + text=cell->strOutText(); +#if 0 + switch( cell->content() ) { + case Cell::Text: + text = cell->text(); + break; + case Cell::RichText: + case Cell::VisualFormula: + text = cell->text(); // untested + break; + case Cell::Formula: + cell->calc( TRUE ); // Incredible, cells are not calculated if the document was just opened + text = cell->valueString(); + break; + } + text = cell->prefix(currentrow, currentcolumn) + " " + text + " " + + cell->postfix(currentrow, currentcolumn); +#endif + line += " <" + html_cell_tag + html_cell_options; + if (text.isRightToLeft() != sheet->isRightToLeft()) + line += QString(" dir=\"%1\" ").arg(text.isRightToLeft()?"rtl":"ltr"); + if (bgcolor.isValid() && bgcolor.name()!="#ffffff") // change color only for non-white cells + line += " bgcolor=\"" + bgcolor.name() + "\""; + + switch((Format::Align)cell->defineAlignX()) + { + case Format::Left: + line+=" align=\"" + html_left +"\""; + break; + case Format::Right: + line+=" align=\"" + html_right +"\""; + break; + case Format::Center: + line+=" align=\"" + html_center +"\""; + break; + case Format::Undefined: + break; + } + switch((Format::AlignY)cell-> format()->alignY(currentrow, currentcolumn)) + { + case Format::Top: + line+=" valign=\"" + html_top +"\""; + break; + case Format::Middle: + line+=" valign=\"" + html_middle +"\""; + break; + case Format::Bottom: + line+=" valign=\"" + html_bottom +"\""; + break; + case Format::UndefinedY: + break; + } + line+=" width=\""+QString::number(cell->width())+"\""; + line+=" height=\""+QString::number(cell->height())+"\""; + + if (cell->extraXCells()>0) + { + QString tmp; + int extra_cells=cell->extraXCells(); + line += " colspan=\"" + tmp.setNum(extra_cells+1) + "\""; + currentcolumn += extra_cells; + } + text = text.stripWhiteSpace(); + if( text.at(0) == '!' ) { + // this is supposed to be markup, just remove the '!': + text = text.right(text.length()-1); + } else if ( !link ) { + // Escape HTML characters. + text.replace ('&' , strAmp) + .replace ('<' , strLt) + .replace ('>' , strGt) + .replace (' ' , nbsp); + } + line += ">\n"; + + if (cell->format()->textFontBold(currentcolumn,currentrow)) + { + text.insert(0, "<" + html_bold + ">"); + text.append("</" + html_bold + ">"); + } + if (cell->format()->textFontItalic(currentcolumn,currentrow)) + { + text.insert(0, "<" + html_italic + ">"); + text.append("</" + html_italic + ">"); + } + if (cell->format()->textFontUnderline(currentcolumn,currentrow)) + { + text.insert(0, "<" + html_underline + ">"); + text.append("</" + html_underline + ">"); + } + QColor textColor = cell->format()->textColor(currentcolumn,currentrow); + if (textColor.isValid() && textColor.name()!="#000000") // change color only for non-default text + { + text.insert(0, "<font color=\"" + textColor.name() + "\">"); + text.append("</font>"); + } + line += " " + text; + line += "\n </" + html_cell_tag + ">\n"; + } + + if (nonempty_cells == 0 && nonempty_cells_prev == 0) { + nonempty_cells_prev = nonempty_cells; + // skip line if there's more than one empty line + continue; + } else { + nonempty_cells_prev = nonempty_cells; + str += emptyLines; + str += "<" + html_row_tag + html_row_options + ">\n"; + str += line; + str += "</" + html_row_tag + ">"; + emptyLines = QString::null; + // Append a CR, but in a temp string -> if no other real line, + // then those will be dropped + emptyLines += "\n"; + } + } + str += "\n</" + html_table_tag + ">\n<br>\n"; +} + +void HTMLExport::createSheetSeparator( QString &str ) +{ + str += ("<p align=\"" + html_center + "\"><a href=\"#__top\">" + i18n("Top") + "</a></p>\n" ); + str += "<hr width=\"80%\">\n"; +} + +void HTMLExport::writeTOC( const QStringList &sheets, const QString &base, QString &str ) +{ + // don't create TOC for 1 sheet + if( sheets.count() == 1 ) + return; + + str += "<p align=\"" + html_center + "\">\n"; + + for( uint i = 0 ; i < sheets.count() ; ++i ) + { + str += "<a href=\""; + + if( m_dialog->separateFiles() ) + { + str += fileName( base, sheets[i], sheets.count() > 1 ); + } + else + { + str += "#" + sheets[i].lower().stripWhiteSpace(); + } + + str += "\">" + sheets[i] + "</a>\n"; + if( i != sheets.count() -1 ) + str += " - "; + } + + str += "</p><hr width=\"80%\">\n"; +} + +QString HTMLExport::fileName( const QString &base, const QString &sheetName, bool multipleFiles ) +{ + QString fileName = base; + if( m_dialog->separateFiles() && multipleFiles ) + { + fileName += "-" + sheetName; + } + fileName += ".html"; + + return fileName; +} + +void HTMLExport::detectFilledCells( Sheet *sheet, int &rows, int &columns ) +{ + int iMaxColumn = sheet->maxColumn(); + int iMaxRow = sheet->maxRow(); + rows = 0; + columns = 0; + + for ( int currentrow = 1 ; currentrow <= iMaxRow ; ++currentrow) + { + Cell * cell = 0L; + int iUsedColumn=0; + for ( int currentcolumn = 1 ; currentcolumn <= iMaxColumn ; currentcolumn++ ) + { + cell = sheet->cellAt( currentcolumn, currentrow, false ); + QString text; + if ( !cell->isDefault() && !cell->isEmpty() ) + { + iUsedColumn = currentcolumn; + } + } + if (cell) + iUsedColumn += cell->extraXCells(); + if (iUsedColumn > columns) + columns = iUsedColumn; + if ( iUsedColumn > 0 ) + rows = currentrow; + } +} + +#include <htmlexport.moc> diff --git a/filters/kspread/html/htmlexport.h b/filters/kspread/html/htmlexport.h new file mode 100644 index 00000000..1952c9af --- /dev/null +++ b/filters/kspread/html/htmlexport.h @@ -0,0 +1,81 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Eva Brucherseifer <[email protected]> + Copyright (C) 2005 Bram Schoenmakers <[email protected]> + based on kspread csv export filter by David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef HTMLEXPORT_TEST_H +#define HTMLEXPORT_TEST_H + +#include <KoFilter.h> + +class ExportDialog; +class KoDocument; + +namespace KSpread +{ +class Sheet; +} + +class HTMLExport : public KoFilter { + Q_OBJECT +public: + HTMLExport(KoFilter *parent, const char*name, const QStringList&); + virtual ~HTMLExport(); + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); + private: + /** Writes the top of the page in HTML to @par str */ + void openPage( KSpread::Sheet *sheet,KoDocument *document, QString &str); + + /** Closes a page in HTML */ + void closePage( QString &); + + /** + Converts @par sheet to HTML and writes to @par str. + */ + void convertSheet( KSpread::Sheet *sheet, QString &str, int, int); + + /** Writes a bar and a link to the top to @par str. */ + void createSheetSeparator( QString & ); + + /** Writes the table of contents */ + void writeTOC( const QStringList &, const QString &, QString & ); + + /** + Returns a filename based on the @par base filename and the options + defined in the dialog. + */ + QString fileName( const QString &base, const QString &, bool ); + + /** + Detects which rows and columsn of the given @par sheet are used and + writes the number of them to @par row and @par column. + */ + void detectFilledCells( KSpread::Sheet *sheet, int &rows, int &colums ); + private: + ExportDialog *m_dialog; + + typedef QMap<QString,int> Rows; + Rows m_rowmap; + typedef QMap<QString,int> Columns; + Columns m_columnmap; +}; + +#endif + diff --git a/filters/kspread/html/kspread_html_export.desktop b/filters/kspread/html/kspread_html_export.desktop new file mode 100644 index 00000000..7164cf9a --- /dev/null +++ b/filters/kspread/html/kspread_html_export.desktop @@ -0,0 +1,72 @@ +[Desktop Entry] +Type=Service +Name=HTML Export Filter for KSpread +Name[af]=Html Voer uit Filter vir Kspread +Name[ar]=مِرْشَح تصدير HTML لدى KSpread +Name[az]=KSpread üçün HTML Vermə Süzgəci +Name[bg]=Филтър за експортиране от KSpread в HTML +Name[br]=Sil ezporzh HTML evit KSpread +Name[bs]=HTML Export Filter za KSpread +Name[ca]=Filtre d'exportació HTML per a KSpread +Name[cs]=HTML exportní filtr pro KSpread +Name[cy]=Hidlen Allforio HTML i KSpread +Name[da]=HTML-eksportfilter for KSpread +Name[de]=KSpread HTML-Exportfilter +Name[el]=Φίλτρο εξαγωγής HTML για το KSpread +Name[eo]=HTML-eksportfiltrilo por KSpread +Name[es]=Filtro de exportación HTML para KSpread +Name[et]=KSpreadi HTML-i ekspordifilter +Name[eu]=KSpread-en HTML esportaziorako iragazkia +Name[fa]=پالایۀ صادرات زنگام برای KSpread +Name[fi]=HTML-vientisuodin KSpeadiin +Name[fr]=Filtre d'exportation HTML de KSpread +Name[fy]=HTML-Eksportfilter foar KSpread +Name[ga]=Scagaire Easpórtála HTML le haghaidh KSpread +Name[gl]=Filtro de Exportación de HTML para KSpread +Name[he]=מסנן ייצוא מ־KSpread ל־HTML +Name[hi]=के-स्प्रेड के लिए एचटीएमएल निर्यात छननी +Name[hr]=HTML filtar izvoza za KSpread +Name[hu]=HTML exportszűrő a KSpreadhez +Name[is]=HTML útflutningssía fyrir KSpread +Name[it]=Filtro di esportazione HTML per KSpread +Name[ja]=KSpread HTML エクスポートフィルタ +Name[km]=តម្រងនាំចេញ HTML សម្រាប់ KSpread +Name[lo]= ຕົວຕອງການສົ່ງອອກ HTML ຂອງກະດາດຄຳນວນ K +Name[lt]=HTML eksporto filtras skirtas KSpread +Name[lv]=HTML eksporta filtrs priekš KSpread +Name[ms]=Penapis Eksport HTML bagi KSpread +Name[mt]=Filtru għall-esportazzjoni ta' fajls HTML minn ġo KSpread +Name[nb]=HTML-eksportfilter for KSpread +Name[nds]=HTML-Exportfilter för KSpread +Name[ne]=केडीई स्प्रिेडका लागि एचटीएमएल निर्यात फिल्टर +Name[nl]=HTML-Exportfilter voor KSpread +Name[nn]=HTML-eksportfilter for KSpread +Name[pl]=Filtr eksportu do formatu HTML dla KSpread +Name[pt]=Filtro de Exportação de HTML para o KSpread +Name[pt_BR]=Filtro de Exportação HTML para o KSpread +Name[ro]=Filtru exportare KSpread pentru HTML +Name[ru]=Фильтр экспорта таблиц KSpread в HTML +Name[se]=KSpread:a HTML-olggosfievrridansilli +Name[sk]=HTML filter pre export z KSpread +Name[sl]=Izvozni filter HTML za Kspread +Name[sr]=KSpread-ов филтер за извоз у HTML +Name[sr@Latn]=KSpread-ov filter za izvoz u HTML +Name[sv]=HTML-exportfilter för Kspread +Name[ta]=KSpread HTML ஏற்றுமதி வடிகட்டி +Name[tg]=Филтри Содироти HTML барои KSpread +Name[th]=ตัวกรองการส่งออก HTML ของกระดาษคำนวณ K +Name[tr]=KSpread için HTML Aktarma Filtresi +Name[uk]=Фільтр експорту HTML для KSpread +Name[uz]=KSpread uchun HTML eksport filteri +Name[uz@cyrillic]=KSpread учун HTML экспорт филтери +Name[ven]=Filithara yau u bvisela nga nnda ya HTML ya u phadaladza ha K +Name[wa]=Passete HTML di rexhowe po KSpread +Name[xh]=HTML Yesihluzi Sokurhweba ngaphandle se KSpread +Name[zh_CN]=KSpread 的 HTML 导出过滤器 +Name[zh_TW]=KSpread 的 HTML 匯出過濾程式 +Name[zu]=HTML IceboExport Filter for KSpread +X-KDE-Export=text/html +X-KDE-Import=application/x-kspread +X-KDE-Weight=50 +X-KDE-Library=libkspreadhtmlexport +ServiceTypes=KOfficeFilter diff --git a/filters/kspread/html/status.html b/filters/kspread/html/status.html new file mode 100644 index 00000000..a625bfd2 --- /dev/null +++ b/filters/kspread/html/status.html @@ -0,0 +1,173 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <title>KOffice filters status: HTML FILTER</title> +</head> +<body text="#000000" bgcolor="#FFFFFF" link="#000099" vlink="#666666" alink="#666666"> +<A NAME="START"> </A> + +<BR> +<center> + <h1> + KOffice filters status: <i>HTML - Hypertext Markup Language</i> + </h1> +</center> + +<hr NOSHADE SIZE=2 WIDTH="70%"> + +<font size="-1"><b> + <A HREF="#import">Import</A> | + <A HREF="#export">Export</A> +</b></font> + +<BR><BR><BR> +<center><a NAME="import"></a></center> + +<A HREF="#START"><font size="-1"><b>Up</b></font></A> +<center> +<table BORDER=0 CELLSPACING=0 BGCOLOR="#000000" WIDTH="100%"> + <tr> + <td> + <table BORDER=0 CELLPADDING=2 BGCOLOR="#FFFFFF" WIDTH="100%"> + + <tr BGCOLOR="#DDFFDD"> + <td COLSPAN="2"> + <center><b><i><font size="+1"> + <BR> + Import HTML for kspread<BR> + <BR> + </font></i></b></center> + </td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP WIDTH="1%" NOWRAP><b><font size="+1">Last update</font></b></td> + <td>?</td> + </tr> + + <tr BGCOLOR="#CCCCFF"> + <td VALIGN=TOP><b><font size="+1">Features</font></b></td> + <td>? </td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP><b><font size="+1">Todo</font></b></td> + <td> + ? + </td> + </tr> + + <tr BGCOLOR="#CCCCFF"> + <td VALIGN=TOP><b><font size="+1">History</font></b></td> + <td>?</td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP><b><font size="+1">Authors</font></b></td> + <td>?</td> + </tr> + + <tr BGCOLOR="#CCCCFF"> + <td VALIGN=TOP><b><font size="+1">Links</font></b></td> + <td>?</td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP><b><font size="+1">Progress report </font></b></td> + <td>?</td> + </tr> + </table> + </td> + </tr> +</table> +</center> +<A HREF="#START"><font size="-1"><b>Up</b></font></A> + +<br><br><br> + +<hr NOSHADE SIZE=1> +<br><br><br> + + +<center> + <a NAME="export"></a> +</center> + +<A HREF="#START"><font size="-1"><b>Up</b></font></A> +<center> +<table BORDER=0 CELLSPACING=0 BGCOLOR="#000000" WIDTH="100%"> + <tr> + <td> + <table BORDER=0 CELLPADDING=2 BGCOLOR="#FFFFFF" WIDTH="100%"> + <tr BGCOLOR="#FFDDDD"> + <td COLSPAN="2"> + <center><b><i><font size="+1"> + <BR>Export kspread to HTML<BR><BR> + </font></i></b></center> + </td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP WIDTH="1%" NOWRAP><b><font size="+1">Last update</font></b></td> + <td>7 April 2005 by Bram Schoenmakers</td> + </tr> + + <tr BGCOLOR="#CCCCFF"> + <td VALIGN=TOP><b><font size="+1">Features</font></b></td> + <td> + <ul> + <li> User can select which sheet(s) to export</li> + <li>Borders are optional</li> + <li>Cell spacing is configurable</li> + <li>Background color cells</li> + <li>Cell width/height</li> + <li>Option between all-in-one page or one sheet per page</li> + <li>User can select encoding</li> + </ul> + </td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP><b><font size="+1">Todo</font></b></td> + <td> <ul> + <li>Text fonts</li> + <li>Row-/colspan cells</li> + </ul> + </td> + </tr> + + <tr BGCOLOR="#CCCCFF"> + <td VALIGN=TOP><b><font size="+1">History</font></b></td> + <td>-</td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP><b><font size="+1">Authors</font></b></td> + <td> + <A HREF="mailto:[email protected]">Eva Brucherseifer</A> <br> + <A HREF="mailto:[email protected]">Bram Schoenmakers</A><br> + This filter is based on the CSV filter by + <A HREF="mailto:[email protected]">David Faure</A> and + <A HREF="mailto:[email protected]">Werner Trobin.</A> + </td> + </tr> + + <tr BGCOLOR="#CCCCFF"> + <td VALIGN=TOP><b><font size="+1">Links</font></b></td> + <td>-</td> + </tr> + + <tr BGCOLOR="#EEEEFF"> + <td VALIGN=TOP><b><font size="+1">Progress report </font></b></td> + <td>---</td> + </tr> + </table> + </td> + </tr> +</table> +</center> +<A HREF="#START"><font size="-1"><b>Up</b></font></A> + +</body> +</html> |