Python Forum

Full Version: Save output into a Excel Sheet with Format Table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What can I add to my code
in order to save the output into a excel shett but with format table

this is the code (part of it, due to it is to long)
with PLC() as comm:
    comm.IPAddress = '172.21.11.10'
    comm.ProcessorSlot = 0
    ret = comm.GetPLCTime()
 
    print("Fecha y Hora de Registro Revision Fallas", ret.Value, )
    time.sleep(1)
 
     Estacion = "D2M017"
 
 
    ACTUADOR = comm.Read('D2M_017.Status.Act._1.WBypassed')
    ret = comm.GetPLCTime()
    Numero_Act_EnBypass = 0
    if ACTUADOR.Value == True:
        Sensor = "ACTUADOR 1 WORK SENSOR EN BY PASS"
        Numero_Act_EnBypass = (Numero_Act_EnBypass +1)
        print(Estacion, ret.Value, "D2M017 =",Sensor)
    else:
        Sensor = "ACTUADOR 1 WORK OK"
 
 
 
    ACTUADOR = comm.Read('D2M_017.Status.Act._1.HBypassed')
    ret = comm.GetPLCTime()
    if ACTUADOR.Value == True:
        Sensor = "ACTUADOR 1 HOME SENSOR EN BY PASS"
        Numero_Act_EnBypass = (Numero_Act_EnBypass +1)
        print(Estacion, ret.Value, "D2M017 =",Sensor)
    else:
        Sensor = "ACTUADOR 1 HOME OK"
#ACTUADOR 2
    ACTUADOR = comm.Read('D2M_017.Status.Act._2.WBypassed')
    ret = comm.GetPLCTime()
    if ACTUADOR.Value == True:
        Sensor = "ACTUADOR 2 WORK SENSOR EN BY PASS"
        Numero_Act_EnBypass = (Numero_Act_EnBypass +1)
        print(Estacion, ret.Value, "D2M017 =",Sensor)
    else:
        Sensor = "ACTUADOR 2 WORK OK"
 
 
 
    ACTUADOR = comm.Read('D2M_017.Status.Act._2.HBypassed')
    ret = comm.GetPLCTime()
    if ACTUADOR.Value == True:
        Sensor = "ACTUADOR 2 HOME SENSOR EN BY PASS"
        Numero_Act_EnBypass = (Numero_Act_EnBypass +1)
        print(Estacion, ret.Value, "D2M017 =",Sensor)
    else:
        Sensor = "ACTUADOR 2 HOME OK"
and this is the output

Output:
D2M_250 2020-04-15 14:20 D2M_250 = ACTUDADOR 7 HOME SENSOR BY PASS
I need to split that text into
STATION DATE STATUS
D2M_250 2020-04-15 14:20 D2M_250 = ACTUDADOR 7 HOME SENSOR BY PASS
Hola,

If you import 'Workbook' from the xlwt package, then on a basic level you may do the following:

import xlwt
from xlwt import Workbook

# Create Excel workbook
wb = Workbook()

sheet1 = wb.add_sheet('Sheet 1')

# Enter data into the cell of the 1st row and 0th column as follows
sheet1.write(1,0,'Some entry')

wb.save('exampleworkbook.xls')
Then you can simply adapt this into your PLC code as appropriate.

¡Espero haberte ayudado!