How to insert entire excel row using delphi7

I have a hard time using the ExcelXP library for delphi. I need to insert a row.

I saw a lot of delphi code snippets like this:

Open in new window

But that doesn't work because of 2 things:


Open in new window

doesn't even compile. Rows is an ExcelRange object, and apparently [] isn't defined.
This does compile, but is a bit strange:

Open in new window


Open in new window

inserts only one cell at the top-left of the given range.
I also saw these on the net

Open in new window

but that doens't work, you really need the two params.

So, simple question: How do you insert a row in an excel sheet using delphi?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you are targeting a particular cell then the correct line to use is:
ExcelApplication1.Rows.Cells.Item[Row, Col] := 'text';

Open in new window

For range of cells:
ExcelApplication1.Range[ExcelApplication1.Rows.Cells.Item[Row1, Col1], ExcelApplication1.Rows.Cells.Item[Row1, Col3]].Item[Row1,Col1] := 'text';

Open in new window

To insert:
ExcelApplication1.Rows.Cells.Insert(Shift, CopyOrigin);

ExcelApplication1.Range[ExcelApplication1.Rows.Cells.Item[Row1, Col1], ExcelApplication1.Rows.Cells.Item[Row1, Col3]].Insert(Shift, CopyOrigin);

Open in new window

Ephraim WangoyaCommented:

The basic concept to remember when working with Excel is that the data is in a Matrix.

A cell is referenced using the row number and the column number

Sheet1.Cells.Item[Row, Col] := 'Something'
gonniegijsenAuthor Commented:
The Insert function inserts above your source range, increasing the row index of the source range. That's why I had some strange behaviour with inserting only one cell instead of the entire row. Case closed.

Using EmptyParam as a col parameter, gets you the entire row.
Ok, so now I know you always have to use both row and col. So why do I always see delphi snippets like this aSheet.Rows[RowIndex] when googling?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gonniegijsenAuthor Commented:
found solution myself
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.