[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    PATCH: kspread html export
From:       Daniel Naber <daniel.naber () t-online ! de>
Date:       2001-07-28 23:03:50
[Download RAW message or body]

Hi,

can I commit this?

-escape <, > and & unless it is markup
-don't claim utf-8, because it isn't, at least with my tests?!
-don't miss pre/post texts
-do not skip *single* empty lines
-slightly better way to find a title

Regards
 Daniel

--=20
Daniel Naber, Paul-Gerhardt-Str. 2, 33332 Guetersloh, Germany
Tel. 05241-59371, Mobil 0170-4819674

["kspread-html-export.diff" (text/x-diff)]

Index: htmlexport.cc
===================================================================
RCS file: /home/kde/koffice/./filters/kspread/html/htmlexport.cc,v
retrieving revision 1.3
diff -u -r1.3 htmlexport.cc
--- htmlexport.cc	2001/06/29 00:42:54	1.3
+++ htmlexport.cc	2001/07/28 22:59:04
@@ -93,18 +93,19 @@
     QString title;
     KoDocumentInfo *info = document->documentInfo();
     KoDocumentInfoAbout *aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( \
                "about" ));
-    if ( !aboutPage )
-      title = file;
-    else
+    if ( aboutPage && !aboutPage->title().isEmpty() )
       title = aboutPage->title();
+    else
+      title = file;
     
     // 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 += "content=\"text/html; charset=UTF-8\">\n";
+    // FIXME (dnaber):
+    //str += "<meta http-equiv=\"Content-Type\" ";
+    //str += "content=\"text/html; charset=UTF-8\">\n";
     str += "<meta name=\"Generator\" ";
     str += "content=\"KSpread HTML Export Filter Version = 0.1 \">\n";
     // I have no idea where to get the document name from :-(  table->tableName()
@@ -163,6 +164,8 @@
 
       str += "<" + html_table_tag + html_table_options + ">\n";
     
+      unsigned int nonempty_cells_prev=0;
+
       for ( currentrow = 1 ; currentrow < iMaxUsedRow ; ++currentrow, ++i )
       {
         if(i>step) {
@@ -184,17 +187,22 @@
               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?!)
             switch( cell->content() ) {
                 case KSpreadCell::Text:
-                  text = cell->text();
+                  text = cell->prefix(currentrow, currentcolumn) + " " + \
cell->text() +  +		    + " " + cell->postfix(currentrow, currentcolumn);
                   break;
                 case KSpreadCell::RichText:   
                 case KSpreadCell::VisualFormula:
-                  text = cell->text(); // untested
+                  text = cell->prefix(currentrow, currentcolumn) + " " + \
cell->text() +  +		    + " " + cell->postfix(currentrow, currentcolumn);  // untested
                   break;
                 case KSpreadCell::Formula:
                   cell->calc( TRUE ); // Incredible, cells are not calculated if the \
                document was just opened
-                  text = cell->valueString();
+                  text = cell->prefix(currentrow, currentcolumn) + " " + \
cell->valueString(); +  +		    + " " + cell->postfix(currentrow, currentcolumn);
                   break;
             }
             line += "  <" + html_cell_tag + html_cell_options;
@@ -206,15 +214,29 @@
               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 {
+	      // Escape HTML characters. No need to be very efficient IMHO,
+	      // so use a RegExp:
+	      text.replace(QRegExp("&"), "&amp;");
+	      text.replace(QRegExp("<"), "&lt;");
+	      text.replace(QRegExp(">"), "&gt;");
             }
-            QString tmp;
             line += ">\n";
-            line += "  " + text;
+            line += "  " + text; 
             line += "\n  </" + html_cell_tag + ">\n";
         }
 
-        if (nonempty_cells>0)
-        {
+        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;


_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic