LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2009, 02:00 PM   #1
Inbhir Pheofharain
LQ Newbie
 
Registered: May 2009
Location: Edinburgh, Scotland
Distribution: Ubuntu
Posts: 15

Rep: Reputation: 0
Exclamation HTML Table Formatting


Can anyone advise what's the best way to go about my scenario here.

I basically have a database (an excel spreadsheet) and want to save as HTML (for putting on a web site) but one of the columns has 'Conditional Formatting'.

I do know that with HTML being a markup language only [not a programming language] that it can't handle this, but on the other hand I don't really want to learn javascript or php as I don't think I'll really need to (then again who knows?).

The conditional format only applies to one column and it changes the text colour depending whether the text is over 20 characters in length.

Can anyone help?

Last edited by Inbhir Pheofharain; 06-29-2009 at 02:01 PM. Reason: Spelling mistakes
 
Old 06-29-2009, 03:20 PM   #2
shane25119
Member
 
Registered: Aug 2003
Location: Illinois
Distribution: Linux Mint XFCE
Posts: 654

Rep: Reputation: 53
For such a simple scenario.... one column with a simple text color change attribute, I would look into php or javascript for just that one section. I used to have a website where I used simple javascript for putting the date on the bottom of the page and simple image changes on mouseover. Alas, I don't remember much from those quick forays into Javascript- but it won't be too involved of a process for you.
 
Old 06-30-2009, 08:30 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
How about using Excel (if possible, or load with Open-Office) to save the spreadsheet as HTML?
--- rod.
 
Old 07-01-2009, 12:55 AM   #4
Inbhir Pheofharain
LQ Newbie
 
Registered: May 2009
Location: Edinburgh, Scotland
Distribution: Ubuntu
Posts: 15

Original Poster
Rep: Reputation: 0
Wink

Quote:
Originally Posted by theNbomr View Post
How about using Excel (if possible, or load with Open-Office) to save the spreadsheet as HTML?
--- rod.
I tried that already, usin both Excel and OOo and it doesn't work
 
Old 07-01-2009, 11:51 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I have used OO to do what you are asking on several occasions, and it worked fine for me. Specifically, what aspect of the procedure did not work? Perhaps there is a simple second step that can be used to patch your output. Is this a 'dynamic' document, in the sense that the content is changing based on run-time parameters, or does the document get served as a static page? If the latter, how often does it need to be updated? It might be simple enough to fix it with a text editor, if the required changes are simple and/or infrequent.
--- rod.
 
Old 07-07-2009, 05:26 PM   #6
Inbhir Pheofharain
LQ Newbie
 
Registered: May 2009
Location: Edinburgh, Scotland
Distribution: Ubuntu
Posts: 15

Original Poster
Rep: Reputation: 0
Lightbulb

Quote:
Originally Posted by theNbomr View Post
I have used OO to do what you are asking on several occasions, and it worked fine for me. Specifically, what aspect of the procedure did not work? Perhaps there is a simple second step that can be used to patch your output. Is this a 'dynamic' document, in the sense that the content is changing based on run-time parameters, or does the document get served as a static page? If the latter, how often does it need to be updated? It might be simple enough to fix it with a text editor, if the required changes are simple and/or infrequent.
--- rod.

The Conditional Formatting carries over but it doesn't appear as a table.



I got the spreadsheet to appear as a table using the Concatenate function in Excel as explined here: http://designintellection.com/using-...les-and-forms/
(presumably OOo can do this as well) but the Conditional Formatting doesn't carry over when I do this.

So presumably I need to do some kind of 'if' statement in Excel/OOo?
 
Old 07-09-2009, 09:29 AM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, yes, I see that now. On the simple test that I tried, it seemed to use HTML styles to distinguish the various cell content. There are different styles named and attached to the table cells, but all of the styles have identical values. Perhaps a small sed/awk/perl script can be used to post-process the HTML, and apply appropriate values to the styles used.
--- rod.
 
Old 07-09-2009, 09:55 AM   #8
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by Inbhir Pheofharain View Post
Can anyone advise what's the best way to go about my scenario here.

I basically have a database (an excel spreadsheet) and want to save as HTML (for putting on a web site) but one of the columns has 'Conditional Formatting'.

I do know that with HTML being a markup language only [not a programming language] that it can't handle this, but on the other hand I don't really want to learn javascript or php as I don't think I'll really need to (then again who knows?).

The conditional format only applies to one column and it changes the text colour depending whether the text is over 20 characters in length.

Can anyone help?
Can you save as an html table without colors?
If you can, could you paste (with the html code)
here an excerpt, say 2 or 3 typical rows
and could you indicate which column is to have a different
color according to its text length
so I could have a look and see what are the possibilities
 
Old 07-12-2009, 05:08 PM   #9
Inbhir Pheofharain
LQ Newbie
 
Registered: May 2009
Location: Edinburgh, Scotland
Distribution: Ubuntu
Posts: 15

