print (" De .CSV a .HTML ")
print (" ")
try:
nombre_csv = raw_input ("Introduzca el nombre del archivo que desea abrir: ") #El usuario decide el archivo que importa
archivo_csv= open((nombre_csv+'.csv')) #Python abre el archivo seleccionado por el usuario
contenido = archivo_csv.read () #Leyendo el archivo .csv
print 'Nombre ''Apellido1 ' 'Apellido2 ' 'mail '
print contenido #Imprime el contenido del archivo en pantalla
print raw_input ('Si los datos son correctos pulse enter para continuar')
nombre_html = raw_input ("Introduzca el nombre del archivo para guardar los datos en formato .html:")
archivo_html = open ((nombre_html+'.html'),"w")
except IOError:
print 'El archivo', (nombre_csv), 'no existe'
csv_to_html('tu_archivo.csv')
// Recuerda: incluir aquí el código de la funcion csv_to_html
try:
nombre_csv = raw_input ("Introduzca el nombre del archivo que desea abrir: ")
csv_to_html(nombre_csv)
except IOError:
print 'El archivo', (nombre_csv), 'no existe'
print (" De .CSV a .HTML ")
print (" ")
import csv
from string import Template
html_template = Template("""
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>$title</title>
<style>
* {margin: 0; padding: 0; font-size: 16px; box-sizing: border-box;}
body {font-family: Helvetica, sans-serif; color: #212121}
table {border-collapse: collapse; width: 100%;}
table, td {border: 1px solid #acacac;}
td { padding: .3rem;}
.datasheet {max-width: 960px; width: 100%; margin: 1rem auto;
overflow: auto;}
</style>
</head>
<body>
<div class="datasheet">
<table>$content</table>
</div>
</body>
</html>""")
def csv_to_html(csv_file, dest_filename='index.html', title='Document'):
""" Convierte un archivo csv a una tabla en formato html. """
with open(csv_file, mode='r') as f:
# detecto el dialecto utilizado por el archivo
dialect = csv.Sniffer().sniff(f.read(1024))
f.seek(0)
csv_reader = csv.reader(f, dialect)
rows = ''
for line in csv_reader:
cols = ''
for field in line:
cols += '<td>{}</td>'.format(field)
rows += '<tr>{}</tr>'.format(cols)
# creo el archivo html
with open(dest_filename, mode='w') as f:
content = html_template.substitute(title=title, content=rows)
f.write(content)
try:
nombre_csv = raw_input ("Introduzca el nombre del archivo que desea abrir: ") #El usuario decide el archivo que importa
csv_to_html(nombre_csv)
archivo_csv= open((nombre_csv+'.csv')) #Python abre el archivo seleccionado por el usuario
contenido = archivo_csv.read () #Leyendo el archivo .csv
print contenido #Imprime el contenido del archivo en pantalla
print raw_input ('Si los datos son correctos pulse enter para continuar')
nombre_html = raw_input ("Introduzca el nombre del archivo para guardar los datos en formato .html:")
archivo_html = open ((nombre_html+'.html'),"w")
archivo_html.write
except:
print "El archivo",(nombre_csv), "no existe"
# /usr/bin/env python
# -*- coding: utf-8 -*-
import csv
from string import Template
html_template = Template("""
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>$title</title>
<style>
* {margin: 0; padding: 0; font-size: 16px; box-sizing: border-box;}
body {font-family: Helvetica, sans-serif; color: #212121}
table {border-collapse: collapse; width: 100%;}
table, td {border: 1px solid #acacac;}
td { padding: .3rem;}
.datasheet {max-width: 960px; width: 100%; margin: 1rem auto;
overflow: auto;}
</style>
</head>
<body>
<div class="datasheet">
<table>$content</table>
</div>
</body>
</html>""")
def csv_to_html(csv_file, dest_filename='index.html', title='Document'):
""" Convierte un archivo csv a una tabla en formato html. """
with open(csv_file, mode='r') as f:
# detecto el dialecto utilizado por el archivo
dialect = csv.Sniffer().sniff(f.read(1024))
f.seek(0)
csv_reader = csv.reader(f, dialect)
rows = ''
for line in csv_reader:
cols = ''
for field in line:
cols += '<td>{}</td>'.format(field)
rows += '<tr>{}</tr>'.format(cols)
# creo el archivo html
with open(dest_filename, mode='w') as f:
content = html_template.substitute(title=title, content=rows)
f.write(content)
try:
nombre_csv = raw_input('Introduzca el nombre del archivo que desea abrir: ')
csv_to_html(nombre_csv)
except IOError:
print 'El archivo %s no existe' % nombre_csv
csv_to_html(nombre_csv, 'nombre_del_archivo.html')
try:
nombre_csv = raw_input('Introduzca el nombre del archivo que desea abrir: ')
nombre_html = raw_input('Introduzca el nombre del archivo html: ')
csv_to_html(nombre_csv, nombre_html)
except IOError:
print 'El archivo %s no existe' % nombre_csv