Jump to content

HTML Section to Excel Script

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
DWk

DWk

    Newbie

  • Members
  • Pip
  • 5 posts
Hi all,

I'm thinking of doing a script and from what I've heard from other programmers it should be fairly simple to code, but I'm unsure where to start.

If I have an html file like this:


<html>

<body>

<title>test page</title>

<body>

this is my first line

<!-- start -->

<table>

    <tr>

        <td></td>

    <tr>

</table>

<!-- end -->


this is my last line

</body>

</html>


And I want to take that table between the start and end tags and export it to Excel. What I'm thinking is that the function should remove anything outside these tags and create a temporary HTML file or buffer from which I can send to the Excel export function.

The challenge I see is that the table is dynamically (it's fed from information from the database), so I can only modify the "template" to include those HTML comments.

Any thoughts?

Thanks!

#2
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
Why not just write a script to pull the information directly from the database, format it, and output it in the excel file format?

#3
DWk

DWk

    Newbie

  • Members
  • Pip
  • 5 posts
That was my initial thought, but the problem is that the information displayed is dynamic. It's a list of tickets that can be filtered using several search criteria (you can even select how many tickets appear on screen).

Unfortunately, there are too many options to filter through, which is why I'm thinking of this alternate solution.

#4
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
Do you need a excel file for each and every variant of the page? That would end up causing a great number of files that all contain the same information just displayed differently.

Wouldn't one or two excel files that contain all the information from the database be a better solution since you could then format the spreadsheet to show what you want just like the table allows?

Maybe you can explain a little more what your needs are.

#5
DWk

DWk

    Newbie

  • Members
  • Pip
  • 5 posts
Not that I need an Excel variant of each page. I would assign a button that calls the function for those people that want/need to export the page they're currently looking at (with the filters).

Ok... let me see if this explanation works better - I need a function to trim every HTML code from the page that is outside of the start and end tags and store the resulting code in a temporary page/buffer/variable.

Hopefully that makes more sense.

#6
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
There are a number of ways that you can accomplish this, you can use curl, file_get_contents or any of the other file reading functions in php to read the current page, then parse out everything but the table you want.

For instance you can use preg_match with regular expressions to find the table and store it into a buffer.

Personally I would create a new page that acts exactly as the current page to gather the information, but instead of displaying the information I would return an excel file that was formatted on the page with the desired information.

This way you could simply put a link at the bottom of the page to that file and pass the parameters used to create the current page and get a custom excel file every time.

#7
DWk

DWk

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks - that's what I thought.

Which functions would you suggest to parse the "duplicate"?