What I use:
VB.NET, NET 3.5, OpenXML SDK 2.0
What I want to do:
I am creating an xlsx reader / writer for my application (based on the OpenXML SDK 2.0). I want to read xlsx files and store the data contained in each line in DTO / PONO. Next, I want to read the xlsx file, and then change it and save.
my thoughts:
Now my problem is not in the OpenXML SDK, I can do what I need.
My problem is how to structure my components. In particular, I have problems with polymorphism at the lowest level of a table, cell.
A cell in Excel / OpenXML can have different types of data associated with it. Like time, date, number, text or formula. These different types need to be handled differently when reading / writing from / to a spreadsheet.
I decided to have a common interface for all subtypes like TextCell, NumberCell, DateCell, etc.
Now, when I read a cell from a spreadsheet, the / Factory method can decide what type of cell will be created.
Now, since the cell is abstract from the actual implementation, it does not know / does not need what type it is. To write / modify a cell, I solve this problem by calling .write (ICellWriter) in the cell I want to save. Since the cell itself knows what type of data it contains, it knows which ICellWriter method it needs to call (static polymorphism).
:
xlsx . , DTO/PONO, → If TypeOf variable is ClassX then doesomething End If. / , .
Edit:
(, /) ( ) . . , Write(num as Integer), Write(text as String), Write(datum as Date). , , Write() , . , .
, ?
, , ?
Edit:
:
- DTO:
- PONO: .Net.
- xlsx: , excel
Edit:
Cell " .
Edit:
, , . - / . , . , , .