Solved

Insert a line in a Excel file

Posted on 2001-09-18
3
713 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 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