Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / October 2003



Tip: Looking for answers? Try searching our database.

Strip css from  Excel-generated file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Julie Miles - 23 Oct 2003 17:29 GMT
I need to pull several tables of data from Excel into a web page, but
when I use Excel's "Save as web page" function, I get an enormous file
containing a massive amount of css formatting. I'd like to strip out
this css so that I can apply my own style sheet; does anyone know
whether there is a way to do this, other than manually? Either a way to
export the data from Excel that doesn't include the css formatting, or
a utility that will strip it out for me?

Julie
Signature

Never ascribe to malice that which can be
adequately accounted for by stupidity

Matt - 23 Oct 2003 18:52 GMT
> I need to pull several tables of data from Excel into a web page, but
> when I use Excel's "Save as web page" function, I get an enormous file
[quoted text clipped - 3 lines]
> export the data from Excel that doesn't include the css formatting, or
> a utility that will strip it out for me?

Quick response:

I don't have Excel, but on Word (XP at least) you can choose File --> Save
As --> Save As Type. There's Web Page and under that something like "Web
Page <something>" which doesn't add the M$ Office Bloat.

Signature

Matt

Julie Miles - 23 Oct 2003 19:35 GMT
> > I need to pull several tables of data from Excel into a web page, but
> > when I use Excel's "Save as web page" function, I get an enormous file
[quoted text clipped - 9 lines]
> As --> Save As Type. There's Web Page and under that something like "Web
> Page <something>" which doesn't add the M$ Office Bloat.

Thanks, Matt, but there doesn't seem to be any corresponding function
in Excel. I think the simplest way around this might be to convert the
file to .pdf rather than an html page.

Signature

Never ascribe to malice that which can be
adequately accounted for by stupidity

Stephen Poley - 23 Oct 2003 19:34 GMT
>I need to pull several tables of data from Excel into a web page, but
>when I use Excel's "Save as web page" function, I get an enormous file
[quoted text clipped - 3 lines]
>export the data from Excel that doesn't include the css formatting, or
>a utility that will strip it out for me?

Simplest way is probably as follows. Insert new columns around the
existing columns: the first containing <TR><TD>, the last with
</TD></TR> and all the others with </TD><TD>. Obviously the Excel "fill
down" function is very handy. Save the file as text. That gets most of
the work done.

Signature

Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/

Julie Miles - 23 Oct 2003 20:17 GMT
> >I need to pull several tables of data from Excel into a web page, but
> >when I use Excel's "Save as web page" function, I get an enormous file
[quoted text clipped - 9 lines]
> down" function is very handy. Save the file as text. That gets most of
> the work done.

That's an ingenious suggestion! I think it will work for most of them -
there are some that have more complex structures (merged cells), but it
certainly gets rid of the majority of the grunt work. Thanks!

Julie
Signature

Never ascribe to malice that which can be
adequately accounted for by stupidity

Joerg - 27 Oct 2003 05:37 GMT
[snip]
>> Simplest way is probably as follows. Insert new columns around the
>> existing columns: the first containing <TR><TD>, the last with
[quoted text clipped - 7 lines]
>
> Julie

Several months ago I wrote an Excel function for this purpose: It can
handle merged cells and it reads the names(!) of Excel styles (not the
style definitions) and translates them into CSS class attributes.

To make it work, paste the following code into an Excel module (Fire the
VBA editor with Alt + F11, find your workook in one of the left windows,
right-click on it, then "Insert - Module" , doubleclick the newly created
module and paste the code).

If the first line of your Excel table stretches from A1 to D1, then in E1
you could use the formula =row2html(A1:D1)
Copy the formula down to the last cell.

Cheers,
Joerg

Here comes the Excel Stuff:

Function row2html(DataRange As Object)
    'Purpose: To mark-up a horizontal cell range as HTML <tr><td> elements
    'How it works: Each cell contents enclosed with <td>..</td> tags. The
whole stuff with <tr>..</tr> tags.
    'Special functions: Reads style names and converts them to class
