-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wera #36
Closed
Closed
Wera #36
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…, Side, Alignment from openpyxl.styles import NamedStyle from openpyxl.utils import get_column_letter from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image # Crear un nuevo libro de Excel wb = openpyxl.Workbook() # Crear hojas wb.active.title = "Ejemplo de funciones" sheet1 = wb.active sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes") # -------------------------- # Hoja 1: Ejemplo de funciones # -------------------------- # Agregar datos y aplicar formato sheet1["A1"] = "Número" sheet1["A2"] = 1000 sheet1["A3"] = 2000 sheet1["A4"] = 0.25 # Formato de número sheet1["A2"].number_format = '#,##0' sheet1["A3"].number_format = '€#,##0.00' sheet1["A4"].number_format = '0.00%' # Pegado especial sheet1["B2"] = "Pegado Transpuesto" sheet1["B3"] = "Valores" # Formato de celda sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin")) # Protección de celda protected = NamedStyle(name="protected") protected.protection.locked = True sheet1["B1"].style = protected sheet1.protection.set_password("123") # Combinar y centrar celdas sheet1.merge_cells("C1:E1") sheet1["C1"] = "Título Combinado" sheet1["C1"].alignment = Alignment(horizontal="center") # Formato condicional sheet1["A5"] = 500 sheet1["A6"] = 1000 sheet1["A7"] = 500 highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight) # Insertar imagen img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5") # Insertar comentario sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor") # Insertar gráfico from openpyxl.chart import BarChart, Reference values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart() chart.add_data(values) sheet1.add_chart(chart, "H10") # ------------------------------ # Hoja 2: Herramientas fundamentales # ------------------------------ sheet2["A1"] = "Herramientas Fundamentales" # (Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas) # ------------------------------ # Hoja 3: BD Clientes # ------------------------------ clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"), ("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"), ("María", "López", "Calle 2", "987654321", "[email protected]")] for row in clientes: sheet3.append(row) # Aplicar filtros sheet3.auto_filter.ref = "A1:E3" # Guardar el archivo wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx") import openpyxl from openpyxl.styles import Font, PatternFill, Border, Side, Alignment from openpyxl.styles import NamedStyle from openpyxl.utils import get_column_letter from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image # Crear un nuevo libro de Excel wb = openpyxl.Workbook() # Crear hojas wb.active.title = "Ejemplo de funciones" sheet1 = wb.active sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes") # -------------------------- # Hoja 1: Ejemplo de funciones # -------------------------- # Agregar datos y aplicar formato sheet1["A1"] = "Número" sheet1["A2"] = 1000 sheet1["A3"] = 2000 sheet1["A4"] = 0.25 # Formato de número sheet1["A2"].number_format = '#,##0' sheet1["A3"].number_format = '€#,##0.00' sheet1["A4"].number_format = '0.00%' # Pegado especial sheet1["B2"] = "Pegado Transpuesto" sheet1["B3"] = "Valores" # Formato de celda sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin")) # Protección de celda protected = NamedStyle(name="protected") protected.protection.locked = True sheet1["B1"].style = protected sheet1.protection.set_password("123") # Combinar y centrar celdas sheet1.merge_cells("C1:E1") sheet1["C1"] = "Título Combinado" sheet1["C1"].alignment = Alignment(horizontal="center") # Formato condicional sheet1["A5"] = 500 sheet1["A6"] = 1000 sheet1["A7"] = 500 highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight) # Insertar imagen img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5") # Insertar comentario sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor") # Insertar gráfico from openpyxl.chart import BarChart, Reference values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart() chart.add_data(values) sheet1.add_chart(chart, "H10") # ------------------------------ # Hoja 2: Herramientas fundamentales # ------------------------------ sheet2["A1"] = "Herramientas Fundamentales" # (Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas) # ------------------------------ # Hoja 3: BD Clientes # ------------------------------ clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"), ("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"), ("María", "López", "Calle 2", "987654321", "[email protected]")] for row in clientes: sheet3.append(row) # Aplicar filtros sheet3.auto_filter.ref = "A1:E3" # Guardar el archivo wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…, Side, Alignment from openpyxl.styles import NamedStyle from openpyxl.utils import get_column_letter from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image # Crear un nuevo libro de Excel wb = openpyxl.Workbook() # Crear hojas wb.active.title = "Ejemplo de funciones" sheet1 = wb.active sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes") # -------------------------- # Hoja 1: Ejemplo de funciones # -------------------------- # Agregar datos y aplicar formato sheet1["A1"] = "Número" sheet1["A2"] = 1000 sheet1["A3"] = 2000 sheet1["A4"] = 0.25 # Formato de número sheet1["A2"].number_format = '#,##0' sheet1["A3"].number_format = '€#,##0.00' sheet1["A4"].number_format = '0.00%' # Pegado especial sheet1["B2"] = "Pegado Transpuesto" sheet1["B3"] = "Valores" # Formato de celda sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin")) # Protección de celda protected = NamedStyle(name="protected") protected.protection.locked = True sheet1["B1"].style = protected sheet1.protection.set_password("123") # Combinar y centrar celdas sheet1.merge_cells("C1:E1") sheet1["C1"] = "Título Combinado" sheet1["C1"].alignment = Alignment(horizontal="center") # Formato condicional sheet1["A5"] = 500 sheet1["A6"] = 1000 sheet1["A7"] = 500 highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight) # Insertar imagen img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5") # Insertar comentario sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor") # Insertar gráfico from openpyxl.chart import BarChart, Reference values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart() chart.add_data(values) sheet1.add_chart(chart, "H10") # ------------------------------ # Hoja 2: Herramientas fundamentales # ------------------------------ sheet2["A1"] = "Herramientas Fundamentales" # (Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas) # ------------------------------ # Hoja 3: BD Clientes # ------------------------------ clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"), ("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"), ("María", "López", "Calle 2", "987654321", "[email protected]")] for row in clientes: sheet3.append(row) # Aplicar filtros sheet3.auto_filter.ref = "A1:E3" # Guardar el archivo wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")
import openpyxl
from openpyxl.styles import Font, PatternFill, Border, Side, Alignment from openpyxl.styles import NamedStyle
from openpyxl.utils import get_column_letter
from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image
Crear un nuevo libro de Excel
wb = openpyxl.Workbook()
Crear hojas
wb.active.title = "Ejemplo de funciones"
sheet1 = wb.active
sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes")
--------------------------
Hoja 1: Ejemplo de funciones
--------------------------
Agregar datos y aplicar formato
sheet1["A1"] = "Número"
sheet1["A2"] = 1000
sheet1["A3"] = 2000
sheet1["A4"] = 0.25
Formato de número
sheet1["A2"].number_format = '#,##0'
sheet1["A3"].number_format = '€#,##0.00'
sheet1["A4"].number_format = '0.00%'
Pegado especial
sheet1["B2"] = "Pegado Transpuesto"
sheet1["B3"] = "Valores"
Formato de celda
sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin"))
Protección de celda
protected = NamedStyle(name="protected")
protected.protection.locked = True
sheet1["B1"].style = protected
sheet1.protection.set_password("123")
Combinar y centrar celdas
sheet1.merge_cells("C1:E1")
sheet1["C1"] = "Título Combinado"
sheet1["C1"].alignment = Alignment(horizontal="center")
Formato condicional
sheet1["A5"] = 500
sheet1["A6"] = 1000
sheet1["A7"] = 500
highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight)
Insertar imagen
img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5")
Insertar comentario
sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor")
Insertar gráfico
from openpyxl.chart import BarChart, Reference
values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart()
chart.add_data(values)
sheet1.add_chart(chart, "H10")
------------------------------
Hoja 2: Herramientas fundamentales
------------------------------
sheet2["A1"] = "Herramientas Fundamentales"
(Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas)
------------------------------
Hoja 3: BD Clientes
------------------------------
clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"),
("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"),
("María", "López", "Calle 2", "987654321", "[email protected]")]
for row in clientes:
sheet3.append(row)
Aplicar filtros
sheet3.auto_filter.ref = "A1:E3"
Guardar el archivo
wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")