Original Poster
Rep: Reputation: 0
Talking

Yes, I can save to a table without colours by using the CONCATENATE function in Excel.

Here is a small sample of my table:

Code:
    <tr>
      <td><b>NLC    </b></td>
      <td><b>NAME (16 character)</b></th>
      <td><b>TOC or Business<b/></td>
      <td><b>Notes </b></td>
    </tr>

    <tr>
      <td>1003    </td>
      <td>    BESCOT STADIUM.    </td>
      <td>    LM    </td>
      <td>        </td>
      <td></td>
    </tr>

    <tr>
      <td>1004    </td>
      <td>    ASTON    </td>
      <td>    LM    </td>
      <td>        </td>
      <td></td>
    </tr>

    <tr>
      <td>1006    </td>
      <td>    BIRMINGHAM SN HL    </td>
      <td>    LM    </td>
      <td>    Was shown as BHAM SNOW HILL    </td>
      <td></td>
    </tr>

    <tr>
      <td>1010    </td>
      <td>    TAME BRIDGE PWY    </td>
      <td>    LM    </td>
      <td>        </td>
      <td></td>
    </tr>
Hope this helps....
 
Old 07-13-2009, 02:20 AM   #10
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by Inbhir Pheofharain View Post
Yes, I can save to a table without colours by using the CONCATENATE function in Excel.

Here is a small sample of my table:

Code:
    <tr>
      <td>1006    </td>
      <td>    BIRMINGHAM SN HL    </td>
      <td>    LM    </td>
      <td>    Was shown as BHAM SNOW HILL    </td>
      <td></td>
    </tr>
Hope this helps....
I take it, it's the 4th column that should be colored if
the text is more that 20 characters.