attributes, translates merged cells into colspans.
    'Applies to: Horizontal cell ranges
    On Error Resume Next
    Dim CellText As String
    Application.Volatile
    txt = "<tr>"
    'If DataRange.MergeCells = True Then MsgBox "contains merged cells"
    Colspan = 0
    For Each cell In DataRange
        ColSpanAttribute = ""
        If cell.MergeArea.Address <> cell.Address And ColSpanProcessed =
True Then
            'Do nothing if cell is part of a merged area and TD with
COLSPAN attribute has already been defined
            'Ignore cell until last cell reached, then reset
ColSpanProcessed (another merged area may follow and has to be processed
with a clean slate)
            Colspan = Colspan - 1
            If Colspan = 1 Then ColSpanProcessed = False
        Else
            'Define COLSPAN if cell is part of merged area
           If cell.MergeArea.Address <> cell.Address And ColSpanProcessed
= False Then
               Colspan = cell.MergeArea.Cells.Count
               ColSpanAttribute = " colspan=""" & Colspan & """"
               ColSpanProcessed = True
           End If

            CellText = cell.Value
            'Add CSS class names, if cell contains named style
           If cell.Style.Name = "Normal" Then
               txt = txt & "<td" & ColSpanAttribute & ">" & CellText &
"</td>"
               Else
               txt = txt & "<td class=""" & cell.Style.Name & """" &
ColSpanAttribute & ">" & CellText & "</td>"
           End If
        End If

    Next cell
    txt = txt & "</tr>"
    row2html = txt
End Function
Philipp Lenssen - 24 Oct 2003 08:49 GMT
> I need to pull several tables of data from Excel into a web page, but
> when I use Excel's "Save as web page" function, I get an enormous
[quoted text clipped - 3 lines]
> to export the data from Excel that doesn't include the css
> formatting, or a utility that will strip it out for me?

Next to the <tr><td> hack which is very good, you can use Tidy HTML.
It's got special functions to clean Word-bloat etc. but it basically
cleans up any HTML, converts to XHTML etc.
http://www.w3.org/People/Raggett/tidy/

Signature

Google Blogoscoped
http://blog.outer-court.com

Stuart Scharf - 24 Oct 2003 13:22 GMT
Wow, I remember that someone wrote a DeCSS program to remove CSS from web
pages. (OK it was mainly to confuse 'bots looking for some other DeCSS
program). This might be an actual use for it.

> I need to pull several tables of data from Excel into a web page, but
> when I use Excel's "Save as web page" function, I get an enormous file
[quoted text clipped - 5 lines]
>
> Julie
Jukka K. Korpela - 26 Oct 2003 22:39 GMT
> I need to pull several tables of data from Excel into a web page,
> but when I use Excel's "Save as web page" function, I get an
> enormous file containing a massive amount of css formatting.

There are several approaches, some of which have been mentioned here.
I'd like to add two more:

1. Save in TSV format (tab separated values) and use some simple
  utilitity like a short Perl script to convert the TSV file
  to simple HTML markup. More on this:
  http://www.cs.tut.fi/~jkorpela/TSV.html

2. Download Office 2000 Filter from Microsoft:
<http://www.microsoft.com/downloads/details.aspx?
FamilyID=209ADBEE-3FBD-482C-83B0-96FB79B74DED&displaylang=EN>
  For Excel files, you would run the filter from the Start menu,
  item Microsoft Office Tools. In the program, click on the
  Options button to make it string standard CSS too (it by
  default strips Microsoft-specific CSS only).
  Problem: It leaves HTML attributes intact, making the table
  foolishly rigid. You could use some other software on it,
  or just try to override those attributes using CSS (e.g.,
  overriding a pixel-valued width or height attribute with
  a CSS rule that uses the em unit or the value 'auto').

Signature

Yucca, http://www.cs.tut.fi/~jkorpela/

Julie Miles - 29 Oct 2003 16:04 GMT
> > I need to pull several tables of data from Excel into a web page,
> > but when I use Excel's "Save as web page" function, I get an
[quoted text clipped - 20 lines]
>    overriding a pixel-valued width or height attribute with
>    a CSS rule that uses the em unit or the value 'auto').

Thanks to everyone for your helpful and creative suggestions - I truly
appreciate the help!

Julie
Signature

Never ascribe to malice that which can be
adequately accounted for by stupidity

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.