26 / 05 / 2017

Usuarios conectados: 4

Cargando documento...



Este Sitio:













Mailing List:

Suscríbete a la lista de correo, No practico spamming y ofrece algunas ventajas.

Pulsa aquí para saber más y suscribirte.



Tecnorama >Tutoriales Dreamweaver


Generate Excel files with DWMX/PHP/MySQL (part 1)

Versión para imprimir | Translate this page

Sometimes, it's very useful to give the user the ability to download data from your website. One of the most common formats is as *.csv file, which can be imported to many applications.

However: What if we generate an already formatted *.xls file, which could be already opened and saved by Excel? Besides data, we can give format to it and we'll give the user a ready to use spreadsheet!!

This article will show you how to generate an Excel file "on the fly", using DW, PHP and data from a MySQL database.

To achieve this, all you need is a blank php file and a table. No special libraries are needed. Ready? Let's start then.

1.- Add some code:
First of all, you need to add these lines at the very beginning of your document:

header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

And, If you want to give the user that "open or save" dialog box, simply add another line between the PHP tags (thanks Bergin for the tip):

header("content-disposition: attachment;filename=yourFileName.xls");

Now, give it a try: After you've written it, press F12 and see how Excel will open it.
Save the file (for example as "test_xls.php).

What have we done so far? We are telling the browser that the file we are sending will be an xls file despite its "php" extension, so it should call excel to open it, and make sure that previous content is not cached. That's all.
Now, we just need to put the data into it.

2.- Add a table:
Let's see what happens when we add a simple table to our document, just like the one above:

Hit F12 again: The spreadsheet now has data!

3.- Give it some format:
We can give the table the appearance that we want: You can modify the cells' width and background color, apply bold or italics to the text, change its font and color... Just use the property inspector to modify the properties (CSS Styles are not supported, sorry).

4.- Make it more dynamic:
We can also make the spreadsheet display dynamic results. For example, we can make it display the sum of Apples and Oranges automatically. Where's the trick? Well, simply adding Excel formulas to our table in DW:

Why B1:B2? Think of it this way: every cell in our table will be a cell in Excel, so the coordinates must match:

Modify the values for oranges and apples in the resulting Excel spreadsheet: Total is also updated!!

Important Notice: Remember that localized versions of Excel use different function names!: English versions use SUM() and Spanish versions, for example, use SUMA(). Be careful with this when you write them! However, you can write some code to find visitor's default language and change the function names. Any volunteers?...

Download sample file (English version):Just copy it into your PHP Site, open it with DW and hit F12 to test it. If you are running a localized version of MS Excel, you should change function names to make it work as expected

Next Part: Adding Data using MySQL

¿Comentarios? 195, de momento. Mostrando 1 ->5

1.- 97 Jeoffrey Pagan Jersey.Chandler Worthy Jersey for sale,
supply usa 28 Bobby McCain Jersey free shipping with
paypal also free gift can get.

2.- wh0cd7356690 [url=http://viagraprice2017.com/]viagra price[/url]

3.- wh0cd6107163 [url=http://viagraonline2017.com/]cheap viagra[/url]

4.- wh0cd6036844 [url=http://buycialis2017.com/]cialis[/url]

5.- Stable sans dandinement pilote ( doit savoir appréhender poids puissance d'autant plus que vitesses ) hautes sont vite atteintes sans?S'en rendre compte 1300 est presque!Trop facile amenant pilote facilement des vitesses inavouables avant même.Que celui s'en rende compte elle a été!Étudiée pour être fois plus pleine plus virile régime elle renforce [url=http://www.chaussurepaschers.com]air max bw[/url] puissance disponibilité vrai moteur.

Previous | 1 - 5 | 6 - 10 | 11 - 15 | 16 - 20 | 21 - 25 | 26 - 30 | 31 - 35 | 36 - 40 | 41 - 45 | 46 - 50 | Next

Añade tu comentario

Escribe el cdigo de la imagen superior:


Tutoriales Dreamweaver

-El muy buscado Men desplegable

-Qu $%&$% es 'SSI'?

-Utilizar tablas de excel para actualizar tablas en html.

-Plantillas en DW MX: Regiones opcionales.

-Adaptar tablas a la ventana.

-Vista diseo para formatos no reconocidos

-Carga de imagenes en orden

-Mi primera Extensin

-Rollover remoto ('Disjointed Rollover')

-Iframes vs. Frames

-Contenido dinmico en celdas

-DW MX: Repeating Tables

-DW MX: Practica el Cloaking

-DW MX: CSS en tiempo Diseo

-Buscar y Reemplazar en Dreamweaver

-Men dinmico

-Collaborative Dreamweaver: Design Notes and Files Panel

-Using PHP Server Formats and MySQL Dates

-Creando un Newsticker

-Generate Excel files with DWMX/PHP/MySQL (part 1)

-Manejo de fechas en PHP y MySQL

-Generate Excel files with DWMX/PHP/MySQL (part 2)

-Manejo de Fechas en consultas a MySQL

-Showing all records by default in a results page (PHP)

-Retrieving data using AHAH (1)

-Retrieving data using AHAH (2)

-Retrieving data using AHAH (3)

TECNORAMA es simplemente una página personal. No sirve ni de promoción del autor ni cosas por el estilo.
Todos los cdigos, textos y tutoriales son de libre uso mientras se mencione al autor (no es mucho pedir)
Este sitio es compatible con IE6/NS6/Mozilla1.0
Para contactar, puedes enviarme un e-mail a tecnorama@hotmail.com