Off the bat, I'd say it should be possible to do it:
1. save as html without colors
2. write a stylesheet 'style.css' where you'd have something like
...
.long { color: #ff0000; }
...
or whatever color you want
write a sed script and run it on the html file and output
a new html file that includes the stylesheet and for every
entry '<td>...</td>' (in the 4th column) that has 20 characters or
more, replace '<td>' by '<td class=long>'

I'll play with it a bit and will get back to you

ok, here we go:

copy and paste the following into a file that you can
name 'seder.sed'
######### cut and paste below this line #######
#!/bin/sed -f

:loop
N
$!b loop

s?<[tT][dD][^>]*>?<td>?g
s?</[tT][dD]>?</td>?g
s?<[tT][rR][^>]*>?<tr>?g
s?</[tT][rR]>?</tr>?g
s?<[ \t\n]*/[ \t\n]*[hH][eE][aA][dD][^>]*>?</head>?

s?<td>[ \t\n\r]*?<td>?g
s?[ \t\n\r]*</td>?</td>?g

#this shouldn't be present
#but if there are, replace with the appropriate
#html code
s?±?__PLUSMINUS__?g
s?÷?__DIVISION__?g
s?¢?__CENT__?g
s?£?__POUND__?g

s?<tr>?±?g
s?</tr>?÷?g
s?<td>?¢?g
s?</td>?£?g

s?\(±[ \t\r\n]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*\)¢\([^£]\{20,\}£\)?\1<td class=long>\2?g

s?±?<tr>?g
s?÷?</tr>?g
s?¢?<td>?g
s?£?</td>?g

s?[ \t\r\n]*\(</head>\)?\
<style type=text/css>\
.long { color: #ff0000; }\
</style>\n\1?

######### end of copy ###############

now, make this script executable:
chmod +x seder.sed
and run it against your html file and redirect the
output to your new colorized html file:

./seder.sed your_input.html > output.html

note:
I'm too lazy to look up the relevant code for
± ÷ ¢ £
should they be present in your html file (they
shouldn't, but if they are, you should replace
__PLUSMINUS__
__DIVISION__
__CENT__
__POUND__
by the appropriate &#.... code)

Last edited by vonbiber; 07-13-2009 at 03:03 AM.
 
Old 07-13-2009, 04:57 PM   #11
Inbhir Pheofharain
LQ Newbie
 
Registered: May 2009
Location: Edinburgh, Scotland
Distribution: Ubuntu
Posts: 15

Original Poster
Rep: Reputation: 0
Talking

Quote:
Originally Posted by vonbiber View Post
I take it, it's the 4th column that should be colored if
the text is more that 20 characters.

Off the bat, I'd say it should be possible to do it:
1. save as html without colors
2. write a stylesheet 'style.css' where you'd have something like
...
.long { color: #ff0000; }
...
or whatever color you want
write a sed script and run it on the html file and output
a new html file that includes the stylesheet and for every
entry '<td>...</td>' (in the 4th column) that has 20 characters or
more, replace '<td>' by '<td class=long>'

I'll play with it a bit and will get back to you

ok, here we go:

copy and paste the following into a file that you can
name 'seder.sed'
######### cut and paste below this line #######
#!/bin/sed -f

:loop
N
$!b loop

s?<[tT][dD][^>]*>?<td>?g
s?</[tT][dD]>?</td>?g
s?<[tT][rR][^>]*>?<tr>?g
s?</[tT][rR]>?</tr>?g
s?<[ \t\n]*/[ \t\n]*[hH][eE][aA][dD][^>]*>?</head>?

s?<td>[ \t\n\r]*?<td>?g
s?[ \t\n\r]*</td>?</td>?g

#this shouldn't be present
#but if there are, replace with the appropriate
#html code
s?±?__PLUSMINUS__?g
s?÷?__DIVISION__?g
s?¢?__CENT__?g
s?£?__POUND__?g

s?<tr>?±?g
s?</tr>?÷?g
s?<td>?¢?g
s?</td>?£?g

s?\(±[ \t\r\n]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*\)¢\([^£]\{20,\}£\)?\1<td class=long>\2?g

s?±?<tr>?g
s?÷?</tr>?g
s?¢?<td>?g
s?£?</td>?g

s?[ \t\r\n]*\(</head>\)?\
<style type=text/css>\
.long { color: #ff0000; }\
</style>\n\1?

######### end of copy ###############

now, make this script executable:
chmod +x seder.sed
and run it against your html file and redirect the
output to your new colorized html file:

./seder.sed your_input.html > output.html

note:
I'm too lazy to look up the relevant code for
± ÷ ¢ £
should they be present in your html file (they
shouldn't, but if they are, you should replace
__PLUSMINUS__
__DIVISION__
__CENT__
__POUND__
by the appropriate &#.... code)
It was actually the 2nd column, but thanks a million!

I'll give it a shot and let you know how I get on.
 
Old 07-14-2009, 08:45 AM   #12
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
You definitely want to use styles in your finished HTML output: that's precisely what styles are "for." I agree with the notion of having Microsoft Excel do all of the work that it can do, then, if necessary, post-processing the file that it produced.

I would suggest exploring what Excel can do very thoroughly, because this is a fairly common request and Excel ought to be able to do it entirely on its own ... it just might not be entirely obvious at first blush. "It usually pays to look deeper." Microsoft's programmers tend to take the approach of, "get it done, more-or-less, if the user pushes the big red button ... but also provide more-sophisticated options to those who bother to look for them." (It's a pretty smart strategy.)
 
Old 07-15-2009, 01:52 AM   #13
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by Inbhir Pheofharain View Post
It was actually the 2nd column, but thanks a million!

I'll give it a shot and let you know how I get on.
ok, let me know if you figured how to change the script accordingly

that's the line you need to edit in your sed script:

s?\(±[ \t\r\n]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*\)¢\([^£]\{20,\}£\)?\1<td class=long>\2?g
 
Old 07-16-2009, 01:26 PM   #14
Inbhir Pheofharain
LQ Newbie
 
Registered: May 2009
Location: Edinburgh, Scotland
Distribution: Ubuntu
Posts: 15

Original Poster
Rep: Reputation: 0
Wink

Quote:
Originally Posted by vonbiber View Post
ok, let me know if you figured how to change the script accordingly

that's the line you need to edit in your sed script:

s?\(±[ \t\r\n]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*\)¢\([^£]\{20,\}£\)?\1<td class=long>\2?g
You've got me there - I'm lost! Can you post the line so it's the 2nd column that it changes?

Thanks again

Last edited by Inbhir Pheofharain; 07-16-2009 at 01:26 PM. Reason: Spelling mistake
 
Old 07-17-2009, 01:54 AM   #15
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by Inbhir Pheofharain View Post
You've got me there - I'm lost! Can you post the line so it's the 2nd column that it changes?

Thanks again
ok, replace the line I mentionned by this one:

########## copy and paste

s?\(±[ \t\r\n]*¢[^£]*£[ \t\n\r]*\)¢\([^£]\{20,\}£[ \t\n\r]*¢[^£]*£[ \t\n\r]*¢[^£]*£[ \t\n\r]*\)?\1<td class
=long>\2?g

############ end of copy

By the way the script excepts a well-formed html file,
that is, if a tag is opened (e.g., <td>\) it expected
the corresponding closing tag (</td>\)

With a few lines of more code, it should be possible
to first fix the html file and then do the
replacements.

Let me know how it went

Last edited by vonbiber; 07-17-2009 at 02:21 AM.
 
  


Reply

Tags
condition, html, table



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pdf table to html table? frieza Linux - Software 4 02-14-2009 06:21 PM
Viewing HTML Documents In KWord With Original Formatting Mark7 Linux - Software 1 06-18-2007 02:46 AM
html formatting thunderbird sharky Linux - Software 4 01-17-2006 02:33 PM
Howto turn off html formatting in OpenOffice jlinkels Linux - Software 1 12-22-2005 01:56 PM
changing an HTML table with javascript eantoranz Programming 2 10-29-2004 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration