Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inserting elements in an arbitary position

See original GitHub issue

First of all: Happy new year 😃

I tried inserting a table after a paragraph, which is impossible. We can just append it to the end of the document. Is that correct?

Offtopic Discussion

I already tried to address my architectural concerns here. I see OfficeIMO as a great high-level API around open-xml-sdk. It attempts to abstract some of the complexity concerning office documents by capsulation. At the moment, I see these tasks:

  • Packaging (maintaining XML files and un/zipping them)
  • Capsulation of open XML Elements
  • Aggregation of them

Domain-wise aggregation hast a context, most of the time. In pseudocode, I would expect something like this:

var doc = new Document();
var p =  new Paragraph();

// or

In other words: The paragraph is not related to the document. Paragraphs are only responsible for the consistency within themselves. The possible validation of how to aggregate this should occur in an AggregationStrategy, assuming not every element can be inserted everywhere.

I am not sure, but I think we are doing more of this:

var doc = new Document()
var p = doc.AddParagraph()

This way, we are not able to insert the elements arbitrarily.

If this is true, another disadvantage would be partial XML serialization. The implementation of the paragraphs is well crafted. Wouldn’t it be nice to get the XML representation for a single paragraph instance and paste it into the document using a file stream? This way, we could provide the best of the high-level API of OfficeIMO and keep it compatible with others. So to say: “If you think you need to do the aggregation in a special way, here you go.”

I don’t want to be impolite. I see all the work happening here, but those concerns should be separated, in my opinion. However, the refactoring would be tremendous, and I don’t know yet how to do it in small steps.

WDYT @PrzemyslawKlys ? I hope my point of view is just wrong because I have to find a way to insert a table in the middle of a document by the end of the week 😃

Issue Analytics

  • State:open
  • Created 8 months ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

PrzemyslawKlyscommented, Jul 19, 2023

I’m working on it as part of:

Having small issues, but will try to resolve this week

PrzemyslawKlyscommented, Jan 9, 2023

I accepted my own PR - feel free to expand on master 😉 Evolve it if you will, add more features, tests whatever 😉

I don’t mind leaving this ticket open as it discusses a lot of other ideas.

Regarding the Future Architecture

PowerShell is a scripting language but it’s based on .NET, so you can use .NET all around place. The problem is, some things are very hard to use. What’s in C# 2 lines of code sometimes gets really ugly if not impossible to be written in PowerShell.

It’s much easier to just use C# classes in PowerShell than it it to use interfaces and that’s what I mean. It’s hard to even find resources how one would use c# interface in PowerShell.

Anyways - that’s not really a problem, just something to keep in mind that whatever is exposed in the public, has to be sort of usable in PowerShell without doing tricks and code that want me to pull out my hair. But if it’s somewhere internally used, it’s not a big deal as PowerShell will never be visible.

And while I could use more experience - the problem is - it’s not part of my job 😃 That means I focus on things that I have to do and stuff like OfficeIMO and so on, are just a hobby. As for the meeting I am not sure I would be competent enough to talk about ‘patters or anti-patterns or code-smells’ because I lack any knowledge on it. That means I can’t understand in real time what you would be saying 😃 I need to read it couple of times, try to play with it, see what can be done.

But like I said before - I am open for people ideas and improvements all over the place. I believe the code is working, but it’s far from being optimized. I prefer the product to be working, having lots of features before you get and do it right - but at the same time it’s functional 2 years later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to efficiently insert an element in an arbitrary position ...
In C++ there is a linked list data structure which can efficiently insert an element at an iterator position in O(1) complexity, but...
Read more >
Insert an element at a particular index in an array
To insert an element at a particular index in an array, we need to Shift all the elements from last index to position...
Read more >
Insert a node at a specific position in a linked list
Approach: To insert a given data at a specified position, the below algorithm is to be followed: Traverse the Linked list upto position-1 ......
Read more >
Inserting an Item at an Arbitrary Position
Two member functions for inserting an item at an arbitrary position in an ordered list are declared in Program gif --InsertBefore and InsertAfter....
Read more >
Solved You may insert an element into an arbitrary position
Question: You may insert an element into an arbitrary position inside a vector using an iterator. Write a function, insert(vector, position, value) which ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found