Python Forum
Save output into a Excel Sheet with Format Table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save output into a Excel Sheet with Format Table
#1
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

Attached Files

Thumbnail(s)
   
Reply
#2
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,840 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  how to save to multiple locations during save cubangt 1 543 Oct-23-2023, 10:16 PM
Last Post: deanhystad
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 743 Sep-22-2023, 02:33 PM
Last Post: carecavoador
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,091 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 3,020 Feb-20-2023, 07:19 PM
Last Post: avd88
  how to read txt file, and write into excel with multiply sheet jacklee26 14 9,902 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,874 Dec-12-2022, 08:22 PM
Last Post: jh67
  Convert Json to table format python_student 2 5,462 Sep-28-2022, 12:48 PM
Last Post: python_student
  How to format EasyOCR results in order to save to CSV? cubangt 0 1,251 Sep-02-2022, 02:06 PM
Last Post: cubangt
  Convert .xlsx to Format as Table bnadir55 0 888 Aug-11-2022, 06:39 AM
Last Post: bnadir55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020