Python Forum
XlsxWriter: How can I append new data into not blank cells?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XlsxWriter: How can I append new data into not blank cells?
#1
to understand better what I want to do, I'll show you a simple example. following a little script to create an excel file named "test.xlsx" via XlsxWriter module. in this document we have only a column called "NAMES" and the name "Vittorio Emanuele" in the A:2 cell:

import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet("TEST")

cell_format_1 = workbook.add_format({'bold': True, 'valign': 'left'})
cell_format_2 = workbook.add_format({'valign': 'left'})

worksheet.write(0, 0, "NAMES", cell_format_1)
worksheet.write(1, 0, "Vittorio Emanuele", cell_format_2)

worksheet.set_column(0, 0, 16.71)

workbook.close()
following picture shows the script's result:

[Image: 5dff0e1238092764.jpg]

what about if I want to add a second name, for example "Alessandro Manzoni" in A2 cell like before, but without overrite the name "Vittorio Emanuele"? I would very like to have this reluslt: "Vittorio Emanuele\nAlessandro Manzoni". see the picture:

[Image: d376781238093964.jpg]

I need to find a command to do that, and use it in others programs that I wtote.
Reply
#2
This works on my PC:
worksheet.write(1, 0, "Vittorio Emanuele\nAlessandro Manzoni")
worksheet.set_row(1,50) # row height
Or use openpyxl:
#!/usr/bin/python3
from openpyxl import Workbook
wb = Workbook()

ws = wb.active
ws['A1'] = 'Names'

ws['A2']  = 'Vittorio'
ws['A2']  = ws['A2'].value + '\nAlexxandro'

wb.save("test.xlsx")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,228 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 9,857 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Append data to Yaml section tbaror 0 7,000 Feb-09-2022, 06:56 PM
Last Post: tbaror
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 1,956 Apr-06-2021, 10:08 AM
Last Post: arsentievalex
  xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet KMV 1 2,043 Mar-09-2021, 09:44 PM
Last Post: KMV
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,502 Mar-09-2021, 12:24 PM
Last Post: KMV
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 7,528 Feb-11-2021, 09:31 PM
Last Post: nilamo
  xlsxwriter in windows dfstrottersfan 2 2,348 Sep-23-2020, 11:41 AM
Last Post: dfstrottersfan
  Copy certain cells into new workbook certain cells Kristenl2784 4 2,503 Jul-14-2020, 07:59 PM
Last Post: Kristenl2784
  openpyxl Pasting data to different cells Kristenl2784 3 7,721 Jun-15-2020, 08:50 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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