Solved

Insert a line in a Excel file

Posted on 2001-09-18
3
709 Views
Last Modified: 2010-04-04
I'm using Delphi 6 and TExcelApplication and TExcelWorksheet.  I want to insert a line between two existing lines in an Excel file. ( Same thing as, in Excel, rigth-clicking and select "Insert". )
I can insert a new line at the end, but I want to insert between two line.  How to do that ?
Thanks.
0
Comment
Question by:frdep
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 6491917
Hi frdep,
for an example (where WS is your worksheet) you can do this to move the rows down and insert some text at row A3:

begin
WS.Range['A3','A3'].EntireRow.Insert(TOleEnum(xlShiftDown));
WS.Range['A3','A3'].Value := 'HELLO IM SOME INSERTED TEXT';
end;

Regards Barry
0
 

Author Comment

by:frdep
ID: 6493551
Thanks.
How Do I do to keep the same format for the cells ?
0
 
LVL 17

Expert Comment

by:inthe
ID: 6494270
hi,
i couldnt work out how to read the current format to save it in a var and reapply it after the insert but if you know it already you can do like so and either format the whole sheet the same or just format your newly inserted row:


Uses ActiveX;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExcelWorksheet1.ConnectTo(ExcelApplication1.ActiveSheet as _Worksheet);
  ExcelWorksheet1.Range['A2', 'A2'].EntireRow.Insert(TOleEnum(xlShiftDown));
  ExcelWorksheet1.Range['A2','A2'].Value := 'HELLO IM SOME INSERTED TEXT';
   // this will just format all cells in the sheet the same
  //  ExcelWorksheet1.Cells.Select;
  //  ExcelWorksheet1.Cells.Font.Name:='Arial Cyr';
  //  ExcelWorksheet1.Cells.Font.Color := clgreen;
  //  ExcelWorksheet1.cells.Font.Size:=9;
  // or below will just format the new row
  ExcelWorksheet1.Range['A2','A2'].Font.Name:='Arial Cyr';
  ExcelWorksheet1.Range['A2','A2'].Font.Color := clblue;
  ExcelWorksheet1.Range['A2','A2'].Font.Size:=9;
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
problem when i try to pack my dll file with upx 9 72
How to use Hashing sha1 in Delphi 2010 4 203
Internet Explorer View Settings Question 15 106
Dev Express grid collapse 2 39
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now