Sunday, August 28, 2022

[FIXED] How to adjust the measurement of cells in .csv/.xlsx file?

Issue

How can I adjust the measurement of the cells in the .csv/.xlsx file?

# Modules
import datetime, os, sys
import urllib.request as request
import pandas as pd

    #Sort Values From URL
Application_value = "org.thoughtcrime.securesms"
Version_value = "3.2.15"
print(Application_value)
        
#Insert into file.txt
with  open("log.csv", "a") as file:
    #content = str("Application_value") + ',' + str("Version_value") + '\n'
    content = str(Application_value) + ',' + str(Version_value) + '\n'
    print("Appended!")
    file.write(content)
    file.close()
df = pd.read_csv('log.csv')
df.to_excel('recordings.xlsx', 'Sheet1')

Let's say I wanted the cell of the first entry to be 25px or a similar measurement.


Solution

You can access to workbook and active sheet through ExcelWriter:

with pd.ExcelWriter('output.xlsx', engine='openpyxl') as writer:
    df.to_excel(writer, sheet_name='Sheet1', index=False)
    writer.book.active.column_dimensions['A'].width = 25


Answered By - Corralien
Answer Checked By - Pedro (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.