Python Forum
How can I create a subclass of XlsxWriter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I create a subclass of XlsxWriter?
#1
Hi guys,

I would like to create a subclass of XlsxWriter in order to add new methods to semplify my work. For example, the script that I have in my mind, is written more or less in this way:
# import my custom class (a subclass of xlsxwriter):
import XlsxWriterPlus as xwp

# create a workbook with the first sheet named "SHEET 1":
wb =  xwp.Workbook("ciao.xlsx")
ws_1 = wb.add_worksheet("SHEET 1")

# use my custom method on the sheet object (ws_1): 
a = ws_1.my_method(arg1, arg2, ..)

# now the object wb has his fisrt worksheet compiled as I wanted. I can close the excel file:
a.close()
How can I reach my goal? Keep in mind that I didn't ever create a subclass of another one.. I'm working with the classes in these weeks. I just want to add new methods in xlsxwriter and use them in my scripts.

maybe what I should write to create my new class should be something like this:
# import just what I need:
from xlsxwriter.worksheet import Worksheet

# create my subclass:
class XlsxWriterPlus(Worksheet):
    def my_method(self, arg1, arg2, ..)
        ..
        ..
        ..

    def my_method_2(self, arg1, arg2, ..)
        ..
        ..
        ..

    def my_method_3(self, arg1, arg2, ..)
        ..
        ..
        ..
what do you think? can you please give me a hand to understand better how to proceed?
Reply


Messages In This Thread
How can I create a subclass of XlsxWriter? - by aquerci - May-02-2020, 12:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,881 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  xlsxwriter + mplfinance: Plot Stock Chart in Excel Worksheet KMV 1 2,079 Mar-09-2021, 09:44 PM
Last Post: KMV
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,549 Mar-09-2021, 12:24 PM
Last Post: KMV
Star Recursively convert nested dicts to dict subclass Alfalfa 1 2,930 Jan-22-2021, 05:43 AM
Last Post: buran
  xlsxwriter in windows dfstrottersfan 2 2,377 Sep-23-2020, 11:41 AM
Last Post: dfstrottersfan
  use of subclass ebolisa 4 2,271 Sep-17-2020, 01:08 PM
Last Post: jefsummers
  Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter jackie 1 3,237 May-27-2020, 11:47 PM
Last Post: mcmxl22
  Accessing subclass with a variable David_S 2 2,173 May-19-2020, 05:55 PM
Last Post: David_S
  XlsxWriter and Python inheritance aquerci 1 2,531 May-05-2020, 09:36 AM
Last Post: buran
  Design Pattern for accessing subclass attributes UGuntupalli 2 2,126 Jul-30-2019, 11:09 PM
Last Post: UGuntupalli

Forum Jump:

User Panel Messages